File size: 1,045 Bytes
813376b
 
 
 
 
 
243ce0b
813376b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).

__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']

# Cell
from fastai.vision.all import *
import gradio as gr

# Function to check if an image is of a cat or dog based on filename capitalization
def is_cat(x): 
    return x[0].isupper()

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

# Define categories for classification
categories = ('Dog', 'Cat')

# Image classification function
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

# Gradio UI components
image = gr.Image(type="pil")  # Use "pil" to ensure image is passed correctly
label = gr.Label()  # Updated from `gr.outputs.Label()`
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']  # Ensure these files exist

# Define the Gradio interface
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)

# Launch the Gradio app
intf.launch(inline=False)