Spaces:
Sleeping
Sleeping
Commit
·
bf3ad15
1
Parent(s):
e06fb02
all files
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
|
|
|
|
|
4 |
|
5 |
+
# Define a function for determining if image is a cat
|
6 |
+
def is_cat(x):
|
7 |
+
return x[0].isupper()
|
8 |
+
|
9 |
+
|
10 |
+
# Load pretrained model
|
11 |
+
learn = load_learner("model.pkl")
|
12 |
+
|
13 |
+
categories = ("Dog", "Cat")
|
14 |
+
|
15 |
+
|
16 |
+
def classify_image(img):
|
17 |
+
"""
|
18 |
+
Classify an image as a dog or cat.
|
19 |
+
:param img: Image to classify
|
20 |
+
:return: Dictionary of probabilities for each class
|
21 |
+
"""
|
22 |
+
pred, pred_idx, probs = learn.predict(img)
|
23 |
+
return dict(zip(categories, map(float, probs)))
|
24 |
+
|
25 |
+
|
26 |
+
image = gr.inputs.Image(shape=(224, 224))
|
27 |
+
label = gr.outputs.Label()
|
28 |
+
examples = ["dog.jpg", "cat.jpg", "tiger.jpg", "wolf.jpg"]
|
29 |
+
|
30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
31 |
+
intf.launch()
|