staraks commited on
Commit
4987752
·
verified ·
1 Parent(s): bed03fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -21
app.py CHANGED
@@ -608,7 +608,15 @@ def transcribe_multiple(
608
 
609
  # ----------------------- Gradio wrapper (streaming) -----------------------
610
  def run_transcription_wrapper(
611
- files, model_name, merge, zip_file, zip_password, enable_memory, advanced_options_state
 
 
 
 
 
 
 
 
612
  ):
613
  """
614
  Gradio callback that streams results from transcribe_multiple.
@@ -618,7 +626,7 @@ def run_transcription_wrapper(
618
  try:
619
  audio_input = files
620
 
621
- # Normalise zip path from different possible Gradio file types
622
  zip_path = None
623
  if zip_file:
624
  if isinstance(zip_file, (str, os.PathLike)):
@@ -628,6 +636,12 @@ def run_transcription_wrapper(
628
  elif isinstance(zip_file, dict) and zip_file.get("name"):
629
  zip_path = zip_file["name"]
630
 
 
 
 
 
 
 
631
  adv = {} # placeholder for future advanced options
632
 
633
  # Stream results from the core generator
@@ -637,15 +651,12 @@ def run_transcription_wrapper(
637
  adv,
638
  merge_checkbox=merge,
639
  zip_file=zip_path,
640
- zip_password=zip_password,
641
  enable_memory=enable_memory,
642
  ):
643
- # Each yield must return 4 values, matching:
644
- # [logs_textbox, transcripts_textbox, download_file, progress_number]
645
  yield logs, transcripts, word_path, percent
646
 
647
  except Exception:
648
- # Surface any unexpected error into the Logs textbox
649
  tb = traceback.format_exc()
650
  logs = f"EXCEPTION in run_transcription_wrapper:\n{tb}"
651
  transcripts = "ERROR: transcription did not start or failed unexpectedly."
@@ -658,46 +669,73 @@ print("DEBUG: building Gradio Blocks", flush=True)
658
  with gr.Blocks(title="Whisper Transcriber") as demo:
659
  gr.Markdown(
660
  "## Whisper Transcriber\n"
661
- "Upload one or more audio files (or a zip) on the left, then click **Transcribe**.\n"
662
- "Progress, logs, and text output will appear on the right."
663
  )
664
 
665
  with gr.Row():
666
- # LEFT: Inputs
667
  with gr.Column(scale=1):
668
  gr.Markdown("### Input")
 
669
  file_input = gr.File(
670
  label="Audio files",
671
  file_count="multiple",
672
  type="filepath",
 
673
  )
 
674
  zip_input = gr.File(
675
- label="Zip with audio (optional)",
676
  file_count="single",
677
  type="filepath",
 
678
  )
 
 
 
 
 
 
 
 
 
 
 
 
679
  zip_password = gr.Textbox(
680
- label="Zip password (optional)",
681
- placeholder="Leave empty if no password",
682
  )
 
683
  model_select = gr.Dropdown(
684
  choices=["small", "medium", "large", "base"],
685
  value="small",
686
  label="Whisper model",
687
  )
 
688
  merge_checkbox = gr.Checkbox(
689
  label="Merge all transcripts into one .docx",
690
  value=True,
691
  )
 
692
  memory_checkbox = gr.Checkbox(
693
  label="Enable correction memory",
694
  value=False,
695
  )
 
696
  submit = gr.Button("Transcribe", variant="primary")
697
 
698
- # RIGHT: Outputs
699
  with gr.Column(scale=1):
700
  gr.Markdown("### Output")
 
 
 
 
 
 
 
701
  progress_num = gr.Slider(
702
  minimum=0,
703
  maximum=100,
@@ -706,19 +744,16 @@ with gr.Blocks(title="Whisper Transcriber") as demo:
706
  label="Progress (%)",
707
  interactive=False,
708
  )
 
 
 
 
 
709
  logs = gr.Textbox(
710
  label="Logs",
711
  lines=10,
712
  interactive=False,
713
  )
714
- transcripts_out = gr.Textbox(
715
- label="Transcript",
716
- lines=15,
717
- interactive=False,
718
- )
719
- download_file = gr.File(
720
- label="Merged .docx (when available)"
721
- )
722
 
723
  submit.click(
724
  fn=run_transcription_wrapper,
@@ -728,9 +763,12 @@ with gr.Blocks(title="Whisper Transcriber") as demo:
728
  merge_checkbox,
729
  zip_input,
730
  zip_password,
 
 
731
  memory_checkbox,
732
  gr.State({}),
733
  ],
 
734
  outputs=[logs, transcripts_out, download_file, progress_num],
735
  )
736
 
 
608
 
609
  # ----------------------- Gradio wrapper (streaming) -----------------------
610
  def run_transcription_wrapper(
611
+ files,
612
+ model_name,
613
+ merge,
614
+ zip_file,
615
+ zip_password,
616
+ use_default_zip_pass,
617
+ default_zip_password,
618
+ enable_memory,
619
+ advanced_options_state,
620
  ):
621
  """
622
  Gradio callback that streams results from transcribe_multiple.
 
626
  try:
627
  audio_input = files
628
 
629
+ # Normalize zip path
630
  zip_path = None
631
  if zip_file:
632
  if isinstance(zip_file, (str, os.PathLike)):
 
636
  elif isinstance(zip_file, dict) and zip_file.get("name"):
637
  zip_path = zip_file["name"]
638
 
639
+ # Decide final zip password
640
+ if use_default_zip_pass and (not zip_password or zip_password.strip() == ""):
641
+ final_zip_password = default_zip_password
642
+ else:
643
+ final_zip_password = zip_password
644
+
645
  adv = {} # placeholder for future advanced options
646
 
647
  # Stream results from the core generator
 
651
  adv,
652
  merge_checkbox=merge,
653
  zip_file=zip_path,
654
+ zip_password=final_zip_password,
655
  enable_memory=enable_memory,
656
  ):
 
 
657
  yield logs, transcripts, word_path, percent
658
 
659
  except Exception:
 
660
  tb = traceback.format_exc()
661
  logs = f"EXCEPTION in run_transcription_wrapper:\n{tb}"
662
  transcripts = "ERROR: transcription did not start or failed unexpectedly."
 
669
  with gr.Blocks(title="Whisper Transcriber") as demo:
670
  gr.Markdown(
671
  "## Whisper Transcriber\n"
672
+ "Upload audio files or a ZIP on the left and click **Transcribe**.\n"
673
+ "Transcript, progress, download, and logs appear on the right."
674
  )
675
 
676
  with gr.Row():
677
+ # LEFT: Inputs (small boxes, simple controls)
678
  with gr.Column(scale=1):
679
  gr.Markdown("### Input")
680
+
681
  file_input = gr.File(
682
  label="Audio files",
683
  file_count="multiple",
684
  type="filepath",
685
+ height=60, # small box
686
  )
687
+
688
  zip_input = gr.File(
689
+ label="ZIP with audio (optional)",
690
  file_count="single",
691
  type="filepath",
692
+ height=60, # small box
693
  )
694
+
695
+ use_default_zip_pass = gr.Checkbox(
696
+ label="Use default ZIP password",
697
+ value=False,
698
+ )
699
+
700
+ default_zip_password = gr.Textbox(
701
+ label="Default ZIP password",
702
+ value="dietcoke1", # you can change this
703
+ interactive=True,
704
+ )
705
+
706
  zip_password = gr.Textbox(
707
+ label="ZIP password (override)",
708
+ placeholder="If empty, default password will be used",
709
  )
710
+
711
  model_select = gr.Dropdown(
712
  choices=["small", "medium", "large", "base"],
713
  value="small",
714
  label="Whisper model",
715
  )
716
+
717
  merge_checkbox = gr.Checkbox(
718
  label="Merge all transcripts into one .docx",
719
  value=True,
720
  )
721
+
722
  memory_checkbox = gr.Checkbox(
723
  label="Enable correction memory",
724
  value=False,
725
  )
726
+
727
  submit = gr.Button("Transcribe", variant="primary")
728
 
729
+ # RIGHT: Outputs (Transcript → Progress → Download → Logs)
730
  with gr.Column(scale=1):
731
  gr.Markdown("### Output")
732
+
733
+ transcripts_out = gr.Textbox(
734
+ label="Transcript",
735
+ lines=18,
736
+ interactive=False,
737
+ )
738
+
739
  progress_num = gr.Slider(
740
  minimum=0,
741
  maximum=100,
 
744
  label="Progress (%)",
745
  interactive=False,
746
  )
747
+
748
+ download_file = gr.File(
749
+ label="Merged .docx (when available)"
750
+ )
751
+
752
  logs = gr.Textbox(
753
  label="Logs",
754
  lines=10,
755
  interactive=False,
756
  )
 
 
 
 
 
 
 
 
757
 
758
  submit.click(
759
  fn=run_transcription_wrapper,
 
763
  merge_checkbox,
764
  zip_input,
765
  zip_password,
766
+ use_default_zip_pass,
767
+ default_zip_password,
768
  memory_checkbox,
769
  gr.State({}),
770
  ],
771
+ # The function yields: logs, transcripts, download_file, progress
772
  outputs=[logs, transcripts_out, download_file, progress_num],
773
  )
774