import gradio as gr | |
import pickle | |
# pip install -Uqq fastbook | |
# from fastbook import * | |
from fastai.vision.all import * | |
from fastai.learner import load_learner | |
# Load the trained model | |
learn = load_learner('model.pkl') | |
labels = learn.dls.vocab | |
def predict(img): | |
pred, _, probs = learn.predict(img) | |
return f"This is a {pred} with probability {probs[pred_idx]}" | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=predict, | |
inputs=gr.Image(), | |
outputs="text" | |
) | |
iface.launch(share=True) |