Praneeth383 commited on
Commit
fbcd3b4
·
1 Parent(s): 4a7a2a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -6,6 +6,16 @@ from sklearn.tree import DecisionTreeClassifier
6
  from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
7
  import joblib
8
  import pickle
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
  def fashion_MNIST_prediction(test_image, model='KNN'):
@@ -52,6 +62,14 @@ def fashion_MNIST_prediction(test_image, model='KNN'):
52
 
53
  else:
54
  return "Invalid Model Selection"
 
 
 
 
 
 
 
 
55
 
56
  input_image = gr.inputs.Image(shape=(28, 28), image_mode='L')
57
  input_model = gr.inputs.Dropdown(['KNN', 'DecisionTreeClassifier', 'RandomForestClassifier', 'AdaBoostClassifier', 'GradientBoostingClassifier'])
 
6
  from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier
7
  import joblib
8
  import pickle
9
+ from PIL import Image
10
+
11
+ def load_image(image_path):
12
+ """
13
+ Load image from file path and convert to numpy array
14
+ """
15
+ with Image.open(image_path).convert('L') as img:
16
+ img = img.resize((28,28))
17
+ img = np.array(img)
18
+ return img
19
 
20
 
21
  def fashion_MNIST_prediction(test_image, model='KNN'):
 
62
 
63
  else:
64
  return "Invalid Model Selection"
65
+ ###
66
+ def predict(image_path, model):
67
+ test_image = load_image(image_path)
68
+ label, prediction = fashion_MNIST_prediction(test_image, model)
69
+ return label, prediction
70
+
71
+ image_paths = ['Ankle boot.jpg', 'bag.jpg', 'dress.jpg', 't-shirt.jpg']
72
+ ###
73
 
74
  input_image = gr.inputs.Image(shape=(28, 28), image_mode='L')
75
  input_model = gr.inputs.Dropdown(['KNN', 'DecisionTreeClassifier', 'RandomForestClassifier', 'AdaBoostClassifier', 'GradientBoostingClassifier'])