| from fastai.vision.all import * | |
| import gradio as gr | |
| # def greet(name): | |
| # return "Hello " + name + "!!" | |
| def is_cat(x): | |
| return x[0].isupper() | |
| learn = load_learner('model.pkl') | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(learn.dls.vocab, map(float, probs))) | |
| image = gr.Image(shape=(192, 192)) | |
| label = gr.outputs.Label() | |
| demo = gr.Interface(fn=classify_image, inputs=image, outputs=label) | |
| # demo.launch() | |
| # demo = gr.Interface( | |
| # fn = classify_image, | |
| # inputs=gr.Image(type='pil'), | |
| # outputs=[gr.Textbox(label="Predicted Label"), gr.Image(label="Labeled Image")], | |
| # title="Image Classification App", | |
| # description="Upload an image and get the predicted label and labeled image." | |
| # ) | |
| if __name__ == "__main__": | |
| demo.launch(share=True) |