from gradio.outputs import Label import gradio as gr import cv2 import tensorflow as tf def caption(image,input_module1): class_names = ["T-shirt/top", "Trouser", "Pullover", "Dress", "Coat", "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"] image=image.reshape(1,28*28) if input_module1=="KNN": output1=KNN_classifier.predict(image)[0] predictions=KNN_classifier.predict_proba(image)[0] elif input_module1==("Linear discriminant analysis"): output1=clf.predict(image)[0] predictions=clf.predict_proba(image)[0] elif input_module1==("Quadratic discriminant analysis"): output1=qda.predict(image)[0] predictions=qda.predict_proba(image)[0] elif input_module1=="Naive Bayes classifier": output1=gnb.predict(image)[0] predictions=gnb.predict_proba(image)[0] output2 = {} for i in range(len(predictions)): output2[class_names[i]] = predictions[i] return output1 ,output2 input_module = gr.inputs.Image(label = "Input Image",image_mode="L",shape=(28,28)) input_module1 = gr.inputs.Dropdown(choices=["KNN","Linear discriminant analysis", "Quadratic discriminant analysis","Naive Bayes classifier"], label = "Method") output1 = gr.outputs.Textbox(label = "Predicted Class") output2=gr.outputs.Label(label= "probability of class") gr.Interface(fn=caption, inputs=[input_module,input_module1], outputs=[output1,output2]).launch(debug=True)