Spaces:
Sleeping
Sleeping
fixed logging
Browse files- .gitignore +3 -1
- app.py +6 -5
.gitignore
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
-
venv
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
ol.py
|
| 3 |
+
server.zip
|
app.py
CHANGED
|
@@ -60,10 +60,11 @@ async def save_audio(file: UploadFile = File(...)):
|
|
| 60 |
except Exception as e:
|
| 61 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 62 |
|
|
|
|
| 63 |
|
| 64 |
logging.basicConfig(
|
| 65 |
level=logging.INFO,
|
| 66 |
-
filename=
|
| 67 |
filemode="w",
|
| 68 |
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 69 |
)
|
|
@@ -73,7 +74,7 @@ logging.basicConfig(
|
|
| 73 |
def temporary_audio_file(audio_bytes):
|
| 74 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 75 |
tmp_file.write(audio_bytes)
|
| 76 |
-
tmp_file.flush()
|
| 77 |
tmp_filename = tmp_file.name
|
| 78 |
try:
|
| 79 |
yield tmp_filename
|
|
@@ -93,7 +94,7 @@ async def process_audio(audio: UploadFile = File(...)):
|
|
| 93 |
audio_bytes = await audio.read()
|
| 94 |
logging.info(
|
| 95 |
f"Received audio bytes: {len(audio_bytes)} bytes"
|
| 96 |
-
)
|
| 97 |
with temporary_audio_file(audio_bytes) as tmp_filename:
|
| 98 |
logging.info(f"Temporary file created: {tmp_filename}")
|
| 99 |
audio_data, sample_rate = librosa.load(tmp_filename, sr=None)
|
|
@@ -110,7 +111,7 @@ async def process_audio(audio: UploadFile = File(...)):
|
|
| 110 |
features = np.expand_dims(features, axis=0)
|
| 111 |
|
| 112 |
prediction = model.predict(features)
|
| 113 |
-
|
| 114 |
logging.info(f"Prediction: {prediction}")
|
| 115 |
return {"prediction": prediction.tolist()}
|
| 116 |
|
|
@@ -121,6 +122,6 @@ async def process_audio(audio: UploadFile = File(...)):
|
|
| 121 |
logging.error(f"Value error: {e}")
|
| 122 |
raise HTTPException(status_code=400, detail=f"Invalid audio data: {e}")
|
| 123 |
except Exception as e:
|
| 124 |
-
logging.exception(f"Error processing audio: {e}")
|
| 125 |
raise HTTPException(status_code=500, detail="Internal server error")
|
| 126 |
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 62 |
|
| 63 |
+
log_file_path = os.path.join("/tmp", "server.log")
|
| 64 |
|
| 65 |
logging.basicConfig(
|
| 66 |
level=logging.INFO,
|
| 67 |
+
filename=log_file_path,
|
| 68 |
filemode="w",
|
| 69 |
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 70 |
)
|
|
|
|
| 74 |
def temporary_audio_file(audio_bytes):
|
| 75 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
| 76 |
tmp_file.write(audio_bytes)
|
| 77 |
+
tmp_file.flush()
|
| 78 |
tmp_filename = tmp_file.name
|
| 79 |
try:
|
| 80 |
yield tmp_filename
|
|
|
|
| 94 |
audio_bytes = await audio.read()
|
| 95 |
logging.info(
|
| 96 |
f"Received audio bytes: {len(audio_bytes)} bytes"
|
| 97 |
+
)
|
| 98 |
with temporary_audio_file(audio_bytes) as tmp_filename:
|
| 99 |
logging.info(f"Temporary file created: {tmp_filename}")
|
| 100 |
audio_data, sample_rate = librosa.load(tmp_filename, sr=None)
|
|
|
|
| 111 |
features = np.expand_dims(features, axis=0)
|
| 112 |
|
| 113 |
prediction = model.predict(features)
|
| 114 |
+
|
| 115 |
logging.info(f"Prediction: {prediction}")
|
| 116 |
return {"prediction": prediction.tolist()}
|
| 117 |
|
|
|
|
| 122 |
logging.error(f"Value error: {e}")
|
| 123 |
raise HTTPException(status_code=400, detail=f"Invalid audio data: {e}")
|
| 124 |
except Exception as e:
|
| 125 |
+
logging.exception(f"Error processing audio: {e}")
|
| 126 |
raise HTTPException(status_code=500, detail="Internal server error")
|
| 127 |
|