File size: 786 Bytes
8a995a0
7dbc0fb
 
c3b11dd
8a995a0
c3b11dd
 
 
 
 
 
8a995a0
 
c3b11dd
 
8a995a0
 
 
 
 
 
 
 
 
 
c3b11dd
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
29
30
31
32
33
34
35
from fastai.vision.all import *
import gradio as gr

# Define categories
categories = ['dog', 'cat']

# Define the function that was used during training
def is_cat(x): 
    return x[0].isupper()

# Load the model
learn = load_learner('model.pkl')

# Gradio prediction function
def predict_image(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=predict_image,
    inputs=image,
    outputs=label,
    examples=examples,
    title="Cat vs Dog Classifier"
)

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