Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,55 @@
|
|
| 1 |
-
import os
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
-
from src.gradio_demo import SadTalker
|
| 5 |
# from src.utils.text2speech import TTSTalker
|
| 6 |
from huggingface_hub import snapshot_download
|
| 7 |
|
| 8 |
-
def get_source_image(image):
|
| 9 |
-
|
| 10 |
|
|
|
|
| 11 |
try:
|
| 12 |
import webui # in webui
|
| 13 |
in_webui = True
|
| 14 |
except:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
def toggle_audio_file(choice):
|
| 19 |
if choice == False:
|
| 20 |
return gr.update(visible=True), gr.update(visible=False)
|
| 21 |
else:
|
| 22 |
return gr.update(visible=False), gr.update(visible=True)
|
| 23 |
-
|
| 24 |
def ref_video_fn(path_of_ref_video):
|
| 25 |
if path_of_ref_video is not None:
|
| 26 |
return gr.update(value=True)
|
| 27 |
else:
|
| 28 |
return gr.update(value=False)
|
| 29 |
-
|
| 30 |
def download_model():
|
| 31 |
REPO_ID = 'vinthony/SadTalker-V002rc'
|
| 32 |
snapshot_download(repo_id=REPO_ID, local_dir='./checkpoints', local_dir_use_symlinks=True)
|
| 33 |
|
| 34 |
def sadtalker_demo():
|
| 35 |
-
|
| 36 |
download_model()
|
| 37 |
-
|
| 38 |
sad_talker = SadTalker(lazy_load=True)
|
| 39 |
# tts_talker = TTSTalker()
|
| 40 |
|
| 41 |
with gr.Blocks(analytics_enabled=False) as sadtalker_interface:
|
| 42 |
gr.Markdown("<div align='center'> <h2> SadTalker: Learning Realistic 3D Motion Coefficients for Stylized Audio-Driven Single Image Talking Face Animation (CVPR 2023) </span> </h2> ")
|
| 43 |
-
|
| 44 |
-
|
| 45 |
gr.Markdown("""
|
| 46 |
<b>Business အတွက် သီးသန့် အသုံးပြုလိုပါက သီးသန့် Plan ဝယ်ယူပြီး အသုံးပြုနိုင်ပါတယ်)
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
with gr.Column(variant='panel'):
|
| 50 |
with gr.Tabs(elem_id="sadtalker_source_image"):
|
| 51 |
with gr.TabItem('Source image'):
|
| 52 |
with gr.Row():
|
| 53 |
-
source_image = gr.Image(label="Source image", source="upload", type="filepath", elem_id="img2img_image")
|
| 54 |
-
|
| 55 |
|
| 56 |
with gr.Tabs(elem_id="sadtalker_driven_audio"):
|
| 57 |
with gr.TabItem('Driving Methods'):
|
|
@@ -64,70 +62,65 @@ def sadtalker_demo():
|
|
| 64 |
with gr.Column():
|
| 65 |
use_idle_mode = gr.Checkbox(label="Use Idle Animation")
|
| 66 |
length_of_audio = gr.Number(value=5, label="The length(seconds) of the generated video.")
|
| 67 |
-
use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no])
|
| 68 |
|
| 69 |
with gr.Row():
|
| 70 |
-
ref_video = gr.Video(label="Reference Video", source="upload", type="filepath", elem_id="vidref")
|
| 71 |
|
| 72 |
with gr.Column():
|
| 73 |
use_ref_video = gr.Checkbox(label="Use Reference Video")
|
| 74 |
ref_info = gr.Radio(['pose', 'blink','pose+blink', 'all'], value='pose', label='Reference Video',info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
|
| 75 |
|
| 76 |
-
ref_video.change(ref_video_fn, inputs=ref_video, outputs=[use_ref_video])
|
| 77 |
-
|
| 78 |
|
| 79 |
-
with gr.Column(variant='panel'):
|
| 80 |
with gr.Tabs(elem_id="sadtalker_checkbox"):
|
| 81 |
with gr.TabItem('Settings'):
|
| 82 |
-
gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more
|
| 83 |
with gr.Column(variant='panel'):
|
| 84 |
-
# width = gr.Slider(minimum=64, elem_id="img2img_width", maximum=2048, step=8, label="Manually Crop Width", value=512) # img2img_width
|
| 85 |
-
# height = gr.Slider(minimum=64, elem_id="img2img_height", maximum=2048, step=8, label="Manually Crop Height", value=512) # img2img_width
|
| 86 |
with gr.Row():
|
| 87 |
-
pose_style = gr.Slider(minimum=0, maximum=45, step=1, label="Pose style", value=0)
|
| 88 |
-
exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="expression scale", value=1)
|
| 89 |
blink_every = gr.Checkbox(label="use eye blink", value=True)
|
| 90 |
|
| 91 |
with gr.Row():
|
| 92 |
-
size_of_image = gr.Radio([256, 512], value=256, label='face model resolution', info="use 256/512 model?")
|
| 93 |
preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
|
| 94 |
-
|
| 95 |
with gr.Row():
|
| 96 |
is_still_mode = gr.Checkbox(label="Still Mode (fewer head motion, works with preprocess `full`)")
|
| 97 |
facerender = gr.Radio(['facevid2vid','pirender'], value='facevid2vid', label='facerender', info="which face render?")
|
| 98 |
-
|
| 99 |
with gr.Row():
|
| 100 |
batch_size = gr.Slider(label="batch size in generation", step=1, maximum=10, value=1)
|
| 101 |
enhancer = gr.Checkbox(label="GFPGAN as Face enhancer")
|
| 102 |
-
|
| 103 |
submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
|
| 104 |
-
|
| 105 |
-
with gr.Tabs(elem_id="sadtalker_genearted"):
|
| 106 |
-
gen_video = gr.Video(label="Generated video", format="mp4", scale=1) # .style(width=256)
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
submit.click(
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
with gr.Row():
|
| 133 |
examples = [
|
|
@@ -201,18 +194,14 @@ def sadtalker_demo():
|
|
| 201 |
driven_audio,
|
| 202 |
preprocess_type,
|
| 203 |
is_still_mode,
|
| 204 |
-
enhancer],
|
| 205 |
outputs=[gen_video],
|
| 206 |
fn=sad_talker.test,
|
| 207 |
-
cache_examples=os.getenv('SYSTEM') == 'spaces')
|
| 208 |
|
| 209 |
return sadtalker_interface
|
| 210 |
-
|
| 211 |
|
| 212 |
if __name__ == "__main__":
|
| 213 |
-
|
| 214 |
demo = sadtalker_demo()
|
| 215 |
demo.queue(max_size=10, api_open=True)
|
| 216 |
demo.launch(debug=True)
|
| 217 |
-
|
| 218 |
-
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
import tempfile
|
| 4 |
import gradio as gr
|
| 5 |
+
from src.gradio_demo import SadTalker
|
| 6 |
# from src.utils.text2speech import TTSTalker
|
| 7 |
from huggingface_hub import snapshot_download
|
| 8 |
|
| 9 |
+
def get_source_image(image):
|
| 10 |
+
return image
|
| 11 |
|
| 12 |
+
in_webui = False
|
| 13 |
try:
|
| 14 |
import webui # in webui
|
| 15 |
in_webui = True
|
| 16 |
except:
|
| 17 |
+
pass
|
|
|
|
| 18 |
|
| 19 |
def toggle_audio_file(choice):
|
| 20 |
if choice == False:
|
| 21 |
return gr.update(visible=True), gr.update(visible=False)
|
| 22 |
else:
|
| 23 |
return gr.update(visible=False), gr.update(visible=True)
|
| 24 |
+
|
| 25 |
def ref_video_fn(path_of_ref_video):
|
| 26 |
if path_of_ref_video is not None:
|
| 27 |
return gr.update(value=True)
|
| 28 |
else:
|
| 29 |
return gr.update(value=False)
|
| 30 |
+
|
| 31 |
def download_model():
|
| 32 |
REPO_ID = 'vinthony/SadTalker-V002rc'
|
| 33 |
snapshot_download(repo_id=REPO_ID, local_dir='./checkpoints', local_dir_use_symlinks=True)
|
| 34 |
|
| 35 |
def sadtalker_demo():
|
|
|
|
| 36 |
download_model()
|
|
|
|
| 37 |
sad_talker = SadTalker(lazy_load=True)
|
| 38 |
# tts_talker = TTSTalker()
|
| 39 |
|
| 40 |
with gr.Blocks(analytics_enabled=False) as sadtalker_interface:
|
| 41 |
gr.Markdown("<div align='center'> <h2> SadTalker: Learning Realistic 3D Motion Coefficients for Stylized Audio-Driven Single Image Talking Face Animation (CVPR 2023) </span> </h2> ")
|
| 42 |
+
|
|
|
|
| 43 |
gr.Markdown("""
|
| 44 |
<b>Business အတွက် သီးသန့် အသုံးပြုလိုပါက သီးသန့် Plan ဝယ်ယူပြီး အသုံးပြုနိုင်ပါတယ်)
|
| 45 |
+
""")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
with gr.Column(variant='panel'):
|
| 49 |
with gr.Tabs(elem_id="sadtalker_source_image"):
|
| 50 |
with gr.TabItem('Source image'):
|
| 51 |
with gr.Row():
|
| 52 |
+
source_image = gr.Image(label="Source image", source="upload", type="filepath", elem_id="img2img_image")
|
|
|
|
| 53 |
|
| 54 |
with gr.Tabs(elem_id="sadtalker_driven_audio"):
|
| 55 |
with gr.TabItem('Driving Methods'):
|
|
|
|
| 62 |
with gr.Column():
|
| 63 |
use_idle_mode = gr.Checkbox(label="Use Idle Animation")
|
| 64 |
length_of_audio = gr.Number(value=5, label="The length(seconds) of the generated video.")
|
| 65 |
+
use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no])
|
| 66 |
|
| 67 |
with gr.Row():
|
| 68 |
+
ref_video = gr.Video(label="Reference Video", source="upload", type="filepath", elem_id="vidref")
|
| 69 |
|
| 70 |
with gr.Column():
|
| 71 |
use_ref_video = gr.Checkbox(label="Use Reference Video")
|
| 72 |
ref_info = gr.Radio(['pose', 'blink','pose+blink', 'all'], value='pose', label='Reference Video',info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
|
| 73 |
|
| 74 |
+
ref_video.change(ref_video_fn, inputs=ref_video, outputs=[use_ref_video])
|
|
|
|
| 75 |
|
| 76 |
+
with gr.Column(variant='panel'):
|
| 77 |
with gr.Tabs(elem_id="sadtalker_checkbox"):
|
| 78 |
with gr.TabItem('Settings'):
|
| 79 |
+
gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more details")
|
| 80 |
with gr.Column(variant='panel'):
|
|
|
|
|
|
|
| 81 |
with gr.Row():
|
| 82 |
+
pose_style = gr.Slider(minimum=0, maximum=45, step=1, label="Pose style", value=0)
|
| 83 |
+
exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="expression scale", value=1)
|
| 84 |
blink_every = gr.Checkbox(label="use eye blink", value=True)
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
+
size_of_image = gr.Radio([256, 512], value=256, label='face model resolution', info="use 256/512 model?")
|
| 88 |
preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
|
| 89 |
+
|
| 90 |
with gr.Row():
|
| 91 |
is_still_mode = gr.Checkbox(label="Still Mode (fewer head motion, works with preprocess `full`)")
|
| 92 |
facerender = gr.Radio(['facevid2vid','pirender'], value='facevid2vid', label='facerender', info="which face render?")
|
| 93 |
+
|
| 94 |
with gr.Row():
|
| 95 |
batch_size = gr.Slider(label="batch size in generation", step=1, maximum=10, value=1)
|
| 96 |
enhancer = gr.Checkbox(label="GFPGAN as Face enhancer")
|
| 97 |
+
|
| 98 |
submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
with gr.Tabs(elem_id="sadtalker_genearted"):
|
| 101 |
+
gen_video = gr.Video(label="Generated video", format="mp4", scale=1)
|
| 102 |
|
| 103 |
submit.click(
|
| 104 |
+
fn=sad_talker.test,
|
| 105 |
+
inputs=[source_image,
|
| 106 |
+
driven_audio,
|
| 107 |
+
preprocess_type,
|
| 108 |
+
is_still_mode,
|
| 109 |
+
enhancer,
|
| 110 |
+
batch_size,
|
| 111 |
+
size_of_image,
|
| 112 |
+
pose_style,
|
| 113 |
+
facerender,
|
| 114 |
+
exp_weight,
|
| 115 |
+
use_ref_video,
|
| 116 |
+
ref_video,
|
| 117 |
+
ref_info,
|
| 118 |
+
use_idle_mode,
|
| 119 |
+
length_of_audio,
|
| 120 |
+
blink_every
|
| 121 |
+
],
|
| 122 |
+
outputs=[gen_video],
|
| 123 |
+
)
|
| 124 |
|
| 125 |
with gr.Row():
|
| 126 |
examples = [
|
|
|
|
| 194 |
driven_audio,
|
| 195 |
preprocess_type,
|
| 196 |
is_still_mode,
|
| 197 |
+
enhancer],
|
| 198 |
outputs=[gen_video],
|
| 199 |
fn=sad_talker.test,
|
| 200 |
+
cache_examples=os.getenv('SYSTEM') == 'spaces')
|
| 201 |
|
| 202 |
return sadtalker_interface
|
|
|
|
| 203 |
|
| 204 |
if __name__ == "__main__":
|
|
|
|
| 205 |
demo = sadtalker_demo()
|
| 206 |
demo.queue(max_size=10, api_open=True)
|
| 207 |
demo.launch(debug=True)
|
|
|
|
|
|