Update app.py
Browse files
app.py
CHANGED
@@ -244,10 +244,21 @@ def on_src_or_tgt_lang_change(src_lang_value, tgt_lang_value, pnc_value):
|
|
244 |
)
|
245 |
return src_lang, tgt_lang, pnc
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
def main(audio_filepath, src_lang, tgt_lang, pnc):
|
248 |
translated = transcribe(audio_filepath, src_lang, tgt_lang, pnc)
|
249 |
answer = llm_pipe(translated, **generation_args)
|
250 |
-
return answer[0]['generated_text']
|
251 |
|
252 |
|
253 |
|
@@ -306,11 +317,13 @@ with gr.Blocks(
|
|
306 |
elem_id="model_output_text_box",
|
307 |
)
|
308 |
|
|
|
|
|
309 |
|
310 |
go_button.click(
|
311 |
fn=main,
|
312 |
inputs = [audio_file, src_lang, tgt_lang, pnc],
|
313 |
-
outputs = [model_output_text_box]
|
314 |
)
|
315 |
|
316 |
# call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
|
|
|
244 |
)
|
245 |
return src_lang, tgt_lang, pnc
|
246 |
|
247 |
+
def txt2speech(text):
|
248 |
+
print("Initializing text-to-speech conversion...")
|
249 |
+
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
250 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
251 |
+
payloads = {'inputs': text}
|
252 |
+
|
253 |
+
response = requests.post(API_URL, headers=headers, json=payloads)
|
254 |
+
|
255 |
+
with open('audio_out.mp3', 'wb') as file:
|
256 |
+
file.write(response.content)
|
257 |
+
|
258 |
def main(audio_filepath, src_lang, tgt_lang, pnc):
|
259 |
translated = transcribe(audio_filepath, src_lang, tgt_lang, pnc)
|
260 |
answer = llm_pipe(translated, **generation_args)
|
261 |
+
return [answer[0]['generated_text'], 'audio_out.mp3']
|
262 |
|
263 |
|
264 |
|
|
|
317 |
elem_id="model_output_text_box",
|
318 |
)
|
319 |
|
320 |
+
audio_out = gr.Audio(label="Generated Audio", type="numpy", elem_id="audio_out")
|
321 |
+
|
322 |
|
323 |
go_button.click(
|
324 |
fn=main,
|
325 |
inputs = [audio_file, src_lang, tgt_lang, pnc],
|
326 |
+
outputs = [model_output_text_box, audio_out]
|
327 |
)
|
328 |
|
329 |
# call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
|