Spaces:
Runtime error
Runtime error
Commit
·
62d3088
1
Parent(s):
b9c36cc
test
Browse files- app.py +18 -4
- model.pkl +3 -0
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
1 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categoreies', 'image', 'label', 'examples', 'intf']
|
2 |
+
|
3 |
+
from fastai.vision import *
|
4 |
import gradio as gr
|
5 |
|
6 |
+
def is_cat(x): return x[0].obj == 'cat'
|
7 |
+
|
8 |
+
learn = load_learner('model.pkl')
|
9 |
+
|
10 |
+
categories = ('Dog', 'Cat')
|
11 |
+
|
12 |
+
def classify_image(img):
|
13 |
+
pred_class, pred_idx, outputs = learn.predict(img)
|
14 |
+
return dict(zip(categories, map(float,probs)))
|
15 |
+
# return {'label': str(pred_class), 'confidence': float(outputs[pred_idx])}
|
16 |
|
17 |
+
image = gr.inputs.Image(shape=(192,192))
|
18 |
+
label = gr.outputs.Label(num_top_classes=2)
|
19 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
20 |
+
intf = gr.Interface(classify_image, image, label, capture_session=True, examples=examples)
|
21 |
+
intf.launch()
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1fc32c3ba5114f2ec20768522beea7f7459d15b4bdaf7c3c710fc3f524176de2
|
3 |
+
size 47063121
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastai
|