GOWREESH M G commited on
Commit
fa18161
·
verified ·
1 Parent(s): f353107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -19,10 +19,11 @@ IMG_SIZE = (224, 224)
19
 
20
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
21
  MODEL = None
 
22
 
23
  # -------------------- LOAD MODEL --------------------
24
  def init_model():
25
- global MODEL
26
  if os.path.exists(MODEL_FILE):
27
  print(f"[INIT] Model found: {MODEL_FILE}")
28
  try:
@@ -30,6 +31,7 @@ def init_model():
30
  print("[INIT] Model loaded successfully.")
31
  except Exception as e:
32
  print(f"[ERROR] Failed to load model: {e}")
 
33
  MODEL = None
34
  else:
35
  print(f"[ERROR] Model file '{MODEL_FILE}' NOT FOUND on server.")
@@ -79,9 +81,11 @@ def analyze():
79
  "color": "rose", "icon": "alert-octagon"
80
  })
81
  else:
 
 
82
  return jsonify({
83
  "diagnosis": "Load Error",
84
- "description": "Model file exists but failed to load. Check TensorFlow version.",
85
  "confidence": "0%",
86
  "color": "rose", "icon": "alert-octagon"
87
  })
 
19
 
20
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
21
  MODEL = None
22
+ LOAD_ERROR = None # Store the specific reason for failure
23
 
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:
 
31
  print("[INIT] Model loaded successfully.")
32
  except Exception as e:
33
  print(f"[ERROR] Failed to load model: {e}")
34
+ LOAD_ERROR = str(e) # Capture the actual error message
35
  MODEL = None
36
  else:
37
  print(f"[ERROR] Model file '{MODEL_FILE}' NOT FOUND on server.")
 
81
  "color": "rose", "icon": "alert-octagon"
82
  })
83
  else:
84
+ # Use the captured specific error message
85
+ error_msg = LOAD_ERROR if LOAD_ERROR else "Unknown internal error"
86
  return jsonify({
87
  "diagnosis": "Load Error",
88
+ "description": f"Error: {error_msg}",
89
  "confidence": "0%",
90
  "color": "rose", "icon": "alert-octagon"
91
  })