File size: 870 Bytes
1573feb
 
 
28212a0
 
 
 
 
1573feb
28212a0
672c0e7
28212a0
 
af62eda
28212a0
1573feb
672c0e7
 
 
 
 
 
af62eda
672c0e7
28212a0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from fastai.vision.all import *

# Load your trained model
def load_model():
    path = 'export.pkl'
    learn = load_learner(path)
    return learn

learn = load_model()

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

# Ensure this matches the function name used in the Interface
interface = gr.Interface(fn=predict_image,
                         inputs=gr.Image(type="pil"),  # Corrected to use gr.Image
                         outputs=gr.Label(num_top_classes=3),
                         title="Image Classifier",
                         description="Upload an image to classify.")

# Use the defined 'interface' variable to launch the Gradio interface
if __name__ == "__main__":
    interface.launch()