Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
66 |
-
|
67 |
-
|
|
|
68 |
|
69 |
-
|
70 |
-
|
|
|
|
|
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__":
|