deepakkumar07 commited on
Commit
0ce1e34
·
verified ·
1 Parent(s): 2fad513

added model name param

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -7,15 +7,15 @@ pipe = pipeline(task="automatic-speech-recognition",
7
  model="openai/whisper-small",
8
  device="cuda" if torch.cuda.is_available() else "cpu")
9
 
10
-
11
- # Initialize the pipeline with the selected model
12
  def initialize_pipeline(model_name):
13
- # Placeholder for the actual pipeline initialization
 
 
 
14
  return model_name
15
 
16
 
17
- def transcribe(audio, model_name):
18
- pipe.model = model_name
19
  text = pipe(audio)["text"]
20
  return text
21
 
@@ -31,7 +31,6 @@ interface = gr.Interface(
31
  with gr.Blocks() as interface:
32
  # Dropdown to select the model
33
  model_dropdown = gr.Dropdown(choices=models, value=models[0], label="Select Model")
34
-
35
  # Audio input component
36
  audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Upload or Record Audio")
37
  # Text output component
@@ -41,8 +40,7 @@ with gr.Blocks() as interface:
41
  # Event listener to initialize the pipeline when the model is selected
42
  model_dropdown.change(fn=initialize_pipeline, inputs=model_dropdown, outputs=None)
43
  # Event listener to transcribe the audio when the button is clicked
44
- transcribe_button.click(fn=transcribe, inputs=[audio_input, model_dropdown], outputs=text_output)
45
- # Event listener to show the download button when audio is uploaded or recorded
46
 
47
  if __name__ == "__main__":
48
  interface.launch()
 
7
  model="openai/whisper-small",
8
  device="cuda" if torch.cuda.is_available() else "cpu")
9
 
 
 
10
  def initialize_pipeline(model_name):
11
+ global pipe
12
+ pipe = pipeline(task="automatic-speech-recognition",
13
+ model=model_name,
14
+ device="cuda" if torch.cuda.is_available() else "cpu")
15
  return model_name
16
 
17
 
18
+ def transcribe(audio):
 
19
  text = pipe(audio)["text"]
20
  return text
21
 
 
31
  with gr.Blocks() as interface:
32
  # Dropdown to select the model
33
  model_dropdown = gr.Dropdown(choices=models, value=models[0], label="Select Model")
 
34
  # Audio input component
35
  audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath", label="Upload or Record Audio")
36
  # Text output component
 
40
  # Event listener to initialize the pipeline when the model is selected
41
  model_dropdown.change(fn=initialize_pipeline, inputs=model_dropdown, outputs=None)
42
  # Event listener to transcribe the audio when the button is clicked
43
+ transcribe_button.click(fn=transcribe, inputs=[audio_input], outputs=text_output)
 
44
 
45
  if __name__ == "__main__":
46
  interface.launch()