Daniel-Sousa commited on
Commit
9679546
·
1 Parent(s): fe1d000

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,17 +1,17 @@
1
- import gradio as gr
2
  from fastai.vision.all import *
3
- import skimage
4
 
5
  learn = load_learner('model.pkl')
 
6
 
7
- examples = ['sonic.jpg', 'eggman.jpg']
8
-
9
-
10
- labels = learn.dls.vocab
11
  def predict(img):
12
- img = PILImage.create(img)
13
  pred,pred_idx,probs = learn.predict(img)
14
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
15
 
16
  title = "Sonic the Hedgehog and Doutor Eggman"
17
  description = "Classificador entre o Sonic e o Doutor Eggman"
@@ -19,11 +19,13 @@ examples = ['sonic.jpg', 'eggman.jpg']
19
  interpretation='default'
20
  enable_queue=True
21
 
22
- gr.Interface(fn=predict,
23
- inputs=gr.Interface.Inputs.Image(shape=(512, 512)),
24
- outputs=gr.outputs.Label(num_top_classes=2),
25
  title=title,
26
  description=description,
27
  examples=examples,
28
  interpretation=interpretation,
29
- enable_queue=enable_queue).launch(share=True)
 
 
 
 
1
  from fastai.vision.all import *
2
+ import gradio as gr
3
 
4
  learn = load_learner('model.pkl')
5
+ categories = ('Sonic the Hedgehog', 'Doutor Eggman')
6
 
 
 
 
 
7
  def predict(img):
 
8
  pred,pred_idx,probs = learn.predict(img)
9
+ return dict(zip(categories, map(float, probs)))
10
+
11
+ image = gr.Image()
12
+ label = gr.Label()
13
+
14
+ examples = ['sonic.jpg', 'eggman.jpg']
15
 
16
  title = "Sonic the Hedgehog and Doutor Eggman"
17
  description = "Classificador entre o Sonic e o Doutor Eggman"
 
19
  interpretation='default'
20
  enable_queue=True
21
 
22
+ iface = gr.Interface(fn=predict,
23
+ inputs=image,
24
+ outputs=label,
25
  title=title,
26
  description=description,
27
  examples=examples,
28
  interpretation=interpretation,
29
+ enable_queue=enable_queue)
30
+
31
+ iface.launch(inline=False)