Update app.py
Browse files
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 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
def classify_image(img):
|
20 |
-
img = PILImage.
|
21 |
-
pred,idx,probs = learn.predict(img)
|
22 |
-
return
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
examples
|
29 |
-
|
30 |
-
|
31 |
-
|
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()
|
|