clstm_fastAPI / app.py
AntwanMekhael's picture
Update app.py
9a49324 verified
raw
history blame
899 Bytes
from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
import shutil
import uuid
import os
from inference import predict
app = FastAPI(title="Audio Emotion Recognition API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
UPLOAD_DIR = "/tmp"
os.makedirs(UPLOAD_DIR, exist_ok=True)
@app.get("/")
def root():
return {
"message": "Audio Emotion Recognition API is running"
}
@app.get("/health")
def health():
return {"status": "ok"}
@app.post("/predict")
async def predict_emotion(file: UploadFile = File(...)):
file_path = f"{UPLOAD_DIR}/{uuid.uuid4()}.wav"
with open(file_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
result = predict(file_path)
os.remove(file_path)
return result