Update server.py
Browse files
server.py
CHANGED
|
@@ -94,15 +94,37 @@ def health_check():
|
|
| 94 |
|
| 95 |
return status
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
@app.post("/api/v1/inference")
|
| 98 |
async def inference(request: AudioRequest) -> AudioResponse:
|
| 99 |
-
"""Run inference on audio input"""
|
| 100 |
-
if not INITIALIZATION_STATUS["model_loaded"]:
|
| 101 |
-
raise HTTPException(
|
| 102 |
-
status_code=503,
|
| 103 |
-
detail=f"Model not ready. Status: {INITIALIZATION_STATUS}"
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
try:
|
| 107 |
# Decode audio from base64
|
| 108 |
audio_bytes = base64.b64decode(request.audio_data)
|
|
@@ -120,10 +142,6 @@ async def inference(request: AudioRequest) -> AudioResponse:
|
|
| 120 |
audio_data=audio_b64,
|
| 121 |
text=result.get("text", "")
|
| 122 |
)
|
| 123 |
-
except Exception as e:
|
| 124 |
-
logger.error(f"Inference failed: {str(e)}")
|
| 125 |
-
raise HTTPException(status_code=500, detail=str(e))
|
| 126 |
-
|
| 127 |
if __name__ == "__main__":
|
| 128 |
import uvicorn
|
| 129 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 94 |
|
| 95 |
return status
|
| 96 |
|
| 97 |
+
# @app.post("/api/v1/inference")
|
| 98 |
+
# async def inference(request: AudioRequest) -> AudioResponse:
|
| 99 |
+
# """Run inference on audio input"""
|
| 100 |
+
# if not INITIALIZATION_STATUS["model_loaded"]:
|
| 101 |
+
# raise HTTPException(
|
| 102 |
+
# status_code=503,
|
| 103 |
+
# detail=f"Model not ready. Status: {INITIALIZATION_STATUS}"
|
| 104 |
+
# )
|
| 105 |
+
|
| 106 |
+
# try:
|
| 107 |
+
# # Decode audio from base64
|
| 108 |
+
# audio_bytes = base64.b64decode(request.audio_data)
|
| 109 |
+
# audio_array = np.load(io.BytesIO(audio_bytes))
|
| 110 |
+
|
| 111 |
+
# # Run inference
|
| 112 |
+
# result = model.inference(audio_array, request.sample_rate)
|
| 113 |
+
|
| 114 |
+
# # Encode output audio
|
| 115 |
+
# buffer = io.BytesIO()
|
| 116 |
+
# np.save(buffer, result['audio'])
|
| 117 |
+
# audio_b64 = base64.b64encode(buffer.getvalue()).decode()
|
| 118 |
+
|
| 119 |
+
# return AudioResponse(
|
| 120 |
+
# audio_data=audio_b64,
|
| 121 |
+
# text=result.get("text", "")
|
| 122 |
+
# )
|
| 123 |
+
# except Exception as e:
|
| 124 |
+
# logger.error(f"Inference failed: {str(e)}")
|
| 125 |
+
# raise HTTPException(status_code=500, detail=str(e))
|
| 126 |
@app.post("/api/v1/inference")
|
| 127 |
async def inference(request: AudioRequest) -> AudioResponse:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
try:
|
| 129 |
# Decode audio from base64
|
| 130 |
audio_bytes = base64.b64decode(request.audio_data)
|
|
|
|
| 142 |
audio_data=audio_b64,
|
| 143 |
text=result.get("text", "")
|
| 144 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
if __name__ == "__main__":
|
| 146 |
import uvicorn
|
| 147 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|