|
|
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} |
|
|
|