dev-scezui commited on
Commit
32b012c
·
verified ·
1 Parent(s): 3a464dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -115,27 +115,28 @@ def make_predictions(image_paths):
115
  # temp = pathlib.PosixPath # Save the original state
116
  # pathlib.PosixPath = pathlib.WindowsPath # Change to WindowsPath temporarily
117
 
118
- model_path = Path(r'model/export')
 
 
 
119
  learner = load_learner(model_path)
120
-
121
  predictions = []
122
 
123
- for image_path in image_paths:
124
- # Open the image using fastai's open_image function
125
- image = open_image(image_path)
126
-
127
- # Make a prediction
128
- prediction_class, prediction_idx, probabilities = learner.predict(image)
129
-
130
- # If you want the predicted class as a string
131
- predicted_class_str = str(prediction_class)
132
-
133
- predictions.append(predicted_class_str)
134
-
135
  return predictions
136
 
137
  except Exception as e:
138
- return {"error in make_predictions": str(e)}
139
 
140
  # finally:
141
  # pathlib.PosixPath = temp
 
115
  # temp = pathlib.PosixPath # Save the original state
116
  # pathlib.PosixPath = pathlib.WindowsPath # Change to WindowsPath temporarily
117
 
118
+ model_path = Path('model/export')
119
+ if not model_path.exists():
120
+ return ["Error: Model not found at 'model/export'"]
121
+
122
  learner = load_learner(model_path)
 
123
  predictions = []
124
 
125
+ for img_path in image_paths:
126
+ path = Path(img_path)
127
+ if not path.exists():
128
+ predictions.append("Error: File not found")
129
+ continue
130
+ try:
131
+ img = open_image(path)
132
+ pred_class, _, _ = learner.predict(img)
133
+ predictions.append(str(pred_class))
134
+ except Exception as e:
135
+ predictions.append(f"Error: {e}")
 
136
  return predictions
137
 
138
  except Exception as e:
139
+ return [f"Model failed: {e}"]
140
 
141
  # finally:
142
  # pathlib.PosixPath = temp