Nymbo commited on
Commit
8f7b84c
·
verified ·
1 Parent(s): d4549f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -39
app.py CHANGED
@@ -31,6 +31,9 @@ CHUNK_LENGTH_S = 30 # Split long audio into 30-second chunks
31
  SAMPLE_RATE = 16000 # Whisper expects 16kHz audio
32
  YT_LENGTH_LIMIT_S = 3600 # Limit YouTube videos to 1 hour
33
 
 
 
 
34
  # Lazy load state for the Whisper model
35
  _WHISPER_STATE = {"initialized": False, "pipe": None, "device": "cpu"}
36
 
@@ -451,50 +454,51 @@ with gr.Blocks(title="Whisper-ASR") as demo:
451
  api_name="transcribe",
452
  )
453
 
454
- # Tab 2: YouTube
455
- with gr.TabItem("YouTube"):
456
- with gr.Row():
457
- with gr.Column():
458
- yt_url_input = gr.Textbox(
459
- label="YouTube URL",
460
- placeholder="Paste a YouTube video URL here...",
461
- lines=1,
462
- )
463
-
464
- with gr.Row():
465
- yt_task_radio = gr.Radio(
466
- choices=["transcribe", "translate"],
467
- value="transcribe",
468
- label="Task",
469
- info="Translate converts any language to English",
470
- )
471
- yt_language_dropdown = gr.Dropdown(
472
- choices=LANGUAGES,
473
- value="auto",
474
- label="Language",
475
  )
476
 
477
- yt_timestamps_checkbox = gr.Checkbox(
478
- label="Return Timestamps",
479
- value=False,
480
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
481
 
482
- yt_transcribe_btn = gr.Button("Transcribe YouTube", variant="primary")
483
 
484
- with gr.Column():
485
- yt_embed = gr.HTML(label="Video")
486
- yt_output = gr.Textbox(
487
- label="Transcription",
488
- placeholder="Transcribed text will appear here...",
489
- lines=10,
490
- )
491
 
492
- yt_transcribe_btn.click(
493
- fn=transcribe_youtube_streaming,
494
- inputs=[yt_url_input, yt_task_radio, yt_language_dropdown, yt_timestamps_checkbox],
495
- outputs=[yt_embed, yt_output],
496
- api_name="transcribe_youtube",
497
- )
498
 
499
 
500
  if __name__ == "__main__":
 
31
  SAMPLE_RATE = 16000 # Whisper expects 16kHz audio
32
  YT_LENGTH_LIMIT_S = 3600 # Limit YouTube videos to 1 hour
33
 
34
+ # Detect if running on Hugging Face Spaces (YouTube won't work there due to network restrictions)
35
+ IS_HF_SPACE = os.environ.get("SPACE_ID") is not None
36
+
37
  # Lazy load state for the Whisper model
38
  _WHISPER_STATE = {"initialized": False, "pipe": None, "device": "cpu"}
39
 
 
454
  api_name="transcribe",
455
  )
456
 
457
+ # Tab 2: YouTube (only shown when running locally)
458
+ if not IS_HF_SPACE:
459
+ with gr.TabItem("YouTube"):
460
+ with gr.Row():
461
+ with gr.Column():
462
+ yt_url_input = gr.Textbox(
463
+ label="YouTube URL",
464
+ placeholder="Paste a YouTube video URL here...",
465
+ lines=1,
 
 
 
 
 
 
 
 
 
 
 
 
466
  )
467
 
468
+ with gr.Row():
469
+ yt_task_radio = gr.Radio(
470
+ choices=["transcribe", "translate"],
471
+ value="transcribe",
472
+ label="Task",
473
+ info="Translate converts any language to English",
474
+ )
475
+ yt_language_dropdown = gr.Dropdown(
476
+ choices=LANGUAGES,
477
+ value="auto",
478
+ label="Language",
479
+ )
480
+
481
+ yt_timestamps_checkbox = gr.Checkbox(
482
+ label="Return Timestamps",
483
+ value=False,
484
+ )
485
 
486
+ yt_transcribe_btn = gr.Button("Transcribe YouTube", variant="primary")
487
 
488
+ with gr.Column():
489
+ yt_embed = gr.HTML(label="Video")
490
+ yt_output = gr.Textbox(
491
+ label="Transcription",
492
+ placeholder="Transcribed text will appear here...",
493
+ lines=10,
494
+ )
495
 
496
+ yt_transcribe_btn.click(
497
+ fn=transcribe_youtube_streaming,
498
+ inputs=[yt_url_input, yt_task_radio, yt_language_dropdown, yt_timestamps_checkbox],
499
+ outputs=[yt_embed, yt_output],
500
+ api_name="transcribe_youtube",
501
+ )
502
 
503
 
504
  if __name__ == "__main__":