Update app.py
Browse files
app.py
CHANGED
|
@@ -24,20 +24,23 @@ app.add_middleware(
|
|
| 24 |
allow_headers=["*"],
|
| 25 |
)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
logger.info("π Loading pre-baked ONNX model...")
|
| 32 |
try:
|
| 33 |
-
# Check if files exist just in case
|
| 34 |
if not os.path.exists(MODEL_PATH):
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
logger.info("β
Engine is LIVE and Ready!")
|
| 39 |
except Exception as e:
|
| 40 |
-
logger.error(f"β
|
| 41 |
raise e
|
| 42 |
|
| 43 |
labels = ("balochi", "english", "pashto", "sindhi", "urdu")
|
|
@@ -88,6 +91,7 @@ async def predict(file: UploadFile = File(...)):
|
|
| 88 |
os.remove(temp_path)
|
| 89 |
return {"success": True, "language": lang.upper(), "confidence": round(conf * 100, 2)}
|
| 90 |
except Exception as e:
|
|
|
|
| 91 |
if os.path.exists(temp_path): os.remove(temp_path)
|
| 92 |
return {"success": False, "error": str(e)}
|
| 93 |
|
|
|
|
| 24 |
allow_headers=["*"],
|
| 25 |
)
|
| 26 |
|
| 27 |
+
# π¨ Use Absolute Path
|
| 28 |
+
MODEL_PATH = "/app/local_model/pakistani_lid_v3.onnx"
|
| 29 |
+
|
| 30 |
+
logger.info(f"π Attempting to load model from: {MODEL_PATH}")
|
| 31 |
|
|
|
|
| 32 |
try:
|
|
|
|
| 33 |
if not os.path.exists(MODEL_PATH):
|
| 34 |
+
# List files for debugging in logs if it fails
|
| 35 |
+
logger.error(f"Files in /app/local_model: {os.listdir('/app/local_model') if os.path.exists('/app/local_model') else 'Dir not found'}")
|
| 36 |
+
raise FileNotFoundError(f"Model file missing at {MODEL_PATH}")
|
| 37 |
|
| 38 |
+
# Load with mmap to save RAM
|
| 39 |
+
session_options = ort.SessionOptions()
|
| 40 |
+
session = ort.InferenceSession(MODEL_PATH, sess_options=session_options, providers=['CPUExecutionProvider'])
|
| 41 |
logger.info("β
Engine is LIVE and Ready!")
|
| 42 |
except Exception as e:
|
| 43 |
+
logger.error(f"β Initialization Error: {e}")
|
| 44 |
raise e
|
| 45 |
|
| 46 |
labels = ("balochi", "english", "pashto", "sindhi", "urdu")
|
|
|
|
| 91 |
os.remove(temp_path)
|
| 92 |
return {"success": True, "language": lang.upper(), "confidence": round(conf * 100, 2)}
|
| 93 |
except Exception as e:
|
| 94 |
+
logger.error(f"Inference Error: {e}")
|
| 95 |
if os.path.exists(temp_path): os.remove(temp_path)
|
| 96 |
return {"success": False, "error": str(e)}
|
| 97 |
|