HarshitJoshi commited on
Commit
d1adb8f
1 Parent(s): 2609da3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -19,26 +19,36 @@ def transcribe_speech(filepath):
19
  return output["text"]
20
 
21
  example_folder = "./examples"
22
- example_files = [os.path.join(example_folder, f) for f in os.listdir(example_folder) if f.endswith('.wav') or f.endswith('.mp3')]
23
 
24
  demo = gr.Blocks()
25
 
26
  mic_transcribe = gr.Interface(
27
  fn=transcribe_speech,
28
- inputs=gr.Audio(source="microphone", type="filepath"),
29
  outputs=gr.Textbox(),
30
  )
31
 
32
  file_transcribe = gr.Interface(
33
  fn=transcribe_speech,
34
- inputs=gr.Audio(type="filepath"),
35
  outputs=gr.Textbox(),
36
- examples=example_files, # Adding examples here
 
 
 
 
 
 
 
 
 
 
37
  )
38
 
39
  with demo:
40
  gr.TabbedInterface(
41
- [mic_transcribe, file_transcribe],
42
- ["Transcribe Microphone", "Transcribe Audio File"],
43
  )
44
  demo.launch(debug=True)
 
19
  return output["text"]
20
 
21
  example_folder = "./examples"
22
+ example_files = [f for f in os.listdir(example_folder) if f.endswith('.wav') or f.endswith('.mp3')]
23
 
24
  demo = gr.Blocks()
25
 
26
  mic_transcribe = gr.Interface(
27
  fn=transcribe_speech,
28
+ inputs=gr.Audio(type="filepath"),
29
  outputs=gr.Textbox(),
30
  )
31
 
32
  file_transcribe = gr.Interface(
33
  fn=transcribe_speech,
34
+ inputs=gr.Audio(type="filepath"),
35
  outputs=gr.Textbox(),
36
+ )
37
+
38
+ def play_and_transcribe(filename):
39
+ filepath = os.path.join(example_folder, filename)
40
+ transcription = transcribe_speech(filepath)
41
+ return filepath, transcription
42
+
43
+ example_transcribe = gr.Interface(
44
+ fn=play_and_transcribe,
45
+ inputs=gr.Dropdown(choices=example_files, label="Select an example"),
46
+ outputs=[gr.Audio(label="Audio Playback"), gr.Textbox(label="Transcription")],
47
  )
48
 
49
  with demo:
50
  gr.TabbedInterface(
51
+ [mic_transcribe, file_transcribe, example_transcribe],
52
+ ["Transcribe Microphone", "Transcribe Audio File", "Transcribe Example"],
53
  )
54
  demo.launch(debug=True)