File size: 916 Bytes
5641ea8
 
 
 
 
 
 
 
2acf23d
5641ea8
80e49ca
5641ea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b21eb2d
5641ea8
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from fastapi import FastAPI, UploadFile, File
from faster_whisper import WhisperModel
import uvicorn
import tempfile
import shutil

app = FastAPI()

# Modèle SMALL optimisé pour CPU HF
model = WhisperModel(
    "base",
    device="cpu",
    compute_type="int8"
)

@app.post("/transcribe")
async def transcribe(file: UploadFile = File(...)):
    # Sauvegarde temporaire du fichier audio
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
        shutil.copyfileobj(file.file, tmp)
        audio_path = tmp.name

    # Transcription
    segments, info = model.transcribe(audio_path)
    text = "".join([seg.text for seg in segments])

    return {
        "text": text,
        "language": info.language,
        "duration": info.duration
    }

@app.get("/")
def root():
    return {"status": "API Whisper BASE OK"}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)