Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -63,6 +63,12 @@ print(app.routes)
|
|
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)
|
@@ -70,6 +76,7 @@ async def detect_noise_api(file: UploadFile = File(...)):
|
|
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
|
|
|
63 |
@app.post("/detect-noise/")
|
64 |
async def detect_noise_api(file: UploadFile = File(...)):
|
65 |
try:
|
66 |
+
print("Tên file:", file.filename)
|
67 |
+
print("Loại file:", file.content_type)
|
68 |
+
file_size = len(await file.read())
|
69 |
+
print("Kích thước file:", file_size, "bytes")
|
70 |
+
await file.seek(0) # Reset lại vị trí đọc file
|
71 |
+
|
72 |
file_path = f"temp/{file.filename}"
|
73 |
with open(file_path, "wb") as buffer:
|
74 |
shutil.copyfileobj(file.file, buffer)
|
|
|
76 |
result = detect_noise(file_path)
|
77 |
return {"noise_level": result}
|
78 |
except Exception as e:
|
79 |
+
print(f"Lỗi trong API: {e}")
|
80 |
return {"error": str(e)}
|
81 |
|
82 |
# Chạy FastAPI trên Hugging Face Spaces
|