samjeffcoat commited on
Commit
406195b
1 Parent(s): 5ebbdb0

updated files

Browse files
Files changed (2) hide show
  1. app.py +11 -9
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,21 +1,23 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
 
 
3
  import skimage
4
 
5
- learn = load_learner('model.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]: float(probs[i]) for i in range(len(labels))}
12
-
13
  title = "Pet Breed Classifier"
14
  description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
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', 'dog.jpg']
17
  interpretation='default'
18
  enable_queue=True
19
-
20
- demo = gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue)
21
- demo.launch()
 
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
+ from fastai.vision.widgets import *
4
+ from fastai.callback.preds import load_learner
5
  import skimage
6
 
7
+ learner = load_learner('model.pkl')
8
 
9
  labels = learn.dls.vocab
10
+ def classify_image(img):
11
+ pred, idx, probs = learner.predict(img)
12
+ return dict(zip(learner.dls.vocab, map(float, probs)))
 
 
13
  title = "Pet Breed Classifier"
14
  description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
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', 'dog.jpg']
17
  interpretation='default'
18
  enable_queue=True
19
+ image = gr.inputs.Image(shape=(192, 192))
20
+ label = gr.outputs.Label()
21
+ out_pl = widgets.Output()
22
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
23
+ intf.launch()
requirements.txt CHANGED
@@ -2,4 +2,5 @@ fastbook
2
  fastai
3
  gradio
4
  scikit-image
 
5
  numpy<1.24
 
2
  fastai
3
  gradio
4
  scikit-image
5
+
6
  numpy<1.24