HarshitJoshi commited on
Commit
104c95a
·
verified ·
1 Parent(s): 84ee29a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -5,14 +5,7 @@ import os
5
  model_id = "HarshitJoshi/whisper-small-Hindi"
6
  pipe = pipeline("automatic-speech-recognition", model=model_id)
7
 
8
- def transcribe_speech(source, source_type):
9
- if source_type == "Microphone":
10
- filepath = source
11
- elif source_type == "Upload":
12
- filepath = source.name
13
- elif source_type == "Example":
14
- filepath = os.path.join(example_folder, source)
15
-
16
  output = pipe(
17
  filepath,
18
  max_new_tokens=256,
@@ -30,21 +23,22 @@ example_files = [f for f in os.listdir(example_folder) if f.endswith('.wav') or
30
 
31
  def handle_input(mic, upload, example):
32
  if mic is not None:
33
- return transcribe_speech(mic, "Microphone")
34
  elif upload is not None:
35
- return transcribe_speech(upload, "Upload")
36
  elif example is not None:
37
- return transcribe_speech(example, "Example")
38
  else:
39
  return "Please provide an input."
40
 
41
  with gr.Blocks() as demo:
42
- mic = gr.Audio(source="microphone", type="filepath", label="Record from Microphone")
43
- upload = gr.Audio(source="upload", type="file", label="Upload an Audio File")
44
- example = gr.Dropdown(choices=example_files, label="Or Select an Example")
 
45
 
46
  output = gr.Textbox(label="Transcription")
47
-
48
  submit_btn = gr.Button("Transcribe")
49
  submit_btn.click(handle_input, inputs=[mic, upload, example], outputs=output)
50
 
 
5
  model_id = "HarshitJoshi/whisper-small-Hindi"
6
  pipe = pipeline("automatic-speech-recognition", model=model_id)
7
 
8
+ def transcribe_speech(filepath):
 
 
 
 
 
 
 
9
  output = pipe(
10
  filepath,
11
  max_new_tokens=256,
 
23
 
24
  def handle_input(mic, upload, example):
25
  if mic is not None:
26
+ return transcribe_speech(mic)
27
  elif upload is not None:
28
+ return transcribe_speech(upload.name)
29
  elif example is not None:
30
+ return transcribe_speech(os.path.join(example_folder, example))
31
  else:
32
  return "Please provide an input."
33
 
34
  with gr.Blocks() as demo:
35
+ with gr.Row():
36
+ mic = gr.Audio(type="filepath", label="Record from Microphone")
37
+ upload = gr.Audio(type="file", label="Upload an Audio File")
38
+ example = gr.Dropdown(choices=example_files, label="Or Select an Example")
39
 
40
  output = gr.Textbox(label="Transcription")
41
+
42
  submit_btn = gr.Button("Transcribe")
43
  submit_btn.click(handle_input, inputs=[mic, upload, example], outputs=output)
44