Upload 8 files
Browse filesFiles changed (2)
29 unmodified lines303132333435363738149 unmodified lines18818919019119219319419519636 unmodified lines233234235236237238239240241242243244137 unmodified lines38238338438538638738820 unmodified lines40941041141241341441533 unmodified lines4494504514524534544554564571 unmodified line45946046146246346446529 unmodified linesAPP_TITLE = "CaptionCraft AI"MODEL_ID = os.getenv("WHISPER_MODEL_ID", "openai/whisper-small")MAX_UPLOAD_MB = int(os.getenv("MAX_UPLOAD_MB", "100"))MAX_AUDIO_MINUTES = int(os.getenv("MAX_AUDIO_MINUTES", "45"))OUTPUT_DIR = Path(tempfile.gettempdir()) / "captioncraft_downloads"OUTPUT_DIR.mkdir(parents=True, exist_ok=True)149 unmodified linesexcept Exception:# Keep the scheduler estimate conservative when metadata cannot be probed.return 60# Whisper-small on the shared Blackwell GPU is substantially faster than realtime.# Cap requests below the free account's 5-minute daily allowance.return max(45, min(240, int(math.ceil(30 + audio_seconds * 0.075))))@spaces.GPU(duration=_estimate_gpu_duration)36 unmodified linesprogress(0.08, desc="Preparing lightweight 16 kHz mono audio…")_prepare_audio(source, wav_path, duration)progress(0.15, desc="Whisper-small is ready; reserving ZeroGPU for transcription…")asr = _ASR_PIPELINEgenerate_kwargs: dict[str, Any] = {"task": "translate" if task_mode == "translate" else "transcribe","num_beams": 1,"condition_on_prev_tokens": False,}if language and language != "auto":137 unmodified linesgr.HTML("""<section id="cc-hero"><span class="cc-chip">WHISPER-SMALL · ZERO GPU</span><span class="cc-chip">AUDIO → SUBTITLE FILES</span><h1>CaptionCraft AI</h1><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></section>20 unmodified lineschoices=LANGUAGES,value="auto",label="Spoken language",info="Auto-detect is recommended. Whisper-small supports 99 languages.",scale=1,)task_input = gr.Radio(33 unmodified lineswith gr.Accordion("How it works & limitations", open=False):gr.Markdown("""- **Model:** `openai/whisper-small` from Hugging Face, a multilingual 244M-parameter ASR model.- **Execution:** Hugging Face ZeroGPU. Whisper-small is loaded onto the shared CUDA device at startup and the transcription callback is wrapped with `@spaces.GPU`.- **Resource use:** Audio is converted to mono 16 kHz WAV, then transcribed in overlapping 30-second chunks using FP16 and PyTorch inference mode.- **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.- **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.- **No video editing:** This tool only creates caption files. It never renders a video or burns subtitles into a video.1 unmodified line""")gr.HTML("<div class='cc-foot'>CaptionCraft AI · OpenAI Whisper-small · Apache-2.0 model license</div>")generate_btn.click(fn=generate_subtitles,29 unmodified lines303132333435363738149 unmodified lines18818919019119219319419519619736 unmodified lines234235236237238239240241242243244245137 unmodified lines38338438538638738838920 unmodified lines41041141241341441541633 unmodified lines4504514524534544554564574581 unmodified line46046146246346446546629 unmodified linesAPP_TITLE = "CaptionCraft AI"MODEL_ID = "openai/whisper-medium"MAX_UPLOAD_MB = int(os.getenv("MAX_UPLOAD_MB", "100"))MAX_AUDIO_MINUTES = int(os.getenv("MAX_AUDIO_MINUTES", "20"))OUTPUT_DIR = Path(tempfile.gettempdir()) / "captioncraft_downloads"OUTPUT_DIR.mkdir(parents=True, exist_ok=True)149 unmodified linesexcept Exception:# Keep the scheduler estimate conservative when metadata cannot be probed.return 60# Whisper-medium with beam search needs a larger reservation than small.# Keep every request below the 240-second per-call cap; ZeroGPU still# checks the visitor's remaining daily quota before allocating the GPU.return max(30, min(240, int(math.ceil(30 + audio_seconds * 0.12))))@spaces.GPU(duration=_estimate_gpu_duration)36 unmodified linesprogress(0.08, desc="Preparing lightweight 16 kHz mono audio…")_prepare_audio(source, wav_path, duration)progress(0.15, desc="Whisper-medium is ready; reserving ZeroGPU for transcription…")asr = _ASR_PIPELINEgenerate_kwargs: dict[str, Any] = {"task": "translate" if task_mode == "translate" else "transcribe","num_beams": 5,"condition_on_prev_tokens": False,}if language and language != "auto":137 unmodified linesgr.HTML("""<section id="cc-hero"><span class="cc-chip">WHISPER-MEDIUM · ZERO GPU</span><span class="cc-chip">AUDIO → SUBTITLE FILES</span><h1>CaptionCraft AI</h1><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></section>20 unmodified lineschoices=LANGUAGES,value="auto",label="Spoken language",info="Auto-detect is recommended. Whisper-medium supports 99 languages; the dropdown lists common languages.",scale=1,)task_input = gr.Radio(33 unmodified lineswith gr.Accordion("How it works & limitations", open=False):gr.Markdown("""- **Model:** `openai/whisper-medium` from Hugging Face, a multilingual 769M-parameter ASR model.- **Execution:** Hugging Face ZeroGPU. Whisper-medium is loaded onto the shared CUDA device at startup and the transcription callback is wrapped with `@spaces.GPU`.- **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.- **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.- **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.- **No video editing:** This tool only creates caption files. It never renders a video or burns subtitles into a video.1 unmodified line""")gr.HTML("<div class='cc-foot'>CaptionCraft AI · OpenAI Whisper-medium · Apache-2.0 model license</div>")generate_btn.click(fn=generate_subtitles,
32 unmodified lines33343532 unmodified linesassert "torch.float16" in appassert "dtype=MODEL_DTYPE" in appassert "torch_dtype=MODEL_DTYPE" not in app32 unmodified lines333435363738394041424332 unmodified linesassert "torch.float16" in appassert "dtype=MODEL_DTYPE" in appassert "torch_dtype=MODEL_DTYPE" not in appdef test_app_uses_whisper_medium_and_beam_search_for_quality():app = (ROOT / "app.py").read_text(encoding="utf-8")assert 'MODEL_ID = "openai/whisper-medium"' in appassert '"num_beams": 5' in appassert "769M-parameter" in appassert "WHISPER-SMALL" not in app
app.py+14-13
tests/test_zerogpu_config.py+8