tuan243 commited on
Commit
f7c7004
·
verified ·
1 Parent(s): 4435adf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -62,12 +62,15 @@ print(app.routes)
62
  # API nhận file âm thanh từ Flutter
63
  @app.post("/detect-noise/")
64
  async def detect_noise_api(file: UploadFile = File(...)):
65
- file_path = f"temp/{file.filename}"
66
- with open(file_path, "wb") as buffer:
67
- shutil.copyfileobj(file.file, buffer)
 
68
 
69
- result = detect_noise(file_path)
70
- return {"noise_level": result}
 
 
71
 
72
  # Chạy FastAPI trên Hugging Face Spaces
73
  if __name__ == "__main__":
 
62
  # API nhận file âm thanh từ Flutter
63
  @app.post("/detect-noise/")
64
  async def detect_noise_api(file: UploadFile = File(...)):
65
+ try:
66
+ file_path = f"temp/{file.filename}"
67
+ with open(file_path, "wb") as buffer:
68
+ shutil.copyfileobj(file.file, buffer)
69
 
70
+ result = detect_noise(file_path)
71
+ return {"noise_level": result}
72
+ except Exception as e:
73
+ return {"error": str(e)}
74
 
75
  # Chạy FastAPI trên Hugging Face Spaces
76
  if __name__ == "__main__":