Spaces:
Sleeping
Sleeping
Download app.py from raddiv/whisper-api: direct link, hf CLI and curl.
- Browser
- Download file 567 Bytes
-
https://huggingface.co/spaces/raddiv/whisper-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/raddiv/whisper-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/raddiv/whisper-api/resolve/main/app.py
567 Bytes
| from fastapi import FastAPI, UploadFile, File | |
| import whisper, tempfile, os | |
| app = FastAPI() | |
| model = whisper.load_model("small") | |
| async def transcribe(file: UploadFile = File(...)): | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp: | |
| tmp.write(await file.read()) | |
| tmp_path = tmp.name | |
| result = model.transcribe(tmp_path) | |
| os.unlink(tmp_path) | |
| return { | |
| "text": result["text"], | |
| "segments": result["segments"] | |
| } | |
| async def health(): | |
| return {"status": "ok"} |