Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
import torch
|
4 |
-
|
|
|
5 |
from transformers import AutoProcessor, AutoModel, pipeline, MarianMTModel, MarianTokenizer
|
6 |
|
7 |
|
@@ -21,7 +20,7 @@ martian_mt_tokenizer = MarianTokenizer.from_pretrained("AbhirupGhosh/opus-mt-fin
|
|
21 |
|
22 |
def translate_english_to_hindi(english_text):
|
23 |
tokenized_text = martian_mt_tokenizer.encode(english_text, return_tensors="pt")
|
24 |
-
generated_token_ids = martian_mt_model.generate(tokenized_text)
|
25 |
hindi_text = martian_mt_tokenizer.decode(generated_token_ids.numpy()[0])
|
26 |
hindi_text = hindi_text.replace("</s>", "")
|
27 |
hindi_text = hindi_text.replace("<pad>", "")
|
@@ -30,21 +29,22 @@ def translate_english_to_hindi(english_text):
|
|
30 |
|
31 |
|
32 |
def translate_to_english(audio):
|
33 |
-
outputs = asr_pipe(audio,
|
34 |
return outputs["text"]
|
35 |
|
36 |
def synthesise(text):
|
37 |
-
inputs = processor(text=text, return_tensors="pt")
|
38 |
-
speech_values = model.generate(**inputs)
|
39 |
speech_values = speech_values.cpu().numpy()
|
40 |
-
|
41 |
return speech_values
|
42 |
|
43 |
def speech_to_hindi_translation(audio):
|
44 |
english_text = translate_to_english(audio)
|
45 |
hindi_text = translate_english_to_hindi(english_text)
|
46 |
-
synthesised_speech = synthesise(hindi_text)
|
47 |
synthesised_speech = (synthesised_speech * 32767).astype(np.int16)
|
|
|
48 |
return 22050, synthesised_speech
|
49 |
|
50 |
|
@@ -67,7 +67,7 @@ file_translate = gr.Interface(
|
|
67 |
fn=speech_to_hindi_translation,
|
68 |
inputs=gr.Audio(source="upload", type="filepath"),
|
69 |
outputs=gr.Audio(label="Generated Speech", type="numpy"),
|
70 |
-
|
71 |
title=title,
|
72 |
description=description,
|
73 |
)
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
from transformers import AutoProcessor, AutoModel, pipeline, MarianMTModel, MarianTokenizer
|
5 |
|
6 |
|
|
|
20 |
|
21 |
def translate_english_to_hindi(english_text):
|
22 |
tokenized_text = martian_mt_tokenizer.encode(english_text, return_tensors="pt")
|
23 |
+
generated_token_ids = martian_mt_model.generate(tokenized_text, use_cache=True)
|
24 |
hindi_text = martian_mt_tokenizer.decode(generated_token_ids.numpy()[0])
|
25 |
hindi_text = hindi_text.replace("</s>", "")
|
26 |
hindi_text = hindi_text.replace("<pad>", "")
|
|
|
29 |
|
30 |
|
31 |
def translate_to_english(audio):
|
32 |
+
outputs = asr_pipe(audio, generate_kwargs={"task": "transcribe", "use_cache":"True"})
|
33 |
return outputs["text"]
|
34 |
|
35 |
def synthesise(text):
|
36 |
+
inputs = processor(text=text, return_tensors="pt").to(device)
|
37 |
+
speech_values = model.generate(**inputs, use_cache=True)
|
38 |
speech_values = speech_values.cpu().numpy()
|
39 |
+
|
40 |
return speech_values
|
41 |
|
42 |
def speech_to_hindi_translation(audio):
|
43 |
english_text = translate_to_english(audio)
|
44 |
hindi_text = translate_english_to_hindi(english_text)
|
45 |
+
synthesised_speech = synthesise(hindi_text)[0]
|
46 |
synthesised_speech = (synthesised_speech * 32767).astype(np.int16)
|
47 |
+
|
48 |
return 22050, synthesised_speech
|
49 |
|
50 |
|
|
|
67 |
fn=speech_to_hindi_translation,
|
68 |
inputs=gr.Audio(source="upload", type="filepath"),
|
69 |
outputs=gr.Audio(label="Generated Speech", type="numpy"),
|
70 |
+
examples=["/home/susnato/Downloads/example.wav"],
|
71 |
title=title,
|
72 |
description=description,
|
73 |
)
|