Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,33 +27,25 @@ def speech_to_speech_translation(audio_data, tgt_lang):
|
|
27 |
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
28 |
return text, output_file
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
gr.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
)
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
accordion = gr.Accordion(
|
53 |
-
iface_s2t,
|
54 |
-
iface_s2st,
|
55 |
-
labels=["Speech to Text", "Speech to Speech Translation"]
|
56 |
-
)
|
57 |
-
|
58 |
-
# Launch the application
|
59 |
-
accordion.launch()
|
|
|
27 |
torchaudio.save(output_file, waveform.unsqueeze(0), sample_rate=16000)
|
28 |
return text, output_file
|
29 |
|
30 |
+
def create_interface():
|
31 |
+
with gr.Blocks(theme='ParityError/Anime') as interface:
|
32 |
+
# Dropdown for language selection
|
33 |
+
input_language = gr.Dropdown(list(languages.keys()), label="Select Target Language", value="English")
|
34 |
+
|
35 |
+
with gr.Accordion("Speech to Text", open=False) as stt_accordion:
|
36 |
+
audio_input_stt = gr.Audio(label="Upload or Record Audio")
|
37 |
+
text_output_stt = gr.Text(label="Transcribed Text")
|
38 |
+
stt_button = gr.Button("Transcribe")
|
39 |
+
stt_button.click(speech_to_text, inputs=[audio_input_stt, input_language], outputs=text_output_stt)
|
40 |
+
|
41 |
+
with gr.Accordion("Speech to Speech Translation", open=False) as s2st_accordion:
|
42 |
+
audio_input_s2st = gr.Audio(label="Upload or Record Audio")
|
43 |
+
text_output_s2st = gr.Text(label="Translated Text")
|
44 |
+
audio_output_s2st = gr.Audio(label="Translated Audio", type="filepath")
|
45 |
+
s2st_button = gr.Button("Translate")
|
46 |
+
s2st_button.click(speech_to_speech_translation, inputs=[audio_input_s2st, input_language], outputs=[text_output_s2st, audio_output_s2st])
|
47 |
+
|
48 |
+
return interface
|
49 |
+
|
50 |
+
app = create_interface()
|
51 |
+
app.launch(show_error=True, debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|