Spaces:
Sleeping
Sleeping
GOWREESH M G commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,9 @@ LOAD_ERROR = None # Store the specific reason for failure
|
|
| 24 |
# -------------------- LOAD MODEL --------------------
|
| 25 |
def init_model():
|
| 26 |
global MODEL, LOAD_ERROR
|
|
|
|
|
|
|
|
|
|
| 27 |
if os.path.exists(MODEL_FILE):
|
| 28 |
print(f"[INIT] Model found: {MODEL_FILE}")
|
| 29 |
try:
|
|
@@ -82,7 +85,7 @@ def analyze():
|
|
| 82 |
})
|
| 83 |
else:
|
| 84 |
# Use the captured specific error message
|
| 85 |
-
error_msg = LOAD_ERROR if LOAD_ERROR else "
|
| 86 |
return jsonify({
|
| 87 |
"diagnosis": "Load Error",
|
| 88 |
"description": f"Error: {error_msg}",
|
|
@@ -134,6 +137,9 @@ def analyze():
|
|
| 134 |
finally:
|
| 135 |
if os.path.exists(temp_path): os.remove(temp_path)
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
if __name__ == "__main__":
|
| 138 |
-
init_model()
|
| 139 |
app.run(debug=True, port=7860)
|
|
|
|
| 24 |
# -------------------- LOAD MODEL --------------------
|
| 25 |
def init_model():
|
| 26 |
global MODEL, LOAD_ERROR
|
| 27 |
+
# Reset errors
|
| 28 |
+
LOAD_ERROR = None
|
| 29 |
+
|
| 30 |
if os.path.exists(MODEL_FILE):
|
| 31 |
print(f"[INIT] Model found: {MODEL_FILE}")
|
| 32 |
try:
|
|
|
|
| 85 |
})
|
| 86 |
else:
|
| 87 |
# Use the captured specific error message
|
| 88 |
+
error_msg = LOAD_ERROR if LOAD_ERROR else "Model initialization skipped by server."
|
| 89 |
return jsonify({
|
| 90 |
"diagnosis": "Load Error",
|
| 91 |
"description": f"Error: {error_msg}",
|
|
|
|
| 137 |
finally:
|
| 138 |
if os.path.exists(temp_path): os.remove(temp_path)
|
| 139 |
|
| 140 |
+
# -------------------- INITIALIZE ON IMPORT --------------------
|
| 141 |
+
# Crucial Fix: Call init_model() globally so Gunicorn runs it!
|
| 142 |
+
init_model()
|
| 143 |
+
|
| 144 |
if __name__ == "__main__":
|
|
|
|
| 145 |
app.run(debug=True, port=7860)
|