from fastapi import FastAPI, File, UploadFile import shutil import os from whispercpp import Whisper app = FastAPI() # Load the local model without Hugging Face token whisper = Whisper.from_pretrained("./app/model/ggml-tiny.en.bin") @app.post("/transcribe") async def transcribe_audio(audio: UploadFile = File(...)): temp_file = f"temp_{audio.filename}" with open(temp_file, "wb") as buffer: shutil.copyfileobj(audio.file, buffer) result = whisper.transcribe(temp_file) os.remove(temp_file) return {"text": result}