Spaces:
Sleeping
Sleeping
Add app.py, images and requirements
Browse files- app.py +32 -0
- images/cat.jpeg +0 -0
- images/dog.jpeg +0 -0
- images/face.jpg +0 -0
- images/profile-avatar.jpeg +0 -0
- images/tori-logo.png +0 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__all__ = ['learn', 'categories', 'examples', 'image', 'label', 'intf', 'classify_image']
|
2 |
+
|
3 |
+
from fastai.vision.all import *
|
4 |
+
import gradio as gr
|
5 |
+
import timm
|
6 |
+
|
7 |
+
# the get_y function
|
8 |
+
def has_tori_logo_parent(o):
|
9 |
+
p = Path(o).parent.name
|
10 |
+
return p == 'tori-logo'
|
11 |
+
|
12 |
+
learn = load_learner('tori-model.pkl')
|
13 |
+
|
14 |
+
categories = ['Something else', 'Tori logo']
|
15 |
+
|
16 |
+
def classify_image(img):
|
17 |
+
is_tori_logo, idx, probs = learn.predict(img)
|
18 |
+
return dict(zip(categories, map(float,probs)))
|
19 |
+
|
20 |
+
examples = [
|
21 |
+
'images/dog.jpeg',
|
22 |
+
'images/cat.jpeg',
|
23 |
+
'images/face.jpg',
|
24 |
+
'images/profile-avatar.jpeg',
|
25 |
+
'images/tori-logo.png'
|
26 |
+
]
|
27 |
+
|
28 |
+
image = gr.Image()
|
29 |
+
label = gr.Label()
|
30 |
+
|
31 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
32 |
+
intf.launch()
|
images/cat.jpeg
ADDED
![]() |
images/dog.jpeg
ADDED
![]() |
images/face.jpg
ADDED
![]() |
images/profile-avatar.jpeg
ADDED
![]() |
images/tori-logo.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
gradio
|
3 |
+
timm
|
4 |
+
torch
|
5 |
+
torchvision
|