import gradio as gr import gr.themes.* # import model for gradio learn_gradio = load_learner('image_classifier_flowers.pkl') # build prediction function labels = learn_gradio.dls.vocab def predict(img): img = PILImage.create(img) pred,pred_idx,probs = learn_gradio.predict(img) return {str(labels[i]): float(probs[i]) for i in range(len(labels))} # build gradio interface gradio_interface = gr.Interface( theme=gr.themes.Soft(), title = "Flower Image Classifier", description = "A simple classifier for the 102-category Flower Dataset", fn=predict, inputs = gr.inputs.Image(shape=(224,224)), outputs = gr.outputs.Label(num_top_classes=5), enable_queue=True, ) # launch interface gradio_interface.launch(share=True)