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