Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, UploadFile, File, HTTPException | |
| from app.model import load_model | |
| from app.audio import preprocess_audio | |
| import os | |
| app = FastAPI(title="Whisper Small ASR API") | |
| asr_model = load_model() | |
| def root(): | |
| return {"status": "running", "model": "whisper-small"} | |
| async def transcribe(file: UploadFile = File(...)): | |
| if not file.filename.endswith((".wav", ".mp3", ".m4a")): | |
| raise HTTPException(status_code=400, detail="Unsupported file format") | |
| try: | |
| processed_audio = preprocess_audio(file) | |
| result = asr_model(processed_audio) | |
| os.remove(processed_audio) | |
| return { | |
| "transcription": result["text"] | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |