Ping Long commited on
Commit
1e5635b
·
1 Parent(s): 59e530b

feat: add engine selector to Gradio UI (hf-gpu/hf-cpu/vllm)

Browse files

- Added Engine dropdown defaulting to hf-gpu (works on all hardware)
- Pass engine param to /transcribe endpoint
- Updated description with engine explanation + WebGPU note
- Fixed deprecated allow_flagging → flagging_mode
- Examples now include engine column

Files changed (1) hide show
  1. backend/app.py +20 -10
backend/app.py CHANGED
@@ -601,7 +601,7 @@ app.add_middleware(
601
  # Gradio UI – mounted at / for HF Spaces iframe
602
  # ---------------------------------------------------------------------------
603
 
604
- def _gradio_transcribe(audio_path: str, model_name: str, language: str):
605
  """Synchronous wrapper called by Gradio – posts to the local FastAPI endpoint."""
606
  import httpx
607
 
@@ -615,7 +615,7 @@ def _gradio_transcribe(audio_path: str, model_name: str, language: str):
615
  resp = httpx.post(
616
  f"http://127.0.0.1:{port}/transcribe",
617
  files={"audio": ("audio.wav", audio_bytes, "audio/wav")},
618
- data={"model": model_name, "language": language},
619
  timeout=120.0,
620
  )
621
  if resp.status_code != 200:
@@ -642,6 +642,11 @@ demo = gr.Interface(
642
  value="openai/whisper-base",
643
  label="Model",
644
  ),
 
 
 
 
 
645
  gr.Dropdown(
646
  choices=["english", "chinese", "spanish", "french", "german",
647
  "japanese", "korean", "hindi", "arabic", "portuguese"],
@@ -653,17 +658,22 @@ demo = gr.Interface(
653
  title="Open-ASR Model Explorer",
654
  description=(
655
  "Hybrid inference testbed for open-source ASR models. "
656
- "Upload audio or record from your microphone, pick a model, and transcribe."
 
 
 
 
 
657
  ),
658
  examples=[
659
- [str(_SAMPLES_DIR / "english.wav"), "openai/whisper-base", "english"],
660
- [str(_SAMPLES_DIR / "chinese.wav"), "openai/whisper-base", "chinese"],
661
- [str(_SAMPLES_DIR / "french.wav"), "openai/whisper-base", "french"],
662
- [str(_SAMPLES_DIR / "spanish.wav"), "openai/whisper-base", "spanish"],
663
- [str(_SAMPLES_DIR / "japanese.wav"), "openai/whisper-base", "japanese"],
664
- [str(_SAMPLES_DIR / "hindi.wav"), "openai/whisper-base", "hindi"],
665
  ],
666
- allow_flagging="never",
667
  )
668
 
669
 
 
601
  # Gradio UI – mounted at / for HF Spaces iframe
602
  # ---------------------------------------------------------------------------
603
 
604
+ def _gradio_transcribe(audio_path: str, model_name: str, engine: str, language: str):
605
  """Synchronous wrapper called by Gradio – posts to the local FastAPI endpoint."""
606
  import httpx
607
 
 
615
  resp = httpx.post(
616
  f"http://127.0.0.1:{port}/transcribe",
617
  files={"audio": ("audio.wav", audio_bytes, "audio/wav")},
618
+ data={"model": model_name, "engine": engine, "language": language},
619
  timeout=120.0,
620
  )
621
  if resp.status_code != 200:
 
642
  value="openai/whisper-base",
643
  label="Model",
644
  ),
645
+ gr.Dropdown(
646
+ choices=["hf-gpu", "hf-cpu", "vllm"],
647
+ value="hf-gpu",
648
+ label="Engine",
649
+ ),
650
  gr.Dropdown(
651
  choices=["english", "chinese", "spanish", "french", "german",
652
  "japanese", "korean", "hindi", "arabic", "portuguese"],
 
658
  title="Open-ASR Model Explorer",
659
  description=(
660
  "Hybrid inference testbed for open-source ASR models. "
661
+ "Upload audio or record from your microphone, pick a model and engine, then transcribe.\n\n"
662
+ "**Engine options:** `hf-gpu` (HuggingFace Transformers on GPU), "
663
+ "`hf-cpu` (CPU-only fallback), `vllm` (vLLM optimised serving).\n\n"
664
+ "**Note:** WebGPU client-side models (Xenova/whisper-*, onnx-community/cohere-*) "
665
+ "run in-browser via transformers.js and are available in the "
666
+ "[full React UI](https://github.com/SiliconLanguage/model-explorer-open-asr) only."
667
  ),
668
  examples=[
669
+ [str(_SAMPLES_DIR / "english.wav"), "openai/whisper-base", "hf-gpu", "english"],
670
+ [str(_SAMPLES_DIR / "chinese.wav"), "openai/whisper-base", "hf-gpu", "chinese"],
671
+ [str(_SAMPLES_DIR / "french.wav"), "openai/whisper-base", "hf-gpu", "french"],
672
+ [str(_SAMPLES_DIR / "spanish.wav"), "openai/whisper-base", "hf-gpu", "spanish"],
673
+ [str(_SAMPLES_DIR / "japanese.wav"), "openai/whisper-base", "hf-gpu", "japanese"],
674
+ [str(_SAMPLES_DIR / "hindi.wav"), "openai/whisper-base", "hf-gpu", "hindi"],
675
  ],
676
+ flagging_mode="never",
677
  )
678
 
679