Orawan commited on
Commit
36f9238
1 Parent(s): 41de011

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def caption(image,input_module1):
4
+ instances_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat",
5
+ "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"]
6
+ image=image.reshape(1,28*28)
7
+ if input_module1=="KNN":
8
+ KNN_classifier = KNeighborsClassifier(n_neighbors=5, metric = 'euclidean')
9
+ output1=KNN_classifier.predict(image)[0]
10
+ predictions=KNN_classifier.predict_proba(image)[0]
11
+
12
+ elif input_module1==("Linear discriminant analysis"):
13
+ clf = LinearDiscriminantAnalysis()
14
+ output1=clf.predict(image)[0]
15
+ predictions=clf.predict_proba(image)[0]
16
+
17
+ elif input_module1==("Quadratic discriminant analysis"):
18
+ qda = QuadraticDiscriminantAnalysis()
19
+ output1=qda.predict(image)[0]
20
+ predictions=qda.predict_proba(image)[0]
21
+
22
+ elif input_module1=="Naive Bayes classifier":
23
+ gnb = GaussianNB()
24
+ output1=gnb.predict(image)[0]
25
+ predictions=gnb.predict_proba(image)[0]
26
+
27
+ output2 = {}
28
+
29
+ for i in range(len(predictions)):
30
+ output2[instances_names[i]] = predictions[i]
31
+ return output1 ,output2
32
+
33
+ input_module = gr.inputs.Image(label = "Input Image",image_mode="L",shape=(28,28))
34
+ input_module1 = gr.inputs.Dropdown(choices=["KNN","Linear discriminant analysis", "Quadratic discriminant analysis","Naive Bayes classifier"], label = "Method")
35
+ output1 = gr.outputs.Textbox(label = "Predicted Class")
36
+ output2=gr.outputs.Label(label= "probability of class")
37
+ gr.Interface(fn=caption, inputs=[input_module,input_module1], outputs=[output1,output2]).launch(debug=True)