tuan243 commited on
Commit
ead532d
·
verified ·
1 Parent(s): d40be6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -8,6 +8,11 @@ from funasr import AutoModel
8
  from starlette.middleware import Middleware
9
  from starlette.middleware.cors import CORSMiddleware
10
 
 
 
 
 
 
11
  app = FastAPI(
12
  middleware=[
13
  Middleware(
@@ -63,10 +68,10 @@ print(app.routes)
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}"
@@ -76,7 +81,7 @@ async def detect_noise_api(file: UploadFile = File(...)):
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
 
8
  from starlette.middleware import Middleware
9
  from starlette.middleware.cors import CORSMiddleware
10
 
11
+ import logging
12
+
13
+ logging.basicConfig(level=logging.INFO)
14
+ logger = logging.getLogger(__name__)
15
+
16
  app = FastAPI(
17
  middleware=[
18
  Middleware(
 
68
  @app.post("/detect-noise/")
69
  async def detect_noise_api(file: UploadFile = File(...)):
70
  try:
71
+ logger.info("Tên file: %s", file.filename)
72
+ logger.info("Loại file: %s", file.content_type)
73
  file_size = len(await file.read())
74
+ logger.info("Kích thước file: %s bytes", file_size)
75
  await file.seek(0) # Reset lại vị trí đọc file
76
 
77
  file_path = f"temp/{file.filename}"
 
81
  result = detect_noise(file_path)
82
  return {"noise_level": result}
83
  except Exception as e:
84
+ logger.exception("Lỗi trong API: %s", e)
85
  return {"error": str(e)}
86
 
87
  # Chạy FastAPI trên Hugging Face Spaces