Tonic commited on
Commit
a848fc8
1 Parent(s): 9bdbe1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -30
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
- # Gradio interfaces
31
- iface_s2t = gr.Interface(
32
- fn=speech_to_text,
33
- inputs=[
34
- gr.Audio(label="Upload or Record Audio for Speech to Text"),
35
- gr.Dropdown(list(languages.keys()), label="Select Target Language")
36
- ],
37
- outputs="text",
38
- title="Speech to Text"
39
- )
40
-
41
- iface_s2st = gr.Interface(
42
- fn=speech_to_speech_translation,
43
- inputs=[
44
- gr.Audio(label="Upload or Record Audio for Speech to Speech Translation"),
45
- gr.Dropdown(list(languages.keys()), label="Select Target Language")
46
- ],
47
- outputs=["text", "audio"],
48
- title="Speech to Speech Translation"
49
- )
50
-
51
- # Combine into an accordion interface
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)