Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
|
2 |
+
|
3 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
4 |
+
|
5 |
+
# Cell
|
6 |
+
from fastai.vision.all import *
|
7 |
import gradio as gr
|
8 |
+
|
9 |
+
# Function to check if an image is of a cat or dog based on filename capitalization
|
10 |
+
def is_cat(x):
|
11 |
+
return x[0].isupper()
|
12 |
+
|
13 |
+
# Load the trained model
|
14 |
+
learn = load_learner('model.pkl')
|
15 |
+
|
16 |
+
# Define categories for classification
|
17 |
+
categories = ('Dog', 'Cat')
|
18 |
+
|
19 |
+
# Image classification function
|
20 |
+
def classify_image(img):
|
21 |
+
pred, idx, probs = learn.predict(img)
|
22 |
+
return dict(zip(categories, map(float, probs)))
|
23 |
+
|
24 |
+
# Gradio UI components
|
25 |
+
image = gr.Image(type="pil") # Use "pil" to ensure image is passed correctly
|
26 |
+
label = gr.Label() # Updated from `gr.outputs.Label()`
|
27 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg'] # Ensure these files exist
|
28 |
+
|
29 |
+
# Define the Gradio interface
|
30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
31 |
+
|
32 |
+
# Launch the Gradio app
|
33 |
+
intf.launch(inline=False)
|