M009 commited on
Commit
77a20d4
1 Parent(s): 82a6ec2

Upload 10 files

Browse files
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from sklearn.tree import DecisionTreeClassifier
3
+ from sklearn.ensemble import RandomForestClassifier
4
+ import joblib
5
+ from sklearn.ensemble import AdaBoostClassifier
6
+ from sklearn.ensemble import GradientBoostingClassifier
7
+ from sklearn.neighbors import KNeighborsClassifier
8
+ import numpy as np
9
+
10
+ import gradio as gr
11
+ # define image data type
12
+ input_image = gr.inputs.Image(label = "Input Image")
13
+ select_algorithm = gr.inputs.Dropdown(choices=["Decision Tree", "Random Forest", "AdaBoost", "Gradient Tree Boosting", "KNN"], label = "Select Algorithm")
14
+
15
+ out_classify = gr.outputs.Textbox(label = "Predict Class")
16
+ out_prob = gr.outputs.Textbox(label = "Predict Probability")
17
+
18
+ """
19
+ gradio interface
20
+ """
21
+ def predict_interface(input_image, select_algorithm):
22
+ """
23
+ evaluate model
24
+ """
25
+ # Convert image to NumPy array
26
+ print(input_image.shape)
27
+ input_image2 = input_image.mean(axis=2)
28
+ print(input_image2.shape)
29
+ img_array = input_image2.reshape(1, 28*28)
30
+
31
+
32
+ model_dict = {"Decision Tree":"best_dt_model.joblib",
33
+ "Random Forest":"best_rf_model.joblib",
34
+ "AdaBoost":"best_ada_model.joblib",
35
+ "Gradient Tree Boosting":"best_gbc_model.joblib",
36
+ "KNN":"best_knn_model.joblib"}
37
+ # Reload the best trained model from disk using joblib
38
+ loaded_model = joblib.load(model_dict[select_algorithm])
39
+
40
+ # Use the reloaded model to make predictions on the validation data
41
+ out_classify = loaded_model.predict(img_array)
42
+ out_prob = loaded_model.predict_proba(img_array)
43
+ class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat",
44
+ "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]
45
+ out_prob2 = '\n'.join([f"{name}\t\t\t{np.round(pro,2)}" for name, pro in zip(class_names, out_prob[0])])
46
+ return class_names[out_classify[0]], out_prob2
47
+
48
+ gr.Interface(fn=predict_interface, inputs=[input_image, select_algorithm],
49
+ outputs=[out_classify, out_prob],
50
+ examples=[["fashion_1.png", "Random Forest"],
51
+ ["fashion_2.png", "Random Forest"],
52
+ ["fashion_3.png", "Random Forest"]]
53
+ ).launch(debug=True)
54
+
best_ada_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a05a9e23f943f0a12bbf6890f7ef8781d8498da0f17fee0dee4d381c981efec
3
+ size 131340
best_dt_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ed195418d7fd560f6877e84b497e419ce85e6990ee34a338bf1e0ae96902ea1
3
+ size 32329
best_gbc_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a36fc928b73970b618ddc709d8a3c6b6d425a886abee322b9775cf27a1425b4
3
+ size 1541752
best_knn_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19d89e9199b92c58534594d33c8db5f397f221c74a13462f9c2028e5c87f27d1
3
+ size 792724
best_rf_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2754f6aa4dcf53e98f9948d8d9b53b1e2ec4f7670866e8d9b3c3919b64617ac1
3
+ size 2477821
fashion_1.png ADDED
fashion_2.png ADDED
fashion_3.png ADDED
requirements (1).txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.18.0
2
+ joblib==1.1.1
3
+ scikit-learn==1.2.2
4
+