satani commited on
Commit
1fbfecc
1 Parent(s): acf2b04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -1,15 +1,18 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
3
 
4
- learn_inf = load_learner('export.pkl')
5
- def classify_image(img):
6
- pred,pred_idx,probs = learn_inf.predict(img)
7
- return dict(zip(pred, map(float, probs[pred_idx])))
8
-
9
  image = gr.inputs.Image(shape=(224, 224))
10
  label = gr.outputs.Label()
11
  examples = ['1.jpg', '2.jpg', '3.jpg']
12
 
13
 
14
- iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
15
- iface.launch(inline=False)
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
+ learner = load_learner('export.pkl')
4
+
5
+
6
+ labels = learner.dls.vocab
7
+
8
+ def predict(img):
9
+ img = PILImage.create(img)
10
+ pred, pred_idx, probs = learner.predict(img)
11
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
 
 
 
 
 
 
13
  image = gr.inputs.Image(shape=(224, 224))
14
  label = gr.outputs.Label()
15
  examples = ['1.jpg', '2.jpg', '3.jpg']
16
 
17
 
18
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(224, 224)), outputs=gr.outputs.Label(num_top_classes=3), examples=examples).launch(share=True, debug=True)