almncarlo commited on
Commit
843bc29
β€’
1 Parent(s): 3b233e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -60
app.py CHANGED
@@ -150,24 +150,7 @@ def on_src_or_tgt_lang_change(src_lang_value, tgt_lang_value, pnc_value):
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
- Note: I found the required logic is easier to understand if you think about the possible src & tgt langs as
155
- a matrix, e.g. with English, Spanish, French, German as the langs, and only transcription in the same language,
156
- and X -> English and English -> X translation being allowed, the matrix looks like the diagram below ("Y" means it is
157
- allowed to go into that state).
158
- It is easier to understand the code if you think about which state you are in, given the current src_lang_value and
159
- tgt_lang_value, and then which states you can go to from there.
160
-
161
- tgt lang
162
- - |EN |ES |FR |DE
163
- ------------------
164
- EN| Y | Y | Y | Y
165
- ------------------
166
- src ES| Y | Y | |
167
- lang ------------------
168
- FR| Y | | Y |
169
- ------------------
170
- DE| Y | | | Y
171
  """
172
 
173
  if src_lang_value == "English" and tgt_lang_value == "English":
@@ -251,42 +234,42 @@ with gr.Blocks(
251
  theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg) # make text slightly bigger (default is text_md )
252
  ) as demo:
253
 
254
- gr.HTML("<h1 style='text-align: center'>NeMo Canary model: Transcribe & Translate audio</h1>")
255
 
256
  with gr.Row():
257
  with gr.Column():
258
  gr.HTML(
259
- "<p><b>Step 1:</b> Upload an audio file or record with your microphone.</p>"
260
-
261
- "<p style='color: #A0A0A0;'>This demo supports audio files up to 10 mins long. "
262
- "You can transcribe longer files locally with this NeMo "
263
- "<a href='https://github.com/NVIDIA/NeMo/blob/main/examples/asr/speech_multitask/speech_to_text_aed_chunked_infer.py'>script</a>.</p>"
264
  )
265
 
266
  audio_file = gr.Audio(sources=["microphone", "upload"], type="filepath")
267
 
268
  gr.HTML("<p><b>Step 2:</b> Choose the input and output language.</p>")
269
 
270
- src_lang = gr.Dropdown(
271
- choices=["English", "Spanish", "French", "German"],
272
- value="English",
273
- label="Input audio is spoken in:"
274
- )
275
-
276
- with gr.Column():
277
- tgt_lang = gr.Dropdown(
278
- choices=["English", "Spanish", "French", "German"],
279
- value="English",
280
- label="Transcribe in language:"
281
- )
282
- pnc = gr.Checkbox(
283
- value=True,
284
- label="Punctuation & Capitalization in transcript?",
285
- )
 
 
 
 
286
 
287
  with gr.Column():
288
 
289
- gr.HTML("<p><b>Step 3:</b> Run the model.</p>")
290
 
291
  go_button = gr.Button(
292
  value="Run model",
@@ -298,15 +281,6 @@ with gr.Blocks(
298
  elem_id="model_output_text_box",
299
  )
300
 
301
- with gr.Row():
302
-
303
- gr.HTML(
304
- "<p style='text-align: center'>"
305
- "🐀 <a href='https://huggingface.co/nvidia/canary-1b' target='_blank'>Canary model</a> | "
306
- "πŸ§‘β€πŸ’» <a href='https://github.com/NVIDIA/NeMo' target='_blank'>NeMo Repository</a>"
307
- "</p>"
308
- )
309
-
310
  go_button.click(
311
  fn=transcribe,
312
  inputs = [audio_file, src_lang, tgt_lang, pnc],
@@ -314,16 +288,16 @@ with gr.Blocks(
314
  )
315
 
316
  # call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
317
- src_lang.change(
318
- fn=on_src_or_tgt_lang_change,
319
- inputs=[src_lang, tgt_lang, pnc],
320
- outputs=[src_lang, tgt_lang, pnc],
321
- )
322
- tgt_lang.change(
323
- fn=on_src_or_tgt_lang_change,
324
- inputs=[src_lang, tgt_lang, pnc],
325
- outputs=[src_lang, tgt_lang, pnc],
326
- )
327
 
328
 
329
  demo.queue()
 
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":
 
234
  theme=gr.themes.Default(text_size=gr.themes.sizes.text_lg) # make text slightly bigger (default is text_md )
235
  ) as demo:
236
 
237
+ gr.HTML("<h1 style='text-align: center'>MyAlexa</h1>")
238
 
239
  with gr.Row():
240
  with gr.Column():
241
  gr.HTML(
242
+ "<p>Upload an audio file or record with your microphone.</p>"
 
 
 
 
243
  )
244
 
245
  audio_file = gr.Audio(sources=["microphone", "upload"], type="filepath")
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
+ src_lang = "English"
267
+ tgt_lang = "English"
268
+ pnc = True
269
 
270
  with gr.Column():
271
 
272
+ gr.HTML("<p>Run the model.</p>")
273
 
274
  go_button = gr.Button(
275
  value="Run model",
 
281
  elem_id="model_output_text_box",
282
  )
283
 
 
 
 
 
 
 
 
 
 
284
  go_button.click(
285
  fn=transcribe,
286
  inputs = [audio_file, src_lang, tgt_lang, pnc],
 
288
  )
289
 
290
  # call on_src_or_tgt_lang_change whenever src_lang or tgt_lang dropdown menus are changed
291
+ # src_lang.change(
292
+ # fn=on_src_or_tgt_lang_change,
293
+ # inputs=[src_lang, tgt_lang, pnc],
294
+ # outputs=[src_lang, tgt_lang, pnc],
295
+ # )
296
+ # tgt_lang.change(
297
+ # fn=on_src_or_tgt_lang_change,
298
+ # inputs=[src_lang, tgt_lang, pnc],
299
+ # outputs=[src_lang, tgt_lang, pnc],
300
+ # )
301
 
302
 
303
  demo.queue()