iamalos commited on
Commit
dfb23f2
1 Parent(s): 216423a
Files changed (4) hide show
  1. app.py +43 -0
  2. requirements.txt +2 -0
  3. shiba.jpeg +0 -0
  4. yorkshire_terrier.jpeg +0 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['labels', 'title', 'description', 'article', 'image', 'label', 'examples', 'interpretation', 'enable_queue', 'intf',
5
+ 'classify_image']
6
+
7
+ # %% app.ipynb 1
8
+ import nbdev
9
+ from fastai.vision.all import *
10
+ import scipy
11
+ import gradio as gr
12
+
13
+ # %% app.ipynb 3
14
+ labels = learner.dls.vocab
15
+
16
+ def classify_image(img):
17
+ """Gradio need a f-n that returns a dict of each class and its probability.
18
+ It also does not accept tensors.
19
+ """
20
+ img = PILImage.create(img)
21
+ pred, pred_idx, probs = learner.predict(img)
22
+ return dict(zip(labels, map(float, probs)))
23
+
24
+ # %% app.ipynb 4
25
+ title = "Cat & Dog Breed Classifier"
26
+ description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
27
+ article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
28
+
29
+ image = gr.components.Image(shape=(512,512))
30
+ label = gr.components.Label(num_top_classes=3)
31
+ examples = ['shiba.jpeg', 'yorkshire_terrier.jpeg']
32
+ interpretation = 'default'
33
+ enable_queue=True
34
+
35
+ intf = gr.Interface(classify_image,
36
+ inputs = image,
37
+ outputs=label,
38
+ examples=examples,
39
+ title=title,
40
+ description=description,
41
+ interpretation=interpretation)
42
+
43
+ intf.launch(enable_queue=enable_queue)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ scikit-image
shiba.jpeg ADDED
yorkshire_terrier.jpeg ADDED