File size: 535 Bytes
585b30b
79deeab
585b30b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from fastai.vision.all import *
import gradio as gr

learn = load_learner('resnet50_30_categories.pkl')

def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}

iface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3),
    title="Flower Classifier",
    description="Upload an image of a flower and the model will predict its category."
)

if __name__ == "__main__":
    iface.launch()