Kornel Szabo commited on
Commit
fe31411
1 Parent(s): f70d1d7

First commit

Browse files
Files changed (3) hide show
  1. app.py +39 -0
  2. data/spider1.jpg +0 -0
  3. data/spider2.jpg +0 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: 02_spider_deploy.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'path', 'categories', 'image', 'output', 'examples', 'intf', 'second', 'classify_image']
5
+
6
+ # %% 02_spider_deploy.ipynb 0
7
+ from fastbook import *
8
+
9
+ # %% 02_spider_deploy.ipynb 2
10
+ import gradio as gr
11
+
12
+ # %% 02_spider_deploy.ipynb 3
13
+ learn = load_learner("spider.pkl")
14
+
15
+ # %% 02_spider_deploy.ipynb 4
16
+ path = Path("data/spiders")
17
+ categories = learn.dls.vocab
18
+
19
+ # %% 02_spider_deploy.ipynb 5
20
+ def second(x):
21
+ a, b = x
22
+ return b
23
+
24
+ def classify_image(img):
25
+ image = Image.fromarray(img)
26
+ image.thumbnail(size=(224,224))
27
+ img = np.asarray(img)
28
+ ans,idx,preds = learn.predict(img)
29
+ results = zip(categories, map(float, preds))
30
+ results = sorted(results, key=second, reverse=True)
31
+ return dict(results[:10])
32
+
33
+ # %% 02_spider_deploy.ipynb 7
34
+ image = gr.inputs.Image()
35
+ output = gr.outputs.Label()
36
+ examples = ["data/spider1.jpg", "data/spider2.jpg"]
37
+
38
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=output, examples=examples)
39
+ intf.launch(inline=False)
data/spider1.jpg ADDED
data/spider2.jpg ADDED