cstr commited on
Commit
60c0a37
·
verified ·
1 Parent(s): 366b663

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -494,25 +494,26 @@ def transcribe_audio(input_source, pipeline_type, model_id, dtype, batch_size, d
494
  if verbose:
495
  yield verbose_messages, "", None
496
 
497
- # Determine if input_source is a URL or file
498
  audio_path = None
499
  is_temp_file = False
500
 
501
- if isinstance(input_source, str) and (input_source.startswith('http://') or input_source.startswith('https://')):
502
- # Input source is a URL
503
- audio_path, is_temp_file = download_audio(input_source, download_method)
504
- if not audio_path:
505
- error_msg = f"Error downloading audio from {input_source} using method {download_method}. Check logs for details."
506
- logging.error(error_msg)
507
- yield verbose_messages + error_msg, "", None
508
- return
509
- elif isinstance(input_source, str) and os.path.exists(input_source):
510
- # Input source is a local file path
511
- audio_path = input_source
512
- is_temp_file = False
513
- elif hasattr(input_source, 'name'):
514
- # Input source is an uploaded file object
515
- audio_path = input_source.name
 
516
  is_temp_file = False
517
  else:
518
  error_msg = "No valid audio source provided."
@@ -620,14 +621,13 @@ def transcribe_audio(input_source, pipeline_type, model_id, dtype, batch_size, d
620
  # Clean up temporary audio files
621
  if audio_path and is_temp_file and os.path.exists(audio_path):
622
  os.remove(audio_path)
623
-
624
  with gr.Blocks() as iface:
625
- gr.Markdown("# Multi-Pipeline Transcription")
626
- gr.Markdown("Transcribe audio using multiple pipelines and models.")
627
 
628
  with gr.Row():
629
- #input_source = gr.File(label="Audio Source (Upload a file or enter a URL/YouTube URL)")
630
- input_source = gr.Textbox(label="Audio Source (Upload a file or enter a URL/YouTube URL)")
631
  pipeline_type = gr.Dropdown(
632
  choices=["faster-batched", "faster-sequenced", "transformers"],
633
  label="Pipeline Type",
 
494
  if verbose:
495
  yield verbose_messages, "", None
496
 
497
+ # Determine if input_source is a URL, file path, or uploaded audio
498
  audio_path = None
499
  is_temp_file = False
500
 
501
+ if isinstance(input_source, str):
502
+ if input_source.startswith('http://') or input_source.startswith('https://'):
503
+ # Input source is a URL
504
+ audio_path, is_temp_file = download_audio(input_source, download_method)
505
+ if not audio_path:
506
+ error_msg = f"Error downloading audio from {input_source} using method {download_method}. Check logs for details."
507
+ logging.error(error_msg)
508
+ yield verbose_messages + error_msg, "", None
509
+ return
510
+ elif os.path.exists(input_source):
511
+ # Input source is a local file path
512
+ audio_path = input_source
513
+ is_temp_file = False
514
+ elif isinstance(input_source, dict) and 'path' in input_source:
515
+ # Input source is an uploaded audio file
516
+ audio_path = input_source['path']
517
  is_temp_file = False
518
  else:
519
  error_msg = "No valid audio source provided."
 
621
  # Clean up temporary audio files
622
  if audio_path and is_temp_file and os.path.exists(audio_path):
623
  os.remove(audio_path)
624
+
625
  with gr.Blocks() as iface:
626
+ gr.Markdown("# Audio Transcription")
627
+ gr.Markdown("Transcribe audio using multiple pipelines and (Faster) Whisper models.")
628
 
629
  with gr.Row():
630
+ input_source = gr.Audio(label="Audio Source (Upload a file or enter a URL/YouTube URL)")
 
631
  pipeline_type = gr.Dropdown(
632
  choices=["faster-batched", "faster-sequenced", "transformers"],
633
  label="Pipeline Type",