File size: 497 Bytes
f8d7ce1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from fastai.vision.all import *
import gradio as gr

# Load the trained model
learn = load_learner("model.pkl")  # Ensure "model.pkl" is in the working directory

# Define a function to predict the class
def predict(img):
    pred, pred_idx, probs = learn.predict(img)
    return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}

# Create a Gradio interface
interface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label())

# Launch the app
interface.launch()