Spaces:
Running
Running
tentative edit on make_predictions
Browse files
app.py
CHANGED
@@ -101,21 +101,19 @@ def upload_files():
|
|
101 |
return render_template('index.html')
|
102 |
|
103 |
|
|
|
|
|
|
|
104 |
def make_predictions(image_paths):
|
105 |
-
temp = None
|
106 |
try:
|
107 |
-
|
108 |
-
temp = pathlib.PosixPath # Save the original state
|
109 |
-
pathlib.PosixPath = pathlib.WindowsPath # Change to WindowsPath temporarily
|
110 |
-
|
111 |
-
model_path = Path(r'model/export')
|
112 |
learner = load_learner(model_path)
|
113 |
|
114 |
predictions = []
|
115 |
|
116 |
for image_path in image_paths:
|
117 |
# Open the image using fastai's open_image function
|
118 |
-
image = open_image(image_path)
|
119 |
|
120 |
# Make a prediction
|
121 |
prediction_class, prediction_idx, probabilities = learner.predict(image)
|
@@ -129,9 +127,6 @@ def make_predictions(image_paths):
|
|
129 |
|
130 |
except Exception as e:
|
131 |
return {"error in make_predictions": str(e)}
|
132 |
-
|
133 |
-
finally:
|
134 |
-
pathlib.PosixPath = temp
|
135 |
|
136 |
|
137 |
@app.route('/predict/<filenames>', methods=['GET', 'POST'])
|
|
|
101 |
return render_template('index.html')
|
102 |
|
103 |
|
104 |
+
from pathlib import Path
|
105 |
+
from fastai.vision import load_learner, open_image
|
106 |
+
|
107 |
def make_predictions(image_paths):
|
|
|
108 |
try:
|
109 |
+
model_path = Path('model/export')
|
|
|
|
|
|
|
|
|
110 |
learner = load_learner(model_path)
|
111 |
|
112 |
predictions = []
|
113 |
|
114 |
for image_path in image_paths:
|
115 |
# Open the image using fastai's open_image function
|
116 |
+
image = open_image(Path(image_path))
|
117 |
|
118 |
# Make a prediction
|
119 |
prediction_class, prediction_idx, probabilities = learner.predict(image)
|
|
|
127 |
|
128 |
except Exception as e:
|
129 |
return {"error in make_predictions": str(e)}
|
|
|
|
|
|
|
130 |
|
131 |
|
132 |
@app.route('/predict/<filenames>', methods=['GET', 'POST'])
|