almncarlo commited on
Commit
eb18247
1 Parent(s): ae25499

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -106
app.py CHANGED
@@ -142,84 +142,84 @@ def transcribe(audio_filepath, src_lang, tgt_lang, pnc):
142
  return output_text
143
 
144
  # add logic to make sure dropdown menus only suggest valid combos
145
- # def on_src_or_tgt_lang_change(src_lang_value, tgt_lang_value, pnc_value):
146
- # """Callback function for when src_lang or tgt_lang dropdown menus are changed.
147
-
148
- # Args:
149
- # src_lang_value(string), tgt_lang_value (string), pnc_value(bool) - the current
150
- # chosen "values" of each Gradio component
151
- # Returns:
152
- # src_lang, tgt_lang, pnc - these are the new Gradio components that will be displayed
153
-
154
- # """
155
-
156
- # if src_lang_value == "English" and tgt_lang_value == "English":
157
- # # src_lang and tgt_lang can go anywhere
158
- # src_lang = gr.Dropdown(
159
- # choices=["English", "Spanish", "French", "German"],
160
- # value=src_lang_value,
161
- # label="Input audio is spoken in:"
162
- # )
163
- # tgt_lang = gr.Dropdown(
164
- # choices=["English", "Spanish", "French", "German"],
165
- # value=tgt_lang_value,
166
- # label="Transcribe in language:"
167
- # )
168
- # elif src_lang_value == "English":
169
- # # src is English & tgt is non-English
170
- # # => src can only be English or current tgt_lang_values
171
- # # & tgt can be anything
172
- # src_lang = gr.Dropdown(
173
- # choices=["English", tgt_lang_value],
174
- # value=src_lang_value,
175
- # label="Input audio is spoken in:"
176
- # )
177
- # tgt_lang = gr.Dropdown(
178
- # choices=["English", "Spanish", "French", "German"],
179
- # value=tgt_lang_value,
180
- # label="Transcribe in language:"
181
- # )
182
- # elif tgt_lang_value == "English":
183
- # # src is non-English & tgt is English
184
- # # => src can be anything
185
- # # & tgt can only be English or current src_lang_value
186
- # src_lang = gr.Dropdown(
187
- # choices=["English", "Spanish", "French", "German"],
188
- # value=src_lang_value,
189
- # label="Input audio is spoken in:"
190
- # )
191
- # tgt_lang = gr.Dropdown(
192
- # choices=["English", src_lang_value],
193
- # value=tgt_lang_value,
194
- # label="Transcribe in language:"
195
- # )
196
- # else:
197
- # # both src and tgt are non-English
198
- # # => both src and tgt can only be switch to English or themselves
199
- # src_lang = gr.Dropdown(
200
- # choices=["English", src_lang_value],
201
- # value=src_lang_value,
202
- # label="Input audio is spoken in:"
203
- # )
204
- # tgt_lang = gr.Dropdown(
205
- # choices=["English", tgt_lang_value],
206
- # value=tgt_lang_value,
207
- # label="Transcribe in language:"
208
- # )
209
- # # let pnc be anything if src_lang_value == tgt_lang_value, else fix to True
210
- # if src_lang_value == tgt_lang_value:
211
- # pnc = gr.Checkbox(
212
- # value=pnc_value,
213
- # label="Punctuation & Capitalization in transcript?",
214
- # interactive=True
215
- # )
216
- # else:
217
- # pnc = gr.Checkbox(
218
- # value=True,
219
- # label="Punctuation & Capitalization in transcript?",
220
- # interactive=False
221
- # )
222
- # return src_lang, tgt_lang, pnc
223
 
224
 
225
  with gr.Blocks(
@@ -246,22 +246,22 @@ with gr.Blocks(
246
 
247
  gr.HTML("<p><b>Step 2:</b> Choose the input and output language.</p>")
248
 
249
- # src_lang = gr.Dropdown(
250
- # choices=["English", "Spanish", "French", "German"],
251
- # value="English",
252
- # label="Input audio is spoken in:"
253
- # )
254
-
255
- # with gr.Column():
256
- # tgt_lang = gr.Dropdown(
257
- # choices=["English", "Spanish", "French", "German"],
258
- # value="English",
259
- # label="Transcribe in language:"
260
- # )
261
- # pnc = gr.Checkbox(
262
- # value=True,
263
- # label="Punctuation & Capitalization in transcript?",
264
- # )
265
 
266
  with gr.Column():
267
 
@@ -279,21 +279,21 @@ with gr.Blocks(
279
 
280
  go_button.click(
281
  fn=transcribe,
282
- inputs = [audio_file, "English", "English", True],
283
  outputs = [model_output_text_box]
284
  )
285
 
286
- # call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
287
- # src_lang.change(
288
- # fn=on_src_or_tgt_lang_change,
289
- # inputs=[src_lang, tgt_lang, pnc],
290
- # outputs=[src_lang, tgt_lang, pnc],
291
- # )
292
- # tgt_lang.change(
293
- # fn=on_src_or_tgt_lang_change,
294
- # inputs=[src_lang, tgt_lang, pnc],
295
- # outputs=[src_lang, tgt_lang, pnc],
296
- # )
297
 
298
 
299
  demo.queue()
 
142
  return output_text
143
 
144
  # add logic to make sure dropdown menus only suggest valid combos
145
+ def on_src_or_tgt_lang_change(src_lang_value, tgt_lang_value, pnc_value):
146
+ """Callback function for when src_lang or tgt_lang dropdown menus are changed.
147
+
148
+ Args:
149
+ src_lang_value(string), tgt_lang_value (string), pnc_value(bool) - the current
150
+ chosen "values" of each Gradio component
151
+ Returns:
152
+ src_lang, tgt_lang, pnc - these are the new Gradio components that will be displayed
153
+
154
+ """
155
+
156
+ if src_lang_value == "English" and tgt_lang_value == "English":
157
+ # src_lang and tgt_lang can go anywhere
158
+ src_lang = gr.Dropdown(
159
+ choices=["English", "Spanish", "French", "German"],
160
+ value=src_lang_value,
161
+ label="Input audio is spoken in:"
162
+ )
163
+ tgt_lang = gr.Dropdown(
164
+ choices=["English", "Spanish", "French", "German"],
165
+ value=tgt_lang_value,
166
+ label="Transcribe in language:"
167
+ )
168
+ elif src_lang_value == "English":
169
+ # src is English & tgt is non-English
170
+ # => src can only be English or current tgt_lang_values
171
+ # & tgt can be anything
172
+ src_lang = gr.Dropdown(
173
+ choices=["English", tgt_lang_value],
174
+ value=src_lang_value,
175
+ label="Input audio is spoken in:"
176
+ )
177
+ tgt_lang = gr.Dropdown(
178
+ choices=["English", "Spanish", "French", "German"],
179
+ value=tgt_lang_value,
180
+ label="Transcribe in language:"
181
+ )
182
+ elif tgt_lang_value == "English":
183
+ # src is non-English & tgt is English
184
+ # => src can be anything
185
+ # & tgt can only be English or current src_lang_value
186
+ src_lang = gr.Dropdown(
187
+ choices=["English", "Spanish", "French", "German"],
188
+ value=src_lang_value,
189
+ label="Input audio is spoken in:"
190
+ )
191
+ tgt_lang = gr.Dropdown(
192
+ choices=["English", src_lang_value],
193
+ value=tgt_lang_value,
194
+ label="Transcribe in language:"
195
+ )
196
+ else:
197
+ # both src and tgt are non-English
198
+ # => both src and tgt can only be switch to English or themselves
199
+ src_lang = gr.Dropdown(
200
+ choices=["English", src_lang_value],
201
+ value=src_lang_value,
202
+ label="Input audio is spoken in:"
203
+ )
204
+ tgt_lang = gr.Dropdown(
205
+ choices=["English", tgt_lang_value],
206
+ value=tgt_lang_value,
207
+ label="Transcribe in language:"
208
+ )
209
+ # let pnc be anything if src_lang_value == tgt_lang_value, else fix to True
210
+ if src_lang_value == tgt_lang_value:
211
+ pnc = gr.Checkbox(
212
+ value=pnc_value,
213
+ label="Punctuation & Capitalization in transcript?",
214
+ interactive=True
215
+ )
216
+ else:
217
+ pnc = gr.Checkbox(
218
+ value=True,
219
+ label="Punctuation & Capitalization in transcript?",
220
+ interactive=False
221
+ )
222
+ return src_lang, tgt_lang, pnc
223
 
224
 
225
  with gr.Blocks(
 
246
 
247
  gr.HTML("<p><b>Step 2:</b> Choose the input and output language.</p>")
248
 
249
+ src_lang = gr.Dropdown(
250
+ choices=["English", "Spanish", "French", "German"],
251
+ value="English",
252
+ label="Input audio is spoken in:"
253
+ )
254
+
255
+ with gr.Column():
256
+ tgt_lang = gr.Dropdown(
257
+ choices=["English", "Spanish", "French", "German"],
258
+ value="English",
259
+ label="Transcribe in language:"
260
+ )
261
+ pnc = gr.Checkbox(
262
+ value=True,
263
+ label="Punctuation & Capitalization in transcript?",
264
+ )
265
 
266
  with gr.Column():
267
 
 
279
 
280
  go_button.click(
281
  fn=transcribe,
282
+ inputs = [audio_file, src_lang, tgt_lang, pnc],
283
  outputs = [model_output_text_box]
284
  )
285
 
286
+ call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
287
+ src_lang.change(
288
+ fn=on_src_or_tgt_lang_change,
289
+ inputs=[src_lang, tgt_lang, pnc],
290
+ outputs=[src_lang, tgt_lang, pnc],
291
+ )
292
+ tgt_lang.change(
293
+ fn=on_src_or_tgt_lang_change,
294
+ inputs=[src_lang, tgt_lang, pnc],
295
+ outputs=[src_lang, tgt_lang, pnc],
296
+ )
297
 
298
 
299
  demo.queue()