leduccam commited on
Commit
59b5c61
·
1 Parent(s): 786d483
Files changed (2) hide show
  1. app.py +15 -13
  2. requirements.txt +0 -1
app.py CHANGED
@@ -1,19 +1,21 @@
1
  import gradio as gr
2
- from fastai.vision.widgets import *
3
  from fastai.vision.all import *
4
- import skimage
5
 
6
  learn = load_learner('export.pkl')
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
- # title = "Pet Breed Classifier"
13
- # description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
14
- # article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
 
 
 
15
  examples = ['tank_1.jpg', 'tank_2.jfif', 'photos.jfif']
16
- # interpretation='default'
17
- # enable_queue=True
18
 
19
- gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(256, 256)), outputs=gr.outputs.Label(), example=examples).launch(share=True)
 
 
1
  import gradio as gr
2
+ # from fastai.vision.widgets import *
3
  from fastai.vision.all import *
4
+ # import skimage
5
 
6
  learn = load_learner('export.pkl')
7
+
8
+ # Cell
9
+ categories = ('Tank', 'No-Tank')
10
+
11
+ def classify_image(img):
12
+ pred,idx,probs = learn.predict(img)
13
+ return dict(zip(categories, map(float,probs)))
14
+
15
+ # Cell
16
+ image = gr.inputs.Image(shape=(256, 256))
17
+ label = gr.outputs.Label()
18
  examples = ['tank_1.jpg', 'tank_2.jfif', 'photos.jfif']
 
 
19
 
20
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
21
+ intf.launch(inline=False)
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
  fastai==2.7.5
2
  fastcore==1.4.5
3
- scikit-image
4
  ipywidgets
 
1
  fastai==2.7.5
2
  fastcore==1.4.5
 
3
  ipywidgets