File size: 574 Bytes
44626f7
 
 
b233b5c
 
 
 
44626f7
b233b5c
0d28e32
 
44626f7
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI, File, UploadFile
from utils.preprocessing import load_audio
from utils.inference import get_embeddings, predict_risk

app = FastAPI()

@app.get("/")
def hello():
    return {"Hello": "World!"}


@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    temp_path = f"/tmp/{file.filename}"
    with open(temp_path, "wb") as f:
        f.write(await file.read())
    
    waveform, sr = load_audio(temp_path)
    embeddings = get_embeddings(waveform, sr)
    score = predict_risk(embeddings)
    
    return {"risk_score": score}