github-actions[bot] commited on
Commit
0863517
·
1 Parent(s): 9e6abf1

Sync with https://github.com/mozilla-ai/speech-to-text-finetune

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -53,32 +53,26 @@ def _load_hf_model(model_repo_id: str) -> Tuple[Pipeline | None, str]:
53
  return pipeline(
54
  "automatic-speech-recognition",
55
  model=model_repo_id,
56
- device=0
57
  ), f"✅ HF Model {model_repo_id} has been loaded."
58
 
59
 
60
- def load_model(
61
- dropdown_model_id: str, hf_model_id: str, local_model_id: str
62
- ) -> Tuple[Pipeline, str]:
 
 
 
 
 
63
  if dropdown_model_id and not hf_model_id and not local_model_id:
64
  dropdown_model_id = dropdown_model_id.split(" (")[0]
65
- yield None, f"Loading {dropdown_model_id}..."
66
- yield _load_hf_model(dropdown_model_id)
67
  elif hf_model_id and not local_model_id and not dropdown_model_id:
68
- yield None, f"Loading {hf_model_id}..."
69
- yield _load_hf_model(hf_model_id)
70
  elif local_model_id and not hf_model_id and not dropdown_model_id:
71
- yield None, f"Loading {local_model_id}..."
72
- yield _load_local_model(local_model_id)
73
  else:
74
- yield (
75
- None,
76
- "️️⚠️ Please select or fill at least and only one of the options above",
77
- )
78
-
79
-
80
- @spaces.GPU
81
- def transcribe(pipe: Pipeline, audio: gr.Audio) -> str:
82
  text = pipe(audio)["text"]
83
  return text
84
 
@@ -111,7 +105,7 @@ def setup_gradio_demo():
111
  placeholder="artifacts/my-whisper-tiny",
112
  )
113
 
114
- load_model_button = gr.Button("Load model")
115
  model_loaded = gr.Markdown()
116
 
117
  ### Transcription ###
@@ -126,15 +120,19 @@ def setup_gradio_demo():
126
  transcribe_output = gr.Text(label="Output")
127
 
128
  ### Event listeners ###
 
129
  model = gr.State()
130
  load_model_button.click(
131
  fn=load_model,
132
  inputs=[dropdown_model, user_model, local_model],
133
  outputs=[model, model_loaded],
134
  )
 
135
 
136
  transcribe_button.click(
137
- fn=transcribe, inputs=[model, audio_input], outputs=transcribe_output
 
 
138
  )
139
 
140
  demo.launch()
 
53
  return pipeline(
54
  "automatic-speech-recognition",
55
  model=model_repo_id,
 
56
  ), f"✅ HF Model {model_repo_id} has been loaded."
57
 
58
 
59
+ @spaces.GPU
60
+ def transcribe(
61
+ dropdown_model_id: str,
62
+ hf_model_id: str,
63
+ local_model_id: str,
64
+ pipe: Pipeline,
65
+ audio: gr.Audio,
66
+ ) -> str:
67
  if dropdown_model_id and not hf_model_id and not local_model_id:
68
  dropdown_model_id = dropdown_model_id.split(" (")[0]
69
+ pipe = _load_hf_model(dropdown_model_id)
 
70
  elif hf_model_id and not local_model_id and not dropdown_model_id:
71
+ pipe = _load_hf_model(hf_model_id)
 
72
  elif local_model_id and not hf_model_id and not dropdown_model_id:
73
+ pipe = _load_local_model(local_model_id)
 
74
  else:
75
+ return ("️️⚠️ Please select or fill at least and only one of the options above",)
 
 
 
 
 
 
 
76
  text = pipe(audio)["text"]
77
  return text
78
 
 
105
  placeholder="artifacts/my-whisper-tiny",
106
  )
107
 
108
+ # load_model_button = gr.Button("Load model")
109
  model_loaded = gr.Markdown()
110
 
111
  ### Transcription ###
 
120
  transcribe_output = gr.Text(label="Output")
121
 
122
  ### Event listeners ###
123
+ """
124
  model = gr.State()
125
  load_model_button.click(
126
  fn=load_model,
127
  inputs=[dropdown_model, user_model, local_model],
128
  outputs=[model, model_loaded],
129
  )
130
+ """
131
 
132
  transcribe_button.click(
133
+ fn=transcribe,
134
+ inputs=[dropdown_model, user_model, local_model, audio_input],
135
+ outputs=transcribe_output,
136
  )
137
 
138
  demo.launch()