jerrypan7 commited on
Commit
65a4fb1
·
verified ·
1 Parent(s): e2c6728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -321,23 +321,23 @@ async def inference_via_llm_api(input_text, min_new_tokens=2, max_new_tokens=64)
321
  return "The system got some error during vLLM generation. Please try it again."
322
 
323
  async def transcribe_and_speak(audio, source_lang, target_lang, youtube_url=None, target_speaker=None, progress_tracker=None):
324
- global transcription_update, translation_update, audio_update, acc_cosy_audio
325
  transcription_update = {"content": "", "new": False}
326
  translation_update = {"content": "", "new": False}
327
  audio_update = {"content": None, "new": False}
328
  acc_cosy_audio =None
329
  video_path = None
330
-
331
  #progress = gr.Progress();
332
 
333
  #progress(0.1, "started:")
334
  if youtube_url:
335
  audio = await download_youtube_audio(youtube_url)
336
  if audio is None:
337
- return "Failed to download YouTube audio.", None, None, video_path
338
  audio, video_path = audio
339
  if not audio:
340
- return "Please provide an audio input or a valid YouTube URL.", None, None, video_path
341
 
342
  # ASR
343
  #progress(0.2, "ASR started:")
@@ -358,7 +358,7 @@ async def transcribe_and_speak(audio, source_lang, target_lang, youtube_url=None
358
  transcription_update["content"] = transcription
359
  transcription_update["new"] = True
360
  else:
361
- return "ASR failed", None, None, video_path
362
  #progress(0.4, "ASR done:")
363
 
364
 
@@ -455,7 +455,7 @@ async def transcribe_and_speak(audio, source_lang, target_lang, youtube_url=None
455
  if accumulated_audio is not None:
456
  return transcription, translated_text, audio_update["content"], video_path, (sample_rate,accumulated_audio)
457
  else:
458
- return transcription, translated_text, "TTS failed", video_path, accumulated_audio
459
 
460
  """
461
  async def run_speech_translation(audio, source_lang, target_lang, youtube_url, target_speaker):
@@ -553,7 +553,7 @@ with gr.Blocks() as demo:
553
 
554
 
555
  temp_video_path = None
556
- transcription, translated_text, audio_chunksr, temp_video_path,accumulated_aud_buf = await transcribe_and_speak(audio, source_lang, target_lang, youtube_url, target_speaker)
557
 
558
  yield (1,
559
  gr.update(interactive=True),
@@ -724,6 +724,6 @@ with gr.Blocks() as demo:
724
 
725
  demo.queue()
726
 
727
- demo.launch(auth=(os.getenv("DEV_USER"), os.getenv("DEV_PWD")))
728
- #asyncio.run(demo.launch(auth=(os.getenv("DEV_USER"), os.getenv("DEV_PWD"))))
729
 
 
321
  return "The system got some error during vLLM generation. Please try it again."
322
 
323
  async def transcribe_and_speak(audio, source_lang, target_lang, youtube_url=None, target_speaker=None, progress_tracker=None):
324
+ global transcription_update, translation_update, audio_update, acc_cosy_audio,audio_update_event
325
  transcription_update = {"content": "", "new": False}
326
  translation_update = {"content": "", "new": False}
327
  audio_update = {"content": None, "new": False}
328
  acc_cosy_audio =None
329
  video_path = None
330
+ audio_update_event.clear()
331
  #progress = gr.Progress();
332
 
333
  #progress(0.1, "started:")
334
  if youtube_url:
335
  audio = await download_youtube_audio(youtube_url)
336
  if audio is None:
337
+ return "Failed to download YouTube audio.", None, None, video_path,(22050, accumulated_audio)
338
  audio, video_path = audio
339
  if not audio:
340
+ return "Please provide an audio input or a valid YouTube URL.", None, None, video_path,(22050, accumulated_audio)
341
 
342
  # ASR
343
  #progress(0.2, "ASR started:")
 
358
  transcription_update["content"] = transcription
359
  transcription_update["new"] = True
360
  else:
361
+ return "ASR failed", None, None, video_path,(22050, accumulated_audio)
362
  #progress(0.4, "ASR done:")
363
 
364
 
 
455
  if accumulated_audio is not None:
456
  return transcription, translated_text, audio_update["content"], video_path, (sample_rate,accumulated_audio)
457
  else:
458
+ return transcription, translated_text, "TTS failed", video_path, (sample_rate, accumulated_audio)
459
 
460
  """
461
  async def run_speech_translation(audio, source_lang, target_lang, youtube_url, target_speaker):
 
553
 
554
 
555
  temp_video_path = None
556
+ transcription, translated_text, audio_chunksr, temp_video_path, accumulated_aud_buf = await transcribe_and_speak(audio, source_lang, target_lang, youtube_url, target_speaker)
557
 
558
  yield (1,
559
  gr.update(interactive=True),
 
724
 
725
  demo.queue()
726
 
727
+ #demo.launch(auth=(os.getenv("DEV_USER"), os.getenv("DEV_PWD")))
728
+ asyncio.run(demo.launch(auth=(os.getenv("DEV_USER"), os.getenv("DEV_PWD"))))
729