Spaces:
Running
Running
Upload 5 files
Browse files- README.md +13 -14
- app.py +205 -215
- packages.txt +1 -2
- pre-requirements.txt +1 -0
- requirements.txt +20 -19
README.md
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
-
---
|
2 |
-
title: SadTalker (Gradio 4.x)
|
3 |
-
emoji: 😭
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: green
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
---
|
2 |
+
title: SadTalker (Gradio 4.x, latest PyTorch)
|
3 |
+
emoji: 😭
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.42.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
app.py
CHANGED
@@ -1,216 +1,206 @@
|
|
1 |
-
import spaces
|
2 |
-
import os, 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 |
-
try:
|
13 |
-
import webui # in webui
|
14 |
-
in_webui = True
|
15 |
-
except:
|
16 |
-
in_webui = False
|
17 |
-
|
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 |
-
|
37 |
-
download_model()
|
38 |
-
|
39 |
-
sad_talker = SadTalker(lazy_load=True)
|
40 |
-
# tts_talker = TTSTalker()
|
41 |
-
|
42 |
-
with gr.Blocks(analytics_enabled=False, theme="Hev832/Applio") as sadtalker_interface:
|
43 |
-
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> \
|
44 |
-
<a style='font-size:18px;color: #efefef' href='https://arxiv.org/abs/2211.12194'>Arxiv</a> \
|
45 |
-
<a style='font-size:18px;color: #efefef' href='https://sadtalker.github.io'>Homepage</a> \
|
46 |
-
<a style='font-size:18px;color: #efefef' href='https://github.com/Winfredy/SadTalker'> Github </div>")
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
<b>
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
use_idle_mode =
|
69 |
-
|
70 |
-
|
71 |
-
with gr.
|
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 |
-
return sadtalker_interface
|
209 |
-
|
210 |
-
|
211 |
-
if __name__ == "__main__":
|
212 |
-
demo = sadtalker_demo()
|
213 |
-
demo.queue()
|
214 |
-
demo.launch()
|
215 |
-
#demo.queue(max_size=10, api_open=True)
|
216 |
#demo.launch(debug=True)
|
|
|
1 |
+
import spaces
|
2 |
+
import os, 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 |
+
try:
|
13 |
+
import webui # in webui
|
14 |
+
in_webui = True
|
15 |
+
except:
|
16 |
+
in_webui = False
|
17 |
+
|
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 |
+
|
37 |
+
download_model()
|
38 |
+
|
39 |
+
sad_talker = SadTalker(lazy_load=True)
|
40 |
+
# tts_talker = TTSTalker()
|
41 |
+
|
42 |
+
with gr.Blocks(analytics_enabled=False, theme="Hev832/Applio") as sadtalker_interface:
|
43 |
+
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> \
|
44 |
+
<a style='font-size:18px;color: #efefef' href='https://arxiv.org/abs/2211.12194'>Arxiv</a> \
|
45 |
+
<a style='font-size:18px;color: #efefef' href='https://sadtalker.github.io'>Homepage</a> \
|
46 |
+
<a style='font-size:18px;color: #efefef' href='https://github.com/Winfredy/SadTalker'> Github </div>")
|
47 |
+
|
48 |
+
gr.Markdown("""
|
49 |
+
<b>You may duplicate the space and upgrade to GPU in settings for better performance and faster inference without waiting in the queue. <a style='display:inline-block' href="https://huggingface.co/spaces/vinthony/SadTalker?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a></b> \
|
50 |
+
<br/><b>Alternatively, try our GitHub <a href=https://github.com/Winfredy/SadTalker> code </a> on your own GPU. </b> <a style='display:inline-block' href="https://github.com/Winfredy/SadTalker"><img src="https://img.shields.io/github/stars/Winfredy/SadTalker?style=social"/></a> \
|
51 |
+
""")
|
52 |
+
|
53 |
+
with gr.Row():
|
54 |
+
with gr.Column(variant='panel'):
|
55 |
+
with gr.Tabs(elem_id="sadtalker_source_image"):
|
56 |
+
with gr.TabItem('Source image'):
|
57 |
+
with gr.Row():
|
58 |
+
source_image = gr.Image(label="Source image", type="filepath", elem_id="img2img_image")
|
59 |
+
|
60 |
+
with gr.TabItem('Driving Methods',elem_id="sadtalker_driven_audio"):
|
61 |
+
gr.Markdown("Possible driving combinations: <br> 1. Audio only 2. Audio/IDLE Mode + Ref Video(pose, blink, pose+blink) 3. IDLE Mode only 4. Ref Video only (all) ")
|
62 |
+
with gr.Row():
|
63 |
+
driven_audio = gr.Audio(label="Input audio", type="filepath")
|
64 |
+
driven_audio_no = gr.Audio(label="Use IDLE mode, no audio is required", type="filepath", visible=False)
|
65 |
+
with gr.Column():
|
66 |
+
use_idle_mode = gr.Checkbox(label="Use Idle Animation")
|
67 |
+
length_of_audio = gr.Number(value=5, label="The length(seconds) of the generated video.")
|
68 |
+
use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no]) # todo
|
69 |
+
with gr.Row():
|
70 |
+
ref_video = gr.Video(label="Reference Video", elem_id="vidref")
|
71 |
+
with gr.Column():
|
72 |
+
use_ref_video = gr.Checkbox(label="Use Reference Video")
|
73 |
+
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))")
|
74 |
+
ref_video.change(ref_video_fn, inputs=ref_video, outputs=[use_ref_video]) # todo
|
75 |
+
|
76 |
+
with gr.TabItem('Settings',elem_id="sadtalker_checkbox"):
|
77 |
+
gr.Markdown("need help? please visit our [[best practice page](https://github.com/OpenTalker/SadTalker/blob/main/docs/best_practice.md)] for more detials")
|
78 |
+
with gr.Column(variant='panel'):
|
79 |
+
with gr.Row():
|
80 |
+
pose_style = gr.Slider(minimum=0, maximum=45, step=1, label="Pose style", value=0) #
|
81 |
+
exp_weight = gr.Slider(minimum=0, maximum=3, step=0.1, label="expression scale", value=1) #
|
82 |
+
blink_every = gr.Checkbox(label="use eye blink", value=True)
|
83 |
+
with gr.Row():
|
84 |
+
size_of_image = gr.Radio([256, 512], value=256, label='face model resolution', info="use 256/512 model?") #
|
85 |
+
preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
|
86 |
+
with gr.Row():
|
87 |
+
is_still_mode = gr.Checkbox(label="Still Mode (fewer head motion, works with preprocess `full`)")
|
88 |
+
facerender = gr.Radio(['facevid2vid','pirender'], value='facevid2vid', label='facerender', info="which face render?")
|
89 |
+
with gr.Row():
|
90 |
+
batch_size = gr.Slider(label="batch size in generation", step=1, maximum=10, value=1)
|
91 |
+
enhancer = gr.Checkbox(label="GFPGAN as Face enhancer")
|
92 |
+
|
93 |
+
submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
|
94 |
+
|
95 |
+
with gr.Tabs(elem_id="sadtalker_genearted"):
|
96 |
+
gen_video = gr.Video(label="Generated video", format="mp4")
|
97 |
+
|
98 |
+
submit.click(
|
99 |
+
fn=sad_talker.test,
|
100 |
+
inputs=[source_image,
|
101 |
+
driven_audio,
|
102 |
+
preprocess_type,
|
103 |
+
is_still_mode,
|
104 |
+
enhancer,
|
105 |
+
batch_size,
|
106 |
+
size_of_image,
|
107 |
+
pose_style,
|
108 |
+
facerender,
|
109 |
+
exp_weight,
|
110 |
+
use_ref_video,
|
111 |
+
ref_video,
|
112 |
+
ref_info,
|
113 |
+
use_idle_mode,
|
114 |
+
length_of_audio,
|
115 |
+
blink_every
|
116 |
+
],
|
117 |
+
outputs=[gen_video],
|
118 |
+
)
|
119 |
+
|
120 |
+
with gr.Row():
|
121 |
+
examples = [
|
122 |
+
[
|
123 |
+
'examples/source_image/full_body_1.png',
|
124 |
+
'examples/driven_audio/bus_chinese.wav',
|
125 |
+
'crop',
|
126 |
+
True,
|
127 |
+
False
|
128 |
+
],
|
129 |
+
[
|
130 |
+
'examples/source_image/full_body_2.png',
|
131 |
+
'examples/driven_audio/japanese.wav',
|
132 |
+
'crop',
|
133 |
+
False,
|
134 |
+
False
|
135 |
+
],
|
136 |
+
[
|
137 |
+
'examples/source_image/full3.png',
|
138 |
+
'examples/driven_audio/deyu.wav',
|
139 |
+
'crop',
|
140 |
+
False,
|
141 |
+
True
|
142 |
+
],
|
143 |
+
[
|
144 |
+
'examples/source_image/full4.jpeg',
|
145 |
+
'examples/driven_audio/eluosi.wav',
|
146 |
+
'full',
|
147 |
+
False,
|
148 |
+
True
|
149 |
+
],
|
150 |
+
[
|
151 |
+
'examples/source_image/full4.jpeg',
|
152 |
+
'examples/driven_audio/imagine.wav',
|
153 |
+
'full',
|
154 |
+
True,
|
155 |
+
True
|
156 |
+
],
|
157 |
+
[
|
158 |
+
'examples/source_image/full_body_1.png',
|
159 |
+
'examples/driven_audio/bus_chinese.wav',
|
160 |
+
'full',
|
161 |
+
True,
|
162 |
+
False
|
163 |
+
],
|
164 |
+
[
|
165 |
+
'examples/source_image/art_13.png',
|
166 |
+
'examples/driven_audio/fayu.wav',
|
167 |
+
'resize',
|
168 |
+
True,
|
169 |
+
False
|
170 |
+
],
|
171 |
+
[
|
172 |
+
'examples/source_image/art_5.png',
|
173 |
+
'examples/driven_audio/chinese_news.wav',
|
174 |
+
'resize',
|
175 |
+
False,
|
176 |
+
False
|
177 |
+
],
|
178 |
+
[
|
179 |
+
'examples/source_image/art_5.png',
|
180 |
+
'examples/driven_audio/RD_Radio31_000.wav',
|
181 |
+
'resize',
|
182 |
+
True,
|
183 |
+
True
|
184 |
+
],
|
185 |
+
]
|
186 |
+
gr.Examples(examples=examples,
|
187 |
+
inputs=[
|
188 |
+
source_image,
|
189 |
+
driven_audio,
|
190 |
+
preprocess_type,
|
191 |
+
is_still_mode,
|
192 |
+
enhancer],
|
193 |
+
outputs=[gen_video],
|
194 |
+
fn=sad_talker.test,
|
195 |
+
cache_examples=False
|
196 |
+
#cache_examples=os.getenv('SYSTEM') == 'spaces'
|
197 |
+
) #
|
198 |
+
|
199 |
+
return sadtalker_interface
|
200 |
+
|
201 |
+
if __name__ == "__main__":
|
202 |
+
demo = sadtalker_demo()
|
203 |
+
demo.queue()
|
204 |
+
demo.launch()
|
205 |
+
#demo.queue(max_size=10, api_open=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
#demo.launch(debug=True)
|
packages.txt
CHANGED
@@ -1,2 +1 @@
|
|
1 |
-
ffmpeg
|
2 |
-
libsndfile1
|
|
|
1 |
+
ffmpeg libsndfile1
|
|
pre-requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pip>=23.0.0
|
requirements.txt
CHANGED
@@ -1,24 +1,25 @@
|
|
1 |
-
torch
|
2 |
-
torchvision
|
3 |
-
torchaudio
|
4 |
-
numpy
|
5 |
-
face_alignment
|
6 |
-
imageio
|
7 |
-
imageio-ffmpeg
|
8 |
-
librosa
|
9 |
-
numba
|
10 |
-
resampy
|
11 |
-
pydub
|
12 |
scipy
|
13 |
-
kornia
|
14 |
tqdm
|
15 |
-
yacs
|
16 |
pyyaml
|
17 |
-
joblib
|
18 |
-
scikit-image
|
19 |
-
|
20 |
-
|
|
|
21 |
dlib-bin
|
22 |
-
gfpgan
|
23 |
av
|
24 |
-
safetensors
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
+
torchaudio
|
4 |
+
numpy
|
5 |
+
face_alignment
|
6 |
+
imageio
|
7 |
+
imageio-ffmpeg
|
8 |
+
librosa
|
9 |
+
numba
|
10 |
+
resampy
|
11 |
+
pydub
|
12 |
scipy
|
13 |
+
kornia
|
14 |
tqdm
|
15 |
+
yacs
|
16 |
pyyaml
|
17 |
+
joblib
|
18 |
+
scikit-image
|
19 |
+
git+https://github.com/XPixelGroup/BasicSR
|
20 |
+
git+https://github.com/TencentARC/GFPGAN
|
21 |
+
facexlib
|
22 |
dlib-bin
|
|
|
23 |
av
|
24 |
+
safetensors
|
25 |
+
TTS
|