Spaces:
Runtime error
Runtime error
Commit ·
789d604
1
Parent(s): 36177d9
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,15 @@ from sklearn.tree import DecisionTreeClassifier
|
|
| 6 |
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
|
| 7 |
import joblib
|
| 8 |
import pickle
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def fashion_MNIST_prediction(test_image, model='KNN'):
|
| 11 |
test_image_flatten = test_image.reshape((-1, 28*28))
|
| 12 |
fashion_mnist = tf.keras.datasets.fashion_mnist
|
|
@@ -51,7 +59,14 @@ def fashion_MNIST_prediction(test_image, model='KNN'):
|
|
| 51 |
|
| 52 |
else:
|
| 53 |
return "Invalid Model Selection"
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
input_image = gr.inputs.Image(shape=(28, 28), image_mode='L')
|
| 56 |
input_model = gr.inputs.Dropdown(['KNN', 'DecisionTreeClassifier', 'RandomForestClassifier', 'AdaBoostClassifier', 'GradientBoostingClassifier'])
|
| 57 |
|
|
|
|
| 6 |
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
|
| 7 |
import joblib
|
| 8 |
import pickle
|
| 9 |
+
def load_image(image_path):
|
| 10 |
+
"""
|
| 11 |
+
Load image from file path and convert to numpy array
|
| 12 |
+
"""
|
| 13 |
+
with Image.open(image_path).convert('L') as img:
|
| 14 |
+
img = img.resize((28,28))
|
| 15 |
+
img = np.array(img)
|
| 16 |
+
return img
|
| 17 |
+
|
| 18 |
def fashion_MNIST_prediction(test_image, model='KNN'):
|
| 19 |
test_image_flatten = test_image.reshape((-1, 28*28))
|
| 20 |
fashion_mnist = tf.keras.datasets.fashion_mnist
|
|
|
|
| 59 |
|
| 60 |
else:
|
| 61 |
return "Invalid Model Selection"
|
| 62 |
+
###
|
| 63 |
+
def predict(image_path, model):
|
| 64 |
+
test_image = load_image(image_path)
|
| 65 |
+
label, prediction = fashion_MNIST_prediction(test_image, model)
|
| 66 |
+
return label, prediction
|
| 67 |
+
|
| 68 |
+
image_paths = ['Ankle boot.jpg', 'bag.jpg', 'dress.jpg', 't-shirt.jpg']
|
| 69 |
+
###
|
| 70 |
input_image = gr.inputs.Image(shape=(28, 28), image_mode='L')
|
| 71 |
input_model = gr.inputs.Dropdown(['KNN', 'DecisionTreeClassifier', 'RandomForestClassifier', 'AdaBoostClassifier', 'GradientBoostingClassifier'])
|
| 72 |
|