Spaces:
Running
on
L40S
Running
on
L40S
UI refactored
Browse files
app.py
CHANGED
@@ -6,6 +6,9 @@ import os
|
|
6 |
|
7 |
from utils.gradio_helpers import parse_outputs, process_outputs
|
8 |
|
|
|
|
|
|
|
9 |
names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
|
10 |
|
11 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
@@ -62,111 +65,127 @@ with gr.Blocks() as demo:
|
|
62 |
type="filepath",
|
63 |
height=180
|
64 |
)
|
65 |
-
with gr.
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
)
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
submit_btn = gr.Button("Submit")
|
138 |
with gr.Column():
|
139 |
result_image = gr.Image(elem_id="top")
|
140 |
gr.HTML("""
|
141 |
-
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
142 |
<p style="display: flex;gap: 6px;">
|
143 |
<a href="https://huggingface.co/spaces/fffiloni/expression-editor?duplicate=true">
|
144 |
-
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-
|
145 |
-
</a>
|
146 |
</p>
|
|
|
147 |
</div>
|
148 |
""")
|
149 |
|
150 |
inputs = [image, rotate_pitch, rotate_yaw, rotate_roll, blink, eyebrow, wink, pupil_x, pupil_y, aaa, eee, woo, smile, src_ratio, sample_ratio, crop_factor, output_format, output_quality]
|
151 |
outputs = [result_image]
|
152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
submit_btn.click(
|
154 |
fn=predict,
|
155 |
inputs=inputs,
|
156 |
outputs=outputs,
|
|
|
157 |
)
|
158 |
|
159 |
-
rotate_pitch.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
160 |
-
rotate_yaw.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
161 |
-
rotate_roll.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
162 |
-
blink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
163 |
-
eyebrow.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
164 |
-
wink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
165 |
-
pupil_x.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
166 |
-
pupil_y.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
167 |
-
aaa.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
168 |
-
eee.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
169 |
-
woo.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
170 |
-
smile.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
|
171 |
|
172 |
demo.queue().launch(share=False, show_error=True)
|
|
|
6 |
|
7 |
from utils.gradio_helpers import parse_outputs, process_outputs
|
8 |
|
9 |
+
def display_uploaded_image(image_in):
|
10 |
+
return image_in
|
11 |
+
|
12 |
names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
|
13 |
|
14 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
|
|
65 |
type="filepath",
|
66 |
height=180
|
67 |
)
|
68 |
+
with gr.Tab("HEAD"):
|
69 |
+
with gr.Column():
|
70 |
+
rotate_pitch = gr.Slider(
|
71 |
+
label="Rotate Up-Down",
|
72 |
+
value=0,
|
73 |
+
minimum=-20, maximum=20
|
74 |
+
)
|
75 |
+
rotate_yaw = gr.Slider(
|
76 |
+
label="Rotate Left-Right turn",
|
77 |
+
value=0,
|
78 |
+
minimum=-20, maximum=20
|
79 |
+
)
|
80 |
+
rotate_roll = gr.Slider(
|
81 |
+
label="Rotate Left-Right tilt", value=0,
|
82 |
+
minimum=-20, maximum=20
|
83 |
+
)
|
84 |
+
with gr.Tab("EYES"):
|
85 |
+
with gr.Column():
|
86 |
+
eyebrow = gr.Slider(
|
87 |
+
label="Eyebrow", value=0,
|
88 |
+
minimum=-10, maximum=15
|
89 |
+
)
|
90 |
+
with gr.Row():
|
91 |
+
blink = gr.Slider(
|
92 |
+
label="Blink", value=0,
|
93 |
+
minimum=-20, maximum=5
|
94 |
+
)
|
95 |
+
|
96 |
+
wink = gr.Slider(
|
97 |
+
label="Wink", value=0,
|
98 |
+
minimum=0, maximum=25
|
99 |
+
)
|
100 |
+
with gr.Row():
|
101 |
+
pupil_x = gr.Slider(
|
102 |
+
label="Pupil X", value=0,
|
103 |
+
minimum=-15, maximum=15
|
104 |
+
)
|
105 |
+
pupil_y = gr.Slider(
|
106 |
+
label="Pupil Y", value=0,
|
107 |
+
minimum=-15, maximum=15
|
108 |
+
)
|
109 |
+
with gr.Tab("MOUTH"):
|
110 |
+
with gr.Column():
|
111 |
+
with gr.Row():
|
112 |
+
aaa = gr.Slider(
|
113 |
+
label="Aaa", value=0,
|
114 |
+
minimum=-30, maximum=120
|
115 |
+
)
|
116 |
+
eee = gr.Slider(
|
117 |
+
label="Eee", value=0,
|
118 |
+
minimum=-20, maximum=15
|
119 |
+
)
|
120 |
+
woo = gr.Slider(
|
121 |
+
label="Woo", value=0,
|
122 |
+
minimum=-20, maximum=15
|
123 |
+
)
|
124 |
+
smile = gr.Slider(
|
125 |
+
label="Smile", value=0,
|
126 |
+
minimum=-0.3, maximum=1.3
|
127 |
+
)
|
128 |
+
with gr.Tab("More Settings"):
|
129 |
+
with gr.Column():
|
130 |
+
src_ratio = gr.Number(
|
131 |
+
label="Src Ratio", info='''Source ratio''', value=1
|
132 |
+
)
|
133 |
+
sample_ratio = gr.Slider(
|
134 |
+
label="Sample Ratio", info='''Sample ratio''', value=1,
|
135 |
+
minimum=-0.2, maximum=1.2
|
136 |
+
)
|
137 |
+
crop_factor = gr.Slider(
|
138 |
+
label="Crop Factor", info='''Crop factor''', value=1.7,
|
139 |
+
minimum=1.5, maximum=2.5
|
140 |
+
)
|
141 |
+
output_format = gr.Dropdown(
|
142 |
+
choices=['webp', 'jpg', 'png'], label="output_format", info='''Format of the output images''', value="webp"
|
143 |
+
)
|
144 |
+
output_quality = gr.Number(
|
145 |
+
label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=95
|
146 |
+
)
|
147 |
submit_btn = gr.Button("Submit")
|
148 |
with gr.Column():
|
149 |
result_image = gr.Image(elem_id="top")
|
150 |
gr.HTML("""
|
151 |
+
<div style="display: flex; flex-direction: column;justify-content: center; align-items: center; text-align: center;">
|
152 |
<p style="display: flex;gap: 6px;">
|
153 |
<a href="https://huggingface.co/spaces/fffiloni/expression-editor?duplicate=true">
|
154 |
+
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg.svg" alt="Duplicate this Space">
|
155 |
+
</a>
|
156 |
</p>
|
157 |
+
<p>to skip the queue and enjoy faster inference on the GPU of your choice </p>
|
158 |
</div>
|
159 |
""")
|
160 |
|
161 |
inputs = [image, rotate_pitch, rotate_yaw, rotate_roll, blink, eyebrow, wink, pupil_x, pupil_y, aaa, eee, woo, smile, src_ratio, sample_ratio, crop_factor, output_format, output_quality]
|
162 |
outputs = [result_image]
|
163 |
|
164 |
+
image.upload(
|
165 |
+
fn = display_uploaded_image,
|
166 |
+
inputs = [image],
|
167 |
+
outputs = [result_image],
|
168 |
+
queue = False
|
169 |
+
)
|
170 |
+
|
171 |
submit_btn.click(
|
172 |
fn=predict,
|
173 |
inputs=inputs,
|
174 |
outputs=outputs,
|
175 |
+
concurrency_limit=4
|
176 |
)
|
177 |
|
178 |
+
rotate_pitch.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
179 |
+
rotate_yaw.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
180 |
+
rotate_roll.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
181 |
+
blink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
182 |
+
eyebrow.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
183 |
+
wink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
184 |
+
pupil_x.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
185 |
+
pupil_y.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
186 |
+
aaa.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
187 |
+
eee.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
188 |
+
woo.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
189 |
+
smile.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
|
190 |
|
191 |
demo.queue().launch(share=False, show_error=True)
|