Nitin Bhandari commited on
Commit
94810ee
1 Parent(s): bfb3aaa

this should work

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -1,24 +1,27 @@
1
- import gradio as gr
 
 
 
 
2
  from fastai.vision.all import *
3
- import skimage
 
 
 
 
4
 
5
- learn = load_learner('export.pkl')
 
6
 
7
- labels = learn.dls.vocab
8
- def predict(img):
9
- img = PILImage.create(img)
10
- pred, pred_idx, probs = learn.predict(img)
11
- return {labels[i]: folat(probs[i] for in in range(len(labels)))}
12
 
13
- title = 'Pet Breed Classifier'
14
- description = 'A pet breed classifier trained on the Oxford Pets dataset'
15
- article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
16
- examples = ['siamese.jpg']
17
- interpretation='default'
18
- enable_queue=True
19
 
20
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)),
21
- outputs=gr.outputs.Label(num_top_classes=3),
22
- title=title, description=description, article=article,
23
- examples=examples, interpretation=interpretation,
24
- enable_queue=enable_queue).launch()
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).
2
+
3
+ __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
4
+
5
+ # Cell
6
  from fastai.vision.all import *
7
+ import gradio as gr
8
+ import timm
9
+
10
+ # Cell
11
+ learn = load_learner('model_021724.pkl')
12
 
13
+ # Cell
14
+ categories = learn.dls.vocab
15
 
16
+ def classify_image(img):
17
+ pred, idx, probs = learn.predict(img)
18
+ return dict(zip(categories, map(float,probs)))
 
 
19
 
20
+ # Cell
21
+ image = gr.inputs.Image(shape=(192, 192))
22
+ label = gr.outputs.Label()
23
+ examples = ['basset.jpg']
 
 
24
 
25
+ # Cell
26
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
27
+ intf.launch()