AryanK commited on
Commit
18f5763
1 Parent(s): 7f37819

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -37
app.py CHANGED
@@ -1,52 +1,26 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['btn_upload', 'out_pl', 'lbl_pred', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'DataLoaders',
5
- 'is_cat', 'classify_img']
6
 
7
  # %% app.ipynb 2
8
  from fastai.vision.all import *
9
  import gradio as gr
10
- from fastbook import *
11
- from fastai.vision.widgets import *
12
- import gradio as gr
13
- btn_upload = widgets.FileUpload()
14
- out_pl = widgets.Output()
15
- lbl_pred = widgets.Label()
16
-
17
- # %% app.ipynb 3
18
- # def on_data_change(change):
19
- # lbl_pred.value = ''
20
- # img = PILImage.create(btn_upload.data[-1])
21
- # out_pl.clear_output()
22
- # with out_pl: display(img.to_thumb(128,128))
23
- # pred,pred_idx,probs = learn_inf.predict(img)
24
- # lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
25
-
26
- class DataLoaders(GetAttr):
27
- def __init__(self, *loaders): self.loaders = loaders
28
- def __getitem__(self, i): return self.loaders[i]
29
- train,valid = add_props(lambda i,self: self[i])
30
-
31
- def is_cat(x): return x[0].isupper()
32
-
33
-
34
 
35
  # %% app.ipynb 4
36
  learn = load_learner('export.pkl')
37
- print(type(learn))
38
 
39
- # %% app.ipynb 7
40
- categories = ('black', 'grizzly', 'teddy')
41
 
42
  # %% app.ipynb 8
43
- def classify_img(img):
44
- cat,idx, prob = learn.predict(img)
45
- return dict(zip(categories, map(float,prob)))
46
 
47
  # %% app.ipynb 10
48
- image = gr.inputs.Image(shape = (192,192))
49
- label = gr.outputs.Label()
50
- examples = ['teddy.png', 'grizzly.jpg','black.jpeg']
51
- intf = gr.Interface(fn = classify_img, inputs = image, outputs = label, examples = examples)
52
- intf.launch(inline = False)
 
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['learn', 'image', 'label', 'examples', 'intf', 'classify_image']
 
5
 
6
  # %% app.ipynb 2
7
  from fastai.vision.all import *
8
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # %% app.ipynb 4
11
  learn = load_learner('export.pkl')
12
+ # print(type(learn))
13
 
 
 
14
 
15
  # %% app.ipynb 8
16
+ def classify_image(img):
17
+ pred,pred_idx,probs = learn.predict(img)
18
+ return dict(zip(learn.dls.vocab, map(float, probs)))
19
 
20
  # %% app.ipynb 10
21
+ image = gr.components.Image(shape=(192,192))
22
+ label = gr.components.Label()
23
+ examples = ['teddy.png', 'grizzly.jpg', 'black.jpeg']
24
+
25
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
26
+ intf.launch(inline=False)