cough_ai / app.py
QnxprU69yCNg8XJ
we can start now
44626f7
raw
history blame contribute delete
574 Bytes
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}