-
Notifications
You must be signed in to change notification settings - Fork 15
/
launch.py
416 lines (369 loc) · 20.7 KB
/
launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# This file is a part of https://github.com/pawansharmaaaa/Lip_Wise/ repository.
import argparse
import gradio as gr
# Custom Modules
import infer
from helpers import file_check
# Argument parser
parser = argparse.ArgumentParser(description="Your description here")
parser.add_argument("--colab", action="store_true", help="Use when running inference from Google Colab")
args = parser.parse_args()
bg_upscalers = list(file_check.REAL_ESRGAN_MODEL_URL.keys())
# Theme
theme = gr.themes.Base(
primary_hue=gr.themes.Color(c100="#efe7ff",
c200="#decefe",
c300="#ccb7fd",
c400="#ba9ffc",
c50="#ffffff",
c500="#a688fa",
c600="#836bc3",
c700="#61508e",
c800="#41365d",
c900="#241e30",
c950="#25242a"),
secondary_hue=gr.themes.Color(c100="#e2e1e4",
c200="#c6c5c9",
c300="#aba9b0",
c400="#908d96",
c50="#ffffff",
c500="#76737e",
c600="#5e5b64",
c700="#46444b",
c800="#302f33",
c900="#1b1b1d",
c950="#25242a"),
neutral_hue=gr.themes.Color(c100="#e1e1e1",
c200="#c4c4c4",
c300="#a7a7a7",
c400="#8c8c8c",
c50="#ffffff",
c500="#717171",
c600="#5a5a5a",
c700="#434343",
c800="#2e2e2e",
c900="#25242a",
c950="#1b1b1b"),
spacing_size="md",
radius_size="lg",
).set(
shadow_drop='*shadow_inset',
shadow_drop_lg='*button_shadow_hover',
block_info_text_size='md',
block_info_text_weight='800',
block_info_text_color_dark="#C494ACFF",
block_title_text_color_dark="#FFFFFFFF",
slider_color_dark="#B12805FF",
panel_border_color_dark="#B12805FF",
loader_color_dark="#C494ACFF",
# body_background_fill="radial-gradient( circle farthest-corner at -4% -12.9%, rgba(255,255,255,1) 0.3%, rgba(255,255,255,1) 90.2% );",
# body_background_fill_dark= "linear-gradient(315deg, #0cbaba 0%, #380036 74%);"
)
head_html = f'''
<head class>
<meta author="Pawan Sharma">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
'''
def render_dd(bg_upscale):
return gr.Dropdown(
choices=bg_upscalers,
label="REALESRGAN Model",
value="RealESRGAN_x2plus",
info="Choose the model to use for upscaling the background.",
visible=bg_upscale
)
def render_weight(face_restorer):
if face_restorer == "CodeFormer":
return gr.Slider(
minimum=0.0,
maximum=1.0,
step=0.1,
value=0.6,
label="CodeFormer Weight",
info="0 for better quality, 1 for better identity.",
visible=True,
scale=2,
elem_classes=["option"]
)
elif face_restorer == "GFPGAN":
return gr.Slider(
minimum=0.0,
maximum=1.0,
step=0.1,
value=0.5,
label="GFPGAN Weight",
info="0 for better identity, 1 for better quality.",
visible=True,
scale=2,
elem_classes=["option"]
)
elif face_restorer == "RestoreFormer":
return gr.Slider(
minimum=0.0,
maximum=1.0,
step=0.1,
value=0.5,
label="RestoreFormer Weight",
info="0 for better identity, 1 for better quality.",
visible=True,
scale=2,
elem_classes=["option"]
)
elif face_restorer == "None":
return gr.Slider(
minimum=0.0,
maximum=1.0,
step=0.1,
value=0.5,
label="None Weight",
info="0 for better identity, 1 for better quality.",
visible=False
)
# Create interface
with gr.Blocks(title='Lip-Wise', theme=theme, css = file_check.CSS_FILE_PATH) as ui:
with gr.Row(elem_classes=["row"]):
gr.HTML(
'''
<header>
<div class="header-left">
<h1>Lip Wise</h1>
<h2>Wise Enhancements for Wav2Lip</h2>
</div>
<div class="header-right">
<img src="https://github.com/pawansharmaaaa/Lip_Wise/assets/56242483/5bc1b8af-879a-414b-b54a-db605a53c8f7" alt="Logo">
</div>
</header>
'''
)
with gr.Tab(label="Process Image", elem_id="tab", elem_classes=["tabs"]):
with gr.Row(elem_classes=["row"]):
with gr.Column():
# gr.Markdown("# INPUTS")
with gr.Accordion(label="Input Image and Audio", open=True, elem_classes=["inp_group", "accordion"]):
image_input = gr.Image(type="filepath",
label="Image",
container=True)
audio_input = gr.Audio(type="filepath",
label="Audio",
container=True)
with gr.Column():
# gr.Markdown("# OUTPUT")
with gr.Column(scale=2):
image_output = gr.Video(sources='upload',
label="Output",
elem_classes=["output"],
container=True)
with gr.Column(scale=3):
gr.HTML(
'''
<div class="separator"></div>
''')
with gr.Column(variant="panel", scale=2):
process = gr.Button(value="Process Image",
variant="primary",
elem_id="gen-button")
clear = gr.ClearButton([image_input, audio_input, image_output],
value="Clear",
variant="secondary",
elem_id="clear-button")
with gr.Accordion(label="OPTIONS", open=True, elem_classes=["opt_group", "accordion"]):
with gr.Group():
with gr.Column(variant="panel"):
with gr.Row():
gan = gr.Checkbox(label = "Use Wav2Lip_GAN?",
value=False,
info="This will use Wav2Lip_GAN instead of Wav2Lip. May get better results in some cases",
interactive=True,
elem_classes=["option"])
alignment = gr.Checkbox(label = "Perform 3D_alignment",
info = "This will improve the quality of the lip sync, but the output will be different from the original video.",
elem_classes=["option"])
with gr.Row():
fps = gr.Slider(minimum=1,
maximum=60,
step=1,
value=25,
label="FPS",
info="Desired Frames per second (FPS) of the output video.",
elem_classes=["option"])
padding = gr.Slider(minimum=0,
maximum=60,
step=1,
value=0,
label="Padding",
info="Increase if getting black outlines. The Value is in Pixels.",
elem_classes=["option"])
with gr.Column(variant="panel"):
with gr.Row():
face_restorer = gr.Radio(["GFPGAN", "CodeFormer", "RestoreFormer", "None"],
value='CodeFormer',
label="Face Restorer",
info="GFPGAN is faster, but CodeFormer is more accurate.", # Needs Change
interactive=True,
elem_classes=["option"])
weight = gr.Slider(minimum=0.0,
maximum=1.0,
step=0.1,
value=0.6,
label="CodeFormer Weight",
info="0 for better quality, 1 for better identity.",
scale=2,
elem_classes=["option"])
with gr.Row():
upscale_bg = gr.Checkbox(label = "Upscale Background with REALESRGAN",
value=False,
info="This will improve the quality of the video, but will take longer to process.",
elem_classes=["option"])
bg_model = gr.Dropdown(choices=bg_upscalers,
label="REALESRGAN Model",
value="RealESRGAN_x2plus",
info="Choose the model to use for upscaling the background.",
visible=False,
scale=2,
elem_classes=["option"])
mel_step_size = gr.Number(value=16,
label="Mel Step Size",
interactive=False,
visible=False,
elem_classes=["option"])
# Event Triggers
upscale_bg.select(render_dd,
upscale_bg,
bg_model)
face_restorer.select(render_weight,
face_restorer,
weight)
process.click(infer.infer_image,
[image_input, audio_input, padding, alignment, face_restorer, fps, mel_step_size, weight, upscale_bg, bg_model, gan],
[image_output],
show_progress="full",
trigger_mode="once")
with gr.Tab(label="Process Video", elem_id="tab", elem_classes=["tabs"]):
with gr.Row(elem_classes=["row"]):
with gr.Column():
# gr.Markdown("# INPUTS")
with gr.Accordion("Input Video and Audio", open=True, elem_classes=["inp_group", "accordion"]):
video_input = gr.Video(sources='upload',
label="Video")
audio_input = gr.Audio(type="filepath",
label="Audio")
with gr.Column():
# gr.Markdown("# OUTPUT")
with gr.Column(scale=2):
video_output = gr.Video(sources='upload',
label="Output",
elem_classes=["output"],
container=True)
with gr.Column(scale=3):
gr.HTML(
'''
<div class="separator"></div>
''')
with gr.Column(variant="panel"):
process = gr.Button(value="Process Video",
variant="primary",
elem_id="gen-button")
clear = gr.ClearButton([video_input, audio_input, video_output],
value="Clear",
variant="secondary",
elem_id="clear-button")
with gr.Accordion(label="OPTIONS", open=True, elem_classes=["opt_group", "accordion"]):
with gr.Group():
with gr.Column():
with gr.Row():
gan = gr.Checkbox(label = "Use Wav2Lip_GAN",
value=False,
info="This will use Wav2Lip_GAN instead of Wav2Lip. May get better results in some cases",
interactive=True)
loop = gr.Checkbox(label = "Loop Video",
value=False,
info="This will loop the video to the length of the audio file.",
interactive=True)
padding = gr.Slider(minimum=0,
maximum=60,
step=1,
value=0,
label="Padding",
info="Increase if getting black outlines. The Value is in Pixels.")
with gr.Column():
with gr.Row():
face_restorer = gr.Radio(["GFPGAN", "CodeFormer", "RestoreFormer", "None"],
value='CodeFormer',
label="Face Restorer",
info="GFPGAN is faster, but CodeFormer is more accurate.")
mel_step_size = gr.Number(value=16,
label="Mel Step Size",
interactive=False,
visible=False)
weight = gr.Slider(minimum=0.0,
maximum=1.0,
step=0.1,
value=0.6,
label="CodeFormer Weight",
info="0 for better quality, 1 for better identity.",
scale=2)
with gr.Row():
upscale_bg = gr.Checkbox(label = "Upscale Background with REALESRGAN",
value=False,
info="This will improve the quality of the video, but will take longer to process.")
bg_model = gr.Dropdown(choices=bg_upscalers,
label="REALESRGAN Model",
value="RealESRGAN_x2plus",
info="Choose the model to use for upscaling the background.",
visible=False,
scale=2)
# Event Triggers
upscale_bg.select(render_dd, upscale_bg, bg_model)
face_restorer.select(render_weight, face_restorer, weight)
process.click(infer.infer_video,
[video_input, audio_input, padding, face_restorer, mel_step_size, weight, upscale_bg, bg_model, gan, loop],
[video_output],
trigger_mode="once",
show_progress="full")
with gr.Tab(label="Guide", elem_id="tab", elem_classes=["tabs"]):
with gr.Accordion(label="Tips For Better Results", open=True, elem_classes=["guide"]):
gr.Markdown(
"""
> - Optimal performance is achieved with a **clear image** featuring a person facing the camera, regardless of head angle. However, avoid **tilting in the z-direction** (3D-alignment can address this with certain considerations).
> - Ensure the image contains only **one person** with a prominently visible face.
> - Clear audio devoid of background noise enhances results significantly.
> - Note that **higher image resolution** necessitates **additional processing time**.
""",
line_breaks=True)
with gr.Accordion(label="Model Selection", open=True, elem_classes=["guide"]):
gr.Markdown(
"""
> ##### **CODEFORMER:**
>**Recommended Weight:** `0 for better quality, 1 for better identity.`
>>- CodeFormer employs a transformative architecture to restore facial features.
>>- While relatively slower, it boasts **higher accuracy**.
>>- Generally delivers superior results while **preserving skin texture**.
>>- In cases of peculiar artifacts, especially around the nose, consider using GFPGAN.
> ##### **GFPGAN:**
>**Recommended Weight:** `0 for better identity, 1 for better quality.`
>>- GFPGAN, a faster model, relies on a GAN-based framework for facial restoration.
>>- Suggested for use **when CodeFormer exhibits undesirable artifacts**.
>>- However, it often sacrifices skin texture fidelity.
""",
line_breaks=True)
with gr.Accordion(label="3D Alignment", open=True, elem_classes=["guide"]):
gr.Markdown(
"""
> Enabling this feature **transforms** the image to ensure the person faces the camera directly. While enhancing lip sync quality, the output may diverge from the original video.
""",
line_breaks=True)
with gr.Accordion(label="Background Upscaling", open=True, elem_classes=["guide"]):
gr.Markdown(
"""
> - Activating this feature **enhances video quality** but prolongs processing time.
> - For most scenarios, RealESRGAN_x2plus is preferable due to its comparative speed.
> - Optimal results are achieved when combined with CodeFormer, except in cases of nose-related artifacts.
> - This feature effectively **eliminates video flickering**.
""",
line_breaks=True)
if args.colab:
ui.queue().launch(share=True)
else:
ui.queue().launch()