nesaboz commited on
Commit
0496eb4
1 Parent(s): ca6a867

Added more examples.

Browse files
README.md CHANGED
@@ -12,6 +12,8 @@ license: apache-2.0
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
- Trying to reproduce Lesson #2 fast.ai
16
- inspiration: https://huggingface.co/spaces/jph00/testing
17
- https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial
 
 
 
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
 
15
+ Reproduced Lesson #2 fast.ai Practical Deep Learning for Coders.
16
+
17
+ Inspiration:
18
+ - https://huggingface.co/spaces/jph00/testing
19
+ - https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial
app.py CHANGED
@@ -1,25 +1,25 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
3
  import PIL
 
4
 
 
 
 
5
 
6
- categories = ('black', 'grizzly', 'teddy') # very careful here, order matters and it should be the same as when training
7
 
8
- learn = load_learner('bear_model.pkl')
9
-
10
-
11
- def classify_image(img):
12
- pred, idx, probs = learn.predict(img)
13
  return dict(zip(categories, map(float, probs)))
14
 
15
 
16
  image = gr.inputs.Image(shape=(192, 192))
17
  label = gr.outputs.Label()
18
- examples = ['sample_images/black_bear.jpeg', 'sample_images/grizzly_bear.jpeg', 'sample_images/grizzly_bear2.jpeg']
19
 
20
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples, title='Bear Classifier',
21
  description='Predicts between black, grizzly, and teddy bears.')
22
- # article="<p style='text-align: center'><a href='some URL' target='_blank'>Bear classifier</a></p>"
23
 
24
 
25
  intf.launch(inline=False)
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
  import PIL
4
+ import glob
5
 
6
+ # very careful here, order matters, and it should be the same as when training
7
+ categories = ('black', 'grizzly', 'teddy')
8
+ learner = load_learner('bear_model.pkl')
9
 
 
10
 
11
+ def classify_image(img: PILImage):
12
+ pred, idx, probs = learner.predict(img)
 
 
 
13
  return dict(zip(categories, map(float, probs)))
14
 
15
 
16
  image = gr.inputs.Image(shape=(192, 192))
17
  label = gr.outputs.Label()
18
+ examples = glob.glob('sample_images/*.*')
19
 
20
  intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples, title='Bear Classifier',
21
  description='Predicts between black, grizzly, and teddy bears.')
22
+ # article="<p style='text-align: center'><a href='some URL' target='_blank'>Bear classifier</a></p>"
23
 
24
 
25
  intf.launch(inline=False)
sample_images/comparison.jpg ADDED

Git LFS Details

  • SHA256: be0931e2253152009827647d27440719bec2eb2111813e63aa14d8bef3657e41
  • Pointer size: 131 Bytes
  • Size of remote file: 107 kB
sample_images/grizzly_bear3.jpeg ADDED

Git LFS Details

  • SHA256: 52e7a850f30a6f830fb97fa2b30738e993cb3015670264c0eb7a0a83e84ed811
  • Pointer size: 131 Bytes
  • Size of remote file: 167 kB
sample_images/{grizzly_bear.jpeg → grizzly_bear4.jpeg} RENAMED
File without changes
sample_images/massive_bear.jpg ADDED

Git LFS Details

  • SHA256: 51cfe847867f9a216b5543704a3c0c1630fcc06ce8ea2080ef0cf468b8a54637
  • Pointer size: 130 Bytes
  • Size of remote file: 47 kB
sample_images/polar_bear.jpg ADDED

Git LFS Details

  • SHA256: 6f0ecab9bc03c2c15b7529e444481dab66eee4432831b14e8a1de95b542276d8
  • Pointer size: 130 Bytes
  • Size of remote file: 62.4 kB
sample_images/sloth_bear.jpg ADDED

Git LFS Details

  • SHA256: 528099ffb9d035600e70e2a99ebf5a7cb2e1404bd834115d59a1171a4b9f84ec
  • Pointer size: 130 Bytes
  • Size of remote file: 55.6 kB
sample_images/teddy_bear.jpeg ADDED

Git LFS Details

  • SHA256: 3f12562e8d5c6c6cfead12e5a1d91f9f39d27595664b455f96b71c1a7d8c6e4c
  • Pointer size: 131 Bytes
  • Size of remote file: 145 kB