Elliot Sones commited on
Commit
67fede5
·
1 Parent(s): 578d1f6

Fix: Pin numpy<2 and handle model load errors gracefully

Browse files
Files changed (2) hide show
  1. app.py +12 -2
  2. requirements.txt +1 -1
app.py CHANGED
@@ -157,7 +157,15 @@ def load_model():
157
  idx_to_class = {v: k for k, v in class_to_idx.items()}
158
  return model, idx_to_class
159
 
160
- MODEL, IDX_TO_CLASS = load_model()
 
 
 
 
 
 
 
 
161
 
162
  # ============================================================================
163
  # Prediction
@@ -165,8 +173,10 @@ MODEL, IDX_TO_CLASS = load_model()
165
 
166
  def predict(strokes_json):
167
  """Predict from JSON stroke data."""
 
 
168
  if MODEL is None:
169
- return {"error": "Model not loaded"}
170
 
171
  try:
172
  raw_strokes = json.loads(strokes_json) if isinstance(strokes_json, str) else strokes_json
 
157
  idx_to_class = {v: k for k, v in class_to_idx.items()}
158
  return model, idx_to_class
159
 
160
+ MODEL = None
161
+ IDX_TO_CLASS = {}
162
+ LOAD_ERROR = None
163
+
164
+ try:
165
+ MODEL, IDX_TO_CLASS = load_model()
166
+ except Exception as e:
167
+ LOAD_ERROR = str(e)
168
+ print(f"Failed to load model: {e}")
169
 
170
  # ============================================================================
171
  # Prediction
 
173
 
174
  def predict(strokes_json):
175
  """Predict from JSON stroke data."""
176
+ if LOAD_ERROR:
177
+ return {"error": f"Model load failed: {LOAD_ERROR}"}
178
  if MODEL is None:
179
+ return {"error": "Model not loaded (unknown reason)"}
180
 
181
  try:
182
  raw_strokes = json.loads(strokes_json) if isinstance(strokes_json, str) else strokes_json
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
  gradio>=4.0.0
2
  torch>=2.0.0
3
- numpy>=1.24.0
 
1
  gradio>=4.0.0
2
  torch>=2.0.0
3
+ numpy>=1.24.0,<2.0.0