Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
|
|
|
|
|
|
|
|
|
| 119 |
learner = load_learner(model_path)
|
| 120 |
-
|
| 121 |
predictions = []
|
| 122 |
|
| 123 |
-
for
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
return predictions
|
| 136 |
|
| 137 |
except Exception as e:
|
| 138 |
-
return
|
| 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
|