jacksonwambali's picture
Update app.py
d54549f verified
raw
history blame
601 Bytes
import gradio as gr
from fastai.vision.all import load_learner, PILImage
# Load your learner
learn = load_learner('export.pkl')
# Define the prediction function
def predict(img):
img = PILImage.create(img) # Convert image into PILImage
pred, pred_idx, probs = learn.predict(img) # Make prediction
labels = learn.dls.vocab # Get the labels
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# Define the Gradio interface
interface = gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3))
# Launch the interface
interface.launch(share=True)