jk
commited on
Commit
•
e557ac7
1
Parent(s):
a2b0967
updated app.py added example image files
Browse files- app.py +35 -3
- happy.png +0 -0
- happy2.png +0 -0
- happy3.png +0 -0
- happy4.png +0 -0
- happy5.png +0 -0
- other.png +0 -0
- other2.png +0 -0
- other3.png +0 -0
- other4.png +0 -0
- other5.png +0 -0
app.py
CHANGED
@@ -1,7 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
7 |
demo.launch(share=True)
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
#
|
3 |
+
# def greet(name):
|
4 |
+
# return "Hello " + name + "!!"
|
5 |
+
#
|
6 |
+
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
# demo.launch(share=True)
|
8 |
+
|
9 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: inference-face-crop-model.ipynb.
|
10 |
+
|
11 |
+
# %% auto 0
|
12 |
+
__all__ = ['learner', 'categories', 'classify_image']
|
13 |
+
|
14 |
+
# %% inference-face-crop-model.ipynb 10
|
15 |
+
from fastai.vision.all import *
|
16 |
import gradio as gr
|
17 |
|
18 |
+
learner = load_learner('./face-crop-model.pkl')
|
19 |
+
|
20 |
+
categories = ('happy', 'other')
|
21 |
+
|
22 |
+
def classify_image(img):
|
23 |
+
img = img["composite"]
|
24 |
+
# print(img.shape)
|
25 |
+
img = img[:,:, :3]
|
26 |
+
pred, idx, probs = learner.predict(img)
|
27 |
+
return dict(zip(categories, map(float, probs)))
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
|
31 |
+
image_edit = gr.ImageEditor(type="numpy", crop_size="1:1.2", canvas_size=(300, 300))
|
32 |
+
# image = gr.Image()
|
33 |
+
label = gr.Label()
|
34 |
+
examples = ['happy.png', "happy2.png", "happy3.png", "happy4.png", 'other.png', 'other2.png', 'other3.png', 'other4.png', 'other5.png',]
|
35 |
|
36 |
+
intf = gr.Interface(fn=classify_image, inputs=image_edit, outputs=label, examples=examples,
|
37 |
+
description="Use crop button to resize around the face for best results")
|
38 |
+
# intf.launch(inline=False)
|
39 |
demo.launch(share=True)
|
happy.png
ADDED
happy2.png
ADDED
happy3.png
ADDED
happy4.png
ADDED
happy5.png
ADDED
other.png
ADDED
other2.png
ADDED
other3.png
ADDED
other4.png
ADDED
other5.png
ADDED