Penta пре 9 месеци
комит
a6a29b1c30
4 измењених фајлова са 62 додато и 0 уклоњено
  1. 1 0
      .gitignore
  2. 23 0
      Dockerfile
  3. 33 0
      app.py
  4. 5 0
      requirements.txt

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.venv/

+ 23 - 0
Dockerfile

@@ -0,0 +1,23 @@
+FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN apt update && apt install -y \
+    python3 \
+    python3-pip \
+    ffmpeg \
+    git \
+    && rm -rf /var/lib/apt/lists/*
+
+RUN pip install --upgrade pip
+
+COPY requirements.txt /requirements.txt
+RUN pip install -r /requirements.txt
+
+COPY app.py /app.py
+
+RUN chmod -R a+rX /app.py /usr/local /usr/lib /usr/bin
+
+EXPOSE 8000
+
+CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

+ 33 - 0
app.py

@@ -0,0 +1,33 @@
+from fastapi import FastAPI, UploadFile, File
+from faster_whisper import WhisperModel
+import tempfile
+import os
+
+app = FastAPI()
+
+model = WhisperModel(
+    "small",
+    device="cuda",
+    compute_type="float16"
+)
+
+@app.post("/transcribe")
+async def transcribe(file: UploadFile = File(...)):
+    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
+        tmp.write(await file.read())
+        tmp_path = tmp.name
+
+    segments, info = model.transcribe(
+        tmp_path,
+        language="fr",
+        vad_filter=True
+    )
+
+    os.remove(tmp_path)
+
+    text = " ".join([seg.text for seg in segments])
+
+    return {
+        "text": text,
+        "language": info.language
+    }

+ 5 - 0
requirements.txt

@@ -0,0 +1,5 @@
+fastapi
+uvicorn
+faster-whisper
+soundfile
+numpy