Update app.py
Browse files
app.py
CHANGED
@@ -267,32 +267,6 @@ async def delete_recording(filename: str):
|
|
267 |
logger.error("Failed to delete file %s: %s", filename, e)
|
268 |
raise HTTPException(status_code=500, detail=f"Failed to delete file: {str(e)}")
|
269 |
|
270 |
-
# New endpoint to analyze emotion directly from uploaded file
|
271 |
-
@app.post("/analyze_emotion")
|
272 |
-
async def analyze_emotion(file: UploadFile = File(...)):
|
273 |
-
"""
|
274 |
-
Analyze the uploaded audio file and return emotion predictions.
|
275 |
-
"""
|
276 |
-
if not classifier:
|
277 |
-
raise HTTPException(status_code=503, detail="Model not yet loaded")
|
278 |
-
|
279 |
-
# Save uploaded file temporarily
|
280 |
-
temp_file = Path("temp_audio_file.wav")
|
281 |
-
try:
|
282 |
-
contents = await file.read()
|
283 |
-
with open(temp_file, "wb") as f:
|
284 |
-
f.write(contents)
|
285 |
-
|
286 |
-
# Run analysis on the uploaded file
|
287 |
-
results = classifier(str(temp_file))
|
288 |
-
return {"predictions": results}
|
289 |
-
except Exception as e:
|
290 |
-
logger.error("Failed to analyze the file: %s", e)
|
291 |
-
raise HTTPException(status_code=500, detail=f"Failed to analyze the file: {str(e)}")
|
292 |
-
finally:
|
293 |
-
if temp_file.exists():
|
294 |
-
temp_file.unlink() # Clean up temporary file
|
295 |
-
|
296 |
if __name__ == "__main__":
|
297 |
-
#
|
298 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
267 |
logger.error("Failed to delete file %s: %s", filename, e)
|
268 |
raise HTTPException(status_code=500, detail=f"Failed to delete file: {str(e)}")
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
if __name__ == "__main__":
|
271 |
+
# Start FastAPI with Uvicorn
|
272 |
+
uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
|