File size: 649 Bytes
8a995a0
7dbc0fb
 
8a995a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7dbc0fb
 
 
8a995a0
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
28
from fastai.vision.all import *
import gradio as gr

# Load the model and define categories
categories = ['dog', 'cat']
learn = load_learner('model.pkl')

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

# Create Gradio interface components
image = gr.components.Image()
label = gr.components.Label()
examples = [['dog.jpg'], ['cat.jpg']]

# Create and launch the interface
interface = gr.Interface(
    fn=is_cat,
    inputs=image,
    outputs=label,
    examples=examples,
    title="Cat vs Dog Classifier"
)

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