staraks commited on
Commit
5bbecec
·
verified ·
1 Parent(s): 34ecfcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -38
app.py CHANGED
@@ -484,45 +484,34 @@ def transcribe_multiple(audio_files, model_name, advanced_options, merge_checkbo
484
 
485
 
486
 
487
- # ----------------------- Gradio UI -----------------------
488
  def run_transcription_wrapper(files, model_name, merge, zip_file, zip_password, enable_memory, advanced_options_state):
489
- audio_input = files
490
- zip_path = None
491
- if zip_file:
492
- if isinstance(zip_file, (str, os.PathLike)):
493
- zip_path = str(zip_file)
494
- elif hasattr(zip_file, "name"):
495
- zip_path = zip_file.name
496
- elif isinstance(zip_file, dict) and zip_file.get("name"):
497
- zip_path = zip_file["name"]
498
- adv = {}
499
- return transcribe_multiple(audio_input, model_name, adv, merge_checkbox=merge, zip_file=zip_path, zip_password=zip_password, enable_memory=enable_memory)
500
-
501
- print("DEBUG: building Gradio Blocks", flush=True)
502
- demo = gr.Blocks()
503
-
504
- with demo:
505
- gr.Markdown("## Whisper Transcription (Spaces-ready)")
506
- with gr.Row():
507
- with gr.Column(scale=2):
508
- file_input = gr.File(label="Upload audio files (or zip)", file_count="multiple", type="filepath")
509
- zip_input = gr.File(label="Optional: Upload zip file containing audio", file_count="single", type="filepath")
510
- zip_password = gr.Textbox(label="Zip password (if any)", placeholder="password (optional)")
511
- model_select = gr.Dropdown(choices=["small","medium","large","base"], value="small", label="Whisper model")
512
- merge_checkbox = gr.Checkbox(label="Merge transcripts to a single .docx (downloadable)", value=True)
513
- memory_checkbox = gr.Checkbox(label="Enable persistent memory (word/phrase correction)", value=False)
514
- submit = gr.Button("Transcribe")
515
- with gr.Column(scale=3):
516
- logs = gr.Textbox(label="Logs (streaming)", lines=12)
517
- transcripts_out = gr.Textbox(label="Transcripts (streaming)", lines=12)
518
- download_file = gr.File(label="Merged .docx (when enabled)")
519
- progress_num = gr.Number(value=0, label="Progress (%)")
520
-
521
- submit.click(
522
- fn=run_transcription_wrapper,
523
- inputs=[file_input, model_select, merge_checkbox, zip_input, zip_password, memory_checkbox, gr.State({})],
524
- outputs=[logs, transcripts_out, download_file, progress_num],
525
- )
526
 
527
  # Launch
528
  if __name__ == "__main__":
 
484
 
485
 
486
 
487
+ # Defensive wrapper to surface exceptions into the Logs textbox
488
  def run_transcription_wrapper(files, model_name, merge, zip_file, zip_password, enable_memory, advanced_options_state):
489
+ import traceback, io
490
+ try:
491
+ audio_input = files
492
+ zip_path = None
493
+ if zip_file:
494
+ if isinstance(zip_file, (str, os.PathLike)):
495
+ zip_path = str(zip_file)
496
+ elif hasattr(zip_file, "name"):
497
+ zip_path = zip_file.name
498
+ elif isinstance(zip_file, dict) and zip_file.get("name"):
499
+ zip_path = zip_file["name"]
500
+ adv = {}
501
+ # return the generator directly (transcribe_multiple yields tuples)
502
+ return transcribe_multiple(audio_input, model_name, adv, merge_checkbox=merge, zip_file=zip_path, zip_password=zip_password, enable_memory=enable_memory)
503
+ except Exception as e:
504
+ # If anything raises before generator returned, produce a generator that yields the traceback
505
+ buf = io.StringIO()
506
+ traceback.print_exc(file=buf)
507
+ tb = buf.getvalue()
508
+ logs = f"EXCEPTION in run_transcription_wrapper:\n{tb}"
509
+ transcripts = "ERROR: transcription did not start due to exception."
510
+ # Yield once with logs and final 100% to stop spinner
511
+ def error_gen():
512
+ yield logs, transcripts, None, 100
513
+ return error_gen()
514
+
 
 
 
 
 
 
 
 
 
 
 
515
 
516
  # Launch
517
  if __name__ == "__main__":