DILEEPJAAT commited on
Commit
f4095d8
·
verified ·
1 Parent(s): 7f7c6e1

Upload 8 files

Browse files
Files changed (2) hide show
  1. app.py +14 -13
  2. tests/test_zerogpu_config.py +8 -0
app.py CHANGED
@@ -30,9 +30,9 @@ from subtitle_utils import build_cues, chunks_to_words, format_duration, to_json
30
 
31
 
32
  APP_TITLE = "CaptionCraft AI"
33
- MODEL_ID = os.getenv("WHISPER_MODEL_ID", "openai/whisper-small")
34
  MAX_UPLOAD_MB = int(os.getenv("MAX_UPLOAD_MB", "100"))
35
- MAX_AUDIO_MINUTES = int(os.getenv("MAX_AUDIO_MINUTES", "45"))
36
  OUTPUT_DIR = Path(tempfile.gettempdir()) / "captioncraft_downloads"
37
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
38
 
@@ -188,9 +188,10 @@ def _estimate_gpu_duration(audio_file: str | None = None, *args, **kwargs) -> in
188
  except Exception:
189
  # Keep the scheduler estimate conservative when metadata cannot be probed.
190
  return 60
191
- # Whisper-small on the shared Blackwell GPU is substantially faster than realtime.
192
- # Cap requests below the free account's 5-minute daily allowance.
193
- return max(45, min(240, int(math.ceil(30 + audio_seconds * 0.075))))
 
194
 
195
 
196
  @spaces.GPU(duration=_estimate_gpu_duration)
@@ -233,12 +234,12 @@ def generate_subtitles(
233
  progress(0.08, desc="Preparing lightweight 16 kHz mono audio…")
234
  _prepare_audio(source, wav_path, duration)
235
 
236
- progress(0.15, desc="Whisper-small is ready; reserving ZeroGPU for transcription…")
237
  asr = _ASR_PIPELINE
238
 
239
  generate_kwargs: dict[str, Any] = {
240
  "task": "translate" if task_mode == "translate" else "transcribe",
241
- "num_beams": 1,
242
  "condition_on_prev_tokens": False,
243
  }
244
  if language and language != "auto":
@@ -382,7 +383,7 @@ with gr.Blocks(
382
  gr.HTML(
383
  """
384
  <section id="cc-hero">
385
- <span class="cc-chip">WHISPER-SMALL · ZERO GPU</span><span class="cc-chip">AUDIO → SUBTITLE FILES</span>
386
  <h1>CaptionCraft AI</h1>
387
  <p>Turn spoken audio into clean, timed subtitle files. ZeroGPU is allocated only for transcription. Download SRT, VTT, TXT or JSON — no video rendering or burned-in captions.</p>
388
  </section>
@@ -409,7 +410,7 @@ with gr.Blocks(
409
  choices=LANGUAGES,
410
  value="auto",
411
  label="Spoken language",
412
- info="Auto-detect is recommended. Whisper-small supports 99 languages.",
413
  scale=1,
414
  )
415
  task_input = gr.Radio(
@@ -449,9 +450,9 @@ with gr.Blocks(
449
  with gr.Accordion("How it works & limitations", open=False):
450
  gr.Markdown(
451
  """
452
- - **Model:** `openai/whisper-small` from Hugging Face, a multilingual 244M-parameter ASR model.
453
- - **Execution:** Hugging Face ZeroGPU. Whisper-small is loaded onto the shared CUDA device at startup and the transcription callback is wrapped with `@spaces.GPU`.
454
- - **Resource use:** Audio is converted to mono 16 kHz WAV, then transcribed in overlapping 30-second chunks using FP16 and PyTorch inference mode.
455
  - **Free quota:** Hugging Face documents 5 minutes of ZeroGPU time per day for free accounts. The app estimates requested GPU duration from the uploaded audio length; actual availability depends on remaining daily quota.
456
  - **Timing:** Whisper word timestamps are used where available. If the model/runtime cannot provide them, segment timestamps are used and individual word timings are proportionally estimated.
457
  - **No video editing:** This tool only creates caption files. It never renders a video or burns subtitles into a video.
@@ -459,7 +460,7 @@ with gr.Blocks(
459
  """
460
  )
461
 
462
- gr.HTML("<div class='cc-foot'>CaptionCraft AI · OpenAI Whisper-small · Apache-2.0 model license</div>")
463
 
464
  generate_btn.click(
465
  fn=generate_subtitles,
 
30
 
31
 
32
  APP_TITLE = "CaptionCraft AI"
33
+ MODEL_ID = "openai/whisper-medium"
34
  MAX_UPLOAD_MB = int(os.getenv("MAX_UPLOAD_MB", "100"))
35
+ MAX_AUDIO_MINUTES = int(os.getenv("MAX_AUDIO_MINUTES", "20"))
36
  OUTPUT_DIR = Path(tempfile.gettempdir()) / "captioncraft_downloads"
37
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
38
 
 
188
  except Exception:
189
  # Keep the scheduler estimate conservative when metadata cannot be probed.
190
  return 60
191
+ # Whisper-medium with beam search needs a larger reservation than small.
192
+ # Keep every request below the 240-second per-call cap; ZeroGPU still
193
+ # checks the visitor's remaining daily quota before allocating the GPU.
194
+ return max(30, min(240, int(math.ceil(30 + audio_seconds * 0.12))))
195
 
196
 
197
  @spaces.GPU(duration=_estimate_gpu_duration)
 
234
  progress(0.08, desc="Preparing lightweight 16 kHz mono audio…")
235
  _prepare_audio(source, wav_path, duration)
236
 
237
+ progress(0.15, desc="Whisper-medium is ready; reserving ZeroGPU for transcription…")
238
  asr = _ASR_PIPELINE
239
 
240
  generate_kwargs: dict[str, Any] = {
241
  "task": "translate" if task_mode == "translate" else "transcribe",
242
+ "num_beams": 5,
243
  "condition_on_prev_tokens": False,
244
  }
245
  if language and language != "auto":
 
383
  gr.HTML(
384
  """
385
  <section id="cc-hero">
386
+ <span class="cc-chip">WHISPER-MEDIUM · ZERO GPU</span><span class="cc-chip">AUDIO → SUBTITLE FILES</span>
387
  <h1>CaptionCraft AI</h1>
388
  <p>Turn spoken audio into clean, timed subtitle files. ZeroGPU is allocated only for transcription. Download SRT, VTT, TXT or JSON — no video rendering or burned-in captions.</p>
389
  </section>
 
410
  choices=LANGUAGES,
411
  value="auto",
412
  label="Spoken language",
413
+ info="Auto-detect is recommended. Whisper-medium supports 99 languages; the dropdown lists common languages.",
414
  scale=1,
415
  )
416
  task_input = gr.Radio(
 
450
  with gr.Accordion("How it works & limitations", open=False):
451
  gr.Markdown(
452
  """
453
+ - **Model:** `openai/whisper-medium` from Hugging Face, a multilingual 769M-parameter ASR model.
454
+ - **Execution:** Hugging Face ZeroGPU. Whisper-medium is loaded onto the shared CUDA device at startup and the transcription callback is wrapped with `@spaces.GPU`.
455
+ - **Resource use:** Audio is converted to mono 16 kHz WAV, then transcribed in overlapping 30-second chunks using FP16, 5-beam decoding and PyTorch inference mode.
456
  - **Free quota:** Hugging Face documents 5 minutes of ZeroGPU time per day for free accounts. The app estimates requested GPU duration from the uploaded audio length; actual availability depends on remaining daily quota.
457
  - **Timing:** Whisper word timestamps are used where available. If the model/runtime cannot provide them, segment timestamps are used and individual word timings are proportionally estimated.
458
  - **No video editing:** This tool only creates caption files. It never renders a video or burns subtitles into a video.
 
460
  """
461
  )
462
 
463
+ gr.HTML("<div class='cc-foot'>CaptionCraft AI · OpenAI Whisper-medium · Apache-2.0 model license</div>")
464
 
465
  generate_btn.click(
466
  fn=generate_subtitles,
tests/test_zerogpu_config.py CHANGED
@@ -33,3 +33,11 @@ def test_app_uses_zero_gpu_and_does_not_mask_cuda():
33
  assert "torch.float16" in app
34
  assert "dtype=MODEL_DTYPE" in app
35
  assert "torch_dtype=MODEL_DTYPE" not in app
 
 
 
 
 
 
 
 
 
33
  assert "torch.float16" in app
34
  assert "dtype=MODEL_DTYPE" in app
35
  assert "torch_dtype=MODEL_DTYPE" not in app
36
+
37
+
38
+ def test_app_uses_whisper_medium_and_beam_search_for_quality():
39
+ app = (ROOT / "app.py").read_text(encoding="utf-8")
40
+ assert 'MODEL_ID = "openai/whisper-medium"' in app
41
+ assert '"num_beams": 5' in app
42
+ assert "769M-parameter" in app
43
+ assert "WHISPER-SMALL" not in app