Vageesh1 commited on
Commit
8e56d37
1 Parent(s): 61c0849

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,4 +1,5 @@
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
2
  from elevenlabs import set_api_key
3
  from elevenlabs import clone, generate, play
4
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
@@ -11,18 +12,20 @@ import streamlit as st
11
 
12
 
13
  #language translation function
14
- def translate(text):
15
- tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M",use_auth_token=True)
16
- tokenizer = AutoTokenizer.from_pretrained(".",use_auth_token=True)
17
- model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M",use_auth_token=True)
18
- model = AutoModelForSeq2SeqLM.from_pretrained(".",use_auth_token=True)
19
- model.config.to_json()
20
- inputs = tokenizer(text, return_tensors="pt")
21
- translated_tokens = model.generate(**inputs,
22
- forced_bos_token_id=tokenizer.lang_code_to_id["hin_Deva"],
23
- max_length=100)
24
- result = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
25
- return result
 
 
26
 
27
 
28
  def save_uploaded_file_as_mp3(uploaded_file, output_file_path):
 
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
+ from transformers import MarianMTModel, MarianTokenizer
3
  from elevenlabs import set_api_key
4
  from elevenlabs import clone, generate, play
5
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
12
 
13
 
14
  #language translation function
15
+ def translate_english_to_hindi(input_text):
16
+ # Load the pre-trained English to Hindi translation model and tokenizer
17
+ model_name = "Helsinki-NLP/opus-mt-en-hi"
18
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
19
+ model = MarianMTModel.from_pretrained(model_name)
20
+
21
+ # Tokenize the input text and generate translation
22
+ inputs = tokenizer(input_text, return_tensors="pt", padding=True)
23
+ translated_ids = model.generate(inputs.input_ids)
24
+
25
+ # Decode the translated output
26
+ translated_text = tokenizer.decode(translated_ids[0], skip_special_tokens=True)
27
+
28
+ return translated_text
29
 
30
 
31
  def save_uploaded_file_as_mp3(uploaded_file, output_file_path):