devdata commited on
Commit
2122cec
·
1 Parent(s): f73982f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -1,19 +1,23 @@
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]: float(probs[i]) for i in range(len(labels))}
 
12
 
13
  examples = ['image1.jpg', 'image2.jpg']
14
  interpretation='default'
15
  enable_queue=True
16
 
17
- #gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
18
- gr.Interface(fn=predict,inputs=gr.components.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
19
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
  import skimage
4
+ from fastai.vision.all import PILImage
5
 
6
  learn = load_learner('export.pkl')
7
 
8
+
9
  labels = learn.dls.vocab
10
+
11
  def predict(img):
12
+ img = PILImage.create(img)
13
+ img = img.resize((512, 512))
14
+ pred,pred_idx,probs = learn.predict(img)
15
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
  examples = ['image1.jpg', 'image2.jpg']
18
  interpretation='default'
19
  enable_queue=True
20
 
21
+ gr.Interface(fn=predict, inputs=gr.components.Image(), outputs=gr.outputs.Label(num_top_classes=3), examples=examples, interpretation=interpretation, enable_queue=enable_queue).launch()
22
+
23