This commit is contained in:
YannAhlgrim
2025-10-07 18:00:20 +02:00
commit 4793f1b183
11 changed files with 262 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install system dependencies for audio handling and build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
libsndfile1 \
build-essential \
git \
wget \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
RUN python -m pip install --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt
COPY server.py ./
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8001"]
+6
View File
@@ -0,0 +1,6 @@
fastapi==0.100.0
uvicorn[standard]==0.22.0
whisper==20230314
pydub==0.25.1
aiofiles==23.1.0
python-multipart==0.0.6
+32
View File
@@ -0,0 +1,32 @@
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import JSONResponse
import whisper
import tempfile
import shutil
app = FastAPI()
model = whisper.load_model("small")
@app.post("/transcribe")
async def transcribe(file: UploadFile = File(...)):
if not file.content_type.startswith("audio"):
raise HTTPException(status_code=400, detail="File must be audio")
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
contents = await file.read()
tmp.write(contents)
tmp.flush()
tmp_path = tmp.name
try:
result = model.transcribe(tmp_path, language=None)
text = result.get("text", "")
finally:
try:
shutil.os.remove(tmp_path)
except Exception:
pass
return JSONResponse({"text": text})