jhj0517
commited on
Commit
•
dab3797
1
Parent(s):
8b2f0bf
Sign listeners to the app
Browse files
app.py
CHANGED
@@ -10,52 +10,56 @@ class App:
|
|
10 |
self.app = gr.Blocks()
|
11 |
self.inferencer = LivePortraitInferencer()
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def launch(self):
|
14 |
with self.app:
|
15 |
with gr.Row():
|
16 |
with gr.Column():
|
17 |
img_ref = gr.Image(label="Reference Image")
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
sld_eyebrow = gr.Slider(label="Eyebrow", minimum=-10, maximum=15, step=0.5, value=0)
|
26 |
-
sld_wink = gr.Slider(label="Wink", minimum=0, maximum=25, step=0.5, value=0)
|
27 |
-
sld_pupil_x = gr.Slider(label="Pupil X", minimum=-15, maximum=15, step=0.5, value=0)
|
28 |
-
sld_pupil_y = gr.Slider(label="Pupil Y", minimum=-15, maximum=15, step=0.5, value=0)
|
29 |
-
|
30 |
-
sld_aaa = gr.Slider(label="AAA", minimum=-30, maximum=120, step=1, value=0)
|
31 |
-
sld_eee = gr.Slider(label="EEE", minimum=-20, maximum=15, step=0.2, value=0)
|
32 |
-
sld_woo = gr.Slider(label="WOO", minimum=-20, maximum=15, step=0.2, value=0)
|
33 |
-
sld_smile = gr.Slider(label="Smile", minimum=-0.3, maximum=1.3, step=0.01, value=0)
|
34 |
-
|
35 |
-
sld_src_ratio = gr.Slider(label="Source Ratio", minimum=0, maximum=1, step=0.01, value=1)
|
36 |
-
sld_sample_ratio = gr.Slider(label="Sample Ratio", minimum=-0.2, maximum=1.2, step=0.01, value=1)
|
37 |
-
|
38 |
-
dd_sample_parts = gr.Dropdown(label="Sample Parts",
|
39 |
-
choices=["OnlyExpression", "OnlyRotation", "OnlyMouth", "OnlyEyes", "All"],
|
40 |
-
value="All")
|
41 |
-
sld_crop_factor = gr.Slider(label="Crop Factor", minimum=1.5, maximum=2.5, step=0.1,
|
42 |
-
value=1.7)
|
43 |
with gr.Accordion("Opt in features", visible=False):
|
44 |
img_sample = gr.Image()
|
45 |
img_motion_link = gr.Image()
|
46 |
tb_exp = gr.Textbox()
|
47 |
-
with gr.Row():
|
48 |
-
btn_gen = gr.Button("GEN")
|
49 |
-
with gr.Row():
|
50 |
-
img_out = gr.Image(label="Output Image")
|
51 |
|
52 |
-
params = [
|
53 |
-
sld_rotate_pitch, sld_rotate_yaw, sld_rotate_roll, sld_blink, sld_eyebrow, sld_wink, sld_pupil_x,
|
54 |
-
sld_pupil_y, sld_aaa, sld_eee, sld_woo, sld_smile, sld_src_ratio, sld_sample_ratio, dd_sample_parts,
|
55 |
-
sld_crop_factor, img_ref
|
56 |
-
]
|
57 |
opt_in_features_params = [img_sample, img_motion_link, tb_exp]
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
btn_gen.click(self.inferencer.edit_expression,
|
60 |
inputs=params + opt_in_features_params,
|
61 |
outputs=img_out)
|
|
|
10 |
self.app = gr.Blocks()
|
11 |
self.inferencer = LivePortraitInferencer()
|
12 |
|
13 |
+
@staticmethod
|
14 |
+
def create_parameters():
|
15 |
+
return [
|
16 |
+
gr.Slider(label="Rotate Pitch", minimum=-20, maximum=20, step=0.5, value=0),
|
17 |
+
gr.Slider(label="Rotate Yaw", minimum=-20, maximum=20, step=0.5, value=0),
|
18 |
+
gr.Slider(label="Rotate Roll", minimum=-20, maximum=20, step=0.5, value=0),
|
19 |
+
gr.Slider(label="Blink", minimum=-20, maximum=5, step=0.5, value=0),
|
20 |
+
gr.Slider(label="Eyebrow", minimum=-10, maximum=15, step=0.5, value=0),
|
21 |
+
gr.Slider(label="Wink", minimum=0, maximum=25, step=0.5, value=0),
|
22 |
+
gr.Slider(label="Pupil X", minimum=-15, maximum=15, step=0.5, value=0),
|
23 |
+
gr.Slider(label="Pupil Y", minimum=-15, maximum=15, step=0.5, value=0),
|
24 |
+
gr.Slider(label="AAA", minimum=-30, maximum=120, step=1, value=0),
|
25 |
+
gr.Slider(label="EEE", minimum=-20, maximum=15, step=0.2, value=0),
|
26 |
+
gr.Slider(label="WOO", minimum=-20, maximum=15, step=0.2, value=0),
|
27 |
+
gr.Slider(label="Smile", minimum=-0.3, maximum=1.3, step=0.01, value=0),
|
28 |
+
gr.Slider(label="Source Ratio", minimum=0, maximum=1, step=0.01, value=1),
|
29 |
+
gr.Slider(label="Sample Ratio", minimum=-0.2, maximum=1.2, step=0.01, value=1),
|
30 |
+
gr.Dropdown(label="Sample Parts",
|
31 |
+
choices=["OnlyExpression", "OnlyRotation", "OnlyMouth", "OnlyEyes", "All"], value="All"),
|
32 |
+
gr.Slider(label="Crop Factor", minimum=1.5, maximum=2.5, step=0.1, value=1.7)
|
33 |
+
]
|
34 |
+
|
35 |
def launch(self):
|
36 |
with self.app:
|
37 |
with gr.Row():
|
38 |
with gr.Column():
|
39 |
img_ref = gr.Image(label="Reference Image")
|
40 |
+
with gr.Row():
|
41 |
+
btn_gen = gr.Button("GENERATE", visible=False)
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column(scale=7):
|
44 |
+
img_out = gr.Image(label="Output Image")
|
45 |
+
with gr.Column(scale=3):
|
46 |
+
expression_parameters = self.create_parameters()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
with gr.Accordion("Opt in features", visible=False):
|
48 |
img_sample = gr.Image()
|
49 |
img_motion_link = gr.Image()
|
50 |
tb_exp = gr.Textbox()
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
params = expression_parameters + [img_ref]
|
|
|
|
|
|
|
|
|
53 |
opt_in_features_params = [img_sample, img_motion_link, tb_exp]
|
54 |
|
55 |
+
changes_expressions = [param.change for param in params]
|
56 |
+
gr.on(
|
57 |
+
triggers=changes_expressions,
|
58 |
+
fn=self.inferencer.edit_expression,
|
59 |
+
inputs=params + opt_in_features_params,
|
60 |
+
outputs=img_out
|
61 |
+
)
|
62 |
+
|
63 |
btn_gen.click(self.inferencer.edit_expression,
|
64 |
inputs=params + opt_in_features_params,
|
65 |
outputs=img_out)
|