carlosduplar
build-small-hackathon: switch to modal.asgi_app, fix endpoint body parsing, base64 audio
4ff45b3 Download stt_engine.py from build-small-hackathon/patient-virtuel-dentiste: direct link, hf CLI and curl.
- Browser
- Download file 584 Bytes
-
https://huggingface.co/spaces/build-small-hackathon/patient-virtuel-dentiste/resolve/4ff45b3aa41715fb618281a8fc9d4382760bdedf/stt_engine.py
- Command line
-
hf download hf://spaces/build-small-hackathon/patient-virtuel-dentiste@4ff45b3aa41715fb618281a8fc9d4382760bdedf/stt_engine.py
-
curl -L -o stt_engine.py https://huggingface.co/spaces/build-small-hackathon/patient-virtuel-dentiste/resolve/4ff45b3aa41715fb618281a8fc9d4382760bdedf/stt_engine.py
584 Bytes
| import base64 | |
| import os | |
| import httpx | |
| MODAL_ENDPOINT = os.environ.get("MODAL_ENDPOINT_WHISPER", "") | |
| MODAL_AUTH_TOKEN = os.environ.get("MODAL_AUTH_TOKEN", "") | |
| def transcribe(audio_path: str) -> str | None: | |
| if not MODAL_ENDPOINT: | |
| raise RuntimeError("MODAL_ENDPOINT_WHISPER not set") | |
| with open(audio_path, "rb") as f: | |
| b64 = base64.b64encode(f.read()).decode() | |
| resp = httpx.post( | |
| MODAL_ENDPOINT, | |
| json={"audio_base64": b64, "token": MODAL_AUTH_TOKEN}, | |
| timeout=30, | |
| ) | |
| resp.raise_for_status() | |
| return resp.json().get("text") | |