segadeds commited on
Commit
4206583
·
verified ·
1 Parent(s): 0a396dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -29
app.py CHANGED
@@ -1,36 +1,33 @@
1
  from fastai.vision.all import *
2
  import gradio as gr
3
-
4
 
5
  learn = load_learner('model.pkl')
6
 
7
-
8
-
9
- categories = (['abraham_grampa_simpson', 'agnes_skinner', 'apu_nahasapeemapetilon', 'barney_gumble', 'bart_simpson',
10
- 'carl_carlson', 'charles_montgomery_burns', 'chief_wiggum', 'cletus_spuckler', 'comic_book_guy', 'disco_stu',
11
- 'edna_krabappel', 'fat_tony', 'gil', 'groundskeeper_willie', 'homer_simpson', 'kent_brockman', 'krusty_the_clown',
12
- 'lenny_leonard', 'lionel_hutz', 'lisa_simpson', 'maggie_simpson', 'marge_simpson', 'martin_prince', 'mayor_quimby',
13
- 'milhouse_van_houten', 'miss_hoover', 'moe_szyslak', 'ned_flanders', 'nelson_muntz', 'otto_mann', 'patty_bouvier',
14
- 'principal_skinner', 'professor_john_frink', 'rainier_wolfcastle', 'ralph_wiggum', 'selma_bouvier', 'sideshow_bob',
15
- 'sideshow_mel', 'snake_jailbird', 'troy_mcclure', 'waylon_smithers'])
16
-
17
-
18
 
19
  def classify_image(img):
20
- img = PILImage.create(img).resize((192, 192))
21
- pred,idx,probs = learn.predict(img)
22
- return dict(zip(categories, map(float,probs)))
23
-
24
-
25
-
26
- image = gr.Image(type='pil')
27
- label = gr.Label()
28
- examples = ['ednar.jpg', 'maggie.jpg', 'bart.jpg']
29
-
30
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
31
- intf.launch(inline=False)
32
-
33
-
34
-
35
-
36
-
 
1
  from fastai.vision.all import *
2
  import gradio as gr
3
+ from PIL import Image as PILImage
4
 
5
  learn = load_learner('model.pkl')
6
 
7
+ categories = ['abraham_grampa_simpson', 'agnes_skinner', 'apu_nahasapeemapetilon', 'barney_gumble',
8
+ 'bart_simpson', 'carl_carlson', 'charles_montgomery_burns', 'chief_wiggum',
9
+ 'cletus_spuckler', 'comic_book_guy', 'disco_stu', 'edna_krabappel', 'fat_tony',
10
+ 'gil', 'groundskeeper_willie', 'homer_simpson', 'kent_brockman', 'krusty_the_clown',
11
+ 'lenny_leonard', 'lionel_hutz', 'lisa_simpson', 'maggie_simpson', 'marge_simpson',
12
+ 'martin_prince', 'mayor_quimby', 'milhouse_van_houten', 'miss_hoover', 'moe_szyslak',
13
+ 'ned_flanders', 'nelson_muntz', 'otto_mann', 'patty_bouvier', 'principal_skinner',
14
+ 'professor_john_frink', 'rainier_wolfcastle', 'ralph_wiggum', 'selma_bouvier',
15
+ 'sideshow_bob', 'sideshow_mel', 'snake_jailbird', 'troy_mcclure', 'waylon_smithers']
 
 
16
 
17
  def classify_image(img):
18
+ img = PILImage.fromarray(img).resize((192, 192))
19
+ pred, idx, probs = learn.predict(img)
20
+ return {cat: float(prob) for cat, prob in zip(categories, probs)}
21
+
22
+ demo = gr.Interface(
23
+ fn=classify_image,
24
+ inputs=gr.Image(type='numpy'),
25
+ outputs=gr.Label(),
26
+ examples=[
27
+ 'ednar.jpg',
28
+ 'maggie.jpg',
29
+ 'bart.jpg'
30
+ ]
31
+ )
32
+
33
+ demo.launch()