Spaces:
Build error
Build error
Daniel Martinec
commited on
Commit
·
a60c626
1
Parent(s):
72f73fb
Adding app
Browse files- app.ipynb +0 -0
- app.py +36 -0
- requirements.txt +2 -0
app.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'get_y', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# %% ../app.ipynb 3
|
11 |
+
# Copied from https://n90l9ahmyv.clg07azjl.paperspacegradient.com/lab/tree/bear_multicat.ipynb
|
12 |
+
|
13 |
+
# from parent_label
|
14 |
+
def get_y(o):
|
15 |
+
parent_name = Path(o).parent.name
|
16 |
+
if parent_name in bear_types:
|
17 |
+
return [parent_name]
|
18 |
+
return []
|
19 |
+
|
20 |
+
# %% ../app.ipynb 4
|
21 |
+
learn = load_learner('Finley_multicat.pkl') #'export.pkl')
|
22 |
+
|
23 |
+
# %% ../app.ipynb 6
|
24 |
+
categories = ('Finley', 'bird')
|
25 |
+
|
26 |
+
def classify_image(im):
|
27 |
+
pred, idx, probs = learn.predict(im)
|
28 |
+
return dict(zip(categories, map(float, probs)))
|
29 |
+
|
30 |
+
# %% ../app.ipynb 8
|
31 |
+
image = gr.Image(width=192, height=192)
|
32 |
+
label = gr.Label()
|
33 |
+
examples = ['images/Finley.jpeg', 'images/bird.jpg']
|
34 |
+
|
35 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
36 |
+
intf.launch(inline=False)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
gradio
|