abreza commited on
Commit
8f6558d
1 Parent(s): 01445d3
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +18 -1
  2. .gitignore +159 -0
  3. Dockerfile +59 -0
  4. LICENSE +21 -0
  5. README.md +7 -5
  6. app.py +382 -0
  7. docs/sadtalker_logo.png +0 -0
  8. examples/.DS_Store +0 -0
  9. examples/driven_audio/RD_Radio31_000.wav +0 -0
  10. examples/driven_audio/RD_Radio34_002.wav +0 -0
  11. examples/driven_audio/RD_Radio36_000.wav +0 -0
  12. examples/driven_audio/RD_Radio40_000.wav +0 -0
  13. examples/driven_audio/bus_chinese.wav +0 -0
  14. examples/driven_audio/chinese_news.wav +3 -0
  15. examples/driven_audio/chinese_poem1.wav +0 -0
  16. examples/driven_audio/chinese_poem2.wav +0 -0
  17. examples/driven_audio/deyu.wav +3 -0
  18. examples/driven_audio/eluosi.wav +3 -0
  19. examples/driven_audio/fayu.wav +3 -0
  20. examples/driven_audio/imagine.wav +3 -0
  21. examples/driven_audio/itosinger1.wav +0 -0
  22. examples/driven_audio/japanese.wav +3 -0
  23. examples/source_image/art_0.png +0 -0
  24. examples/source_image/art_1.png +0 -0
  25. examples/source_image/art_10.png +0 -0
  26. examples/source_image/art_11.png +0 -0
  27. examples/source_image/art_12.png +0 -0
  28. examples/source_image/art_13.png +0 -0
  29. examples/source_image/art_14.png +0 -0
  30. examples/source_image/art_15.png +0 -0
  31. examples/source_image/art_16.png +3 -0
  32. examples/source_image/art_17.png +3 -0
  33. examples/source_image/art_18.png +0 -0
  34. examples/source_image/art_19.png +0 -0
  35. examples/source_image/art_2.png +0 -0
  36. examples/source_image/art_20.png +0 -0
  37. examples/source_image/art_3.png +3 -0
  38. examples/source_image/art_4.png +3 -0
  39. examples/source_image/art_5.png +3 -0
  40. examples/source_image/art_6.png +0 -0
  41. examples/source_image/art_7.png +0 -0
  42. examples/source_image/art_8.png +3 -0
  43. examples/source_image/art_9.png +3 -0
  44. examples/source_image/full3.png +0 -0
  45. examples/source_image/full4.jpeg +0 -0
  46. examples/source_image/full_body_1.png +0 -0
  47. examples/source_image/full_body_2.png +0 -0
  48. examples/source_image/happy.png +0 -0
  49. examples/source_image/happy1.png +0 -0
  50. examples/source_image/people_0.png +0 -0
.gitattributes CHANGED
@@ -25,7 +25,6 @@
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
@@ -33,3 +32,21 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
28
  *.tflite filter=lfs diff=lfs merge=lfs -text
29
  *.tgz filter=lfs diff=lfs merge=lfs -text
30
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ checkpoints/BFM_Fitting/01_MorphableModel.mat filter=lfs diff=lfs merge=lfs -text
36
+ checkpoints/BFM_Fitting/BFM09_model_info.mat filter=lfs diff=lfs merge=lfs -text
37
+ checkpoints/facevid2vid_00189-model.pth.tar filter=lfs diff=lfs merge=lfs -text
38
+ checkpoints/mapping_00229-model.pth.tar filter=lfs diff=lfs merge=lfs -text
39
+ checkpoints/shape_predictor_68_face_landmarks.dat filter=lfs diff=lfs merge=lfs -text
40
+ examples/driven_audio/chinese_news.wav filter=lfs diff=lfs merge=lfs -text
41
+ examples/driven_audio/deyu.wav filter=lfs diff=lfs merge=lfs -text
42
+ examples/driven_audio/eluosi.wav filter=lfs diff=lfs merge=lfs -text
43
+ examples/driven_audio/fayu.wav filter=lfs diff=lfs merge=lfs -text
44
+ examples/driven_audio/imagine.wav filter=lfs diff=lfs merge=lfs -text
45
+ examples/driven_audio/japanese.wav filter=lfs diff=lfs merge=lfs -text
46
+ examples/source_image/art_16.png filter=lfs diff=lfs merge=lfs -text
47
+ examples/source_image/art_17.png filter=lfs diff=lfs merge=lfs -text
48
+ examples/source_image/art_3.png filter=lfs diff=lfs merge=lfs -text
49
+ examples/source_image/art_4.png filter=lfs diff=lfs merge=lfs -text
50
+ examples/source_image/art_5.png filter=lfs diff=lfs merge=lfs -text
51
+ examples/source_image/art_8.png filter=lfs diff=lfs merge=lfs -text
52
+ examples/source_image/art_9.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ results/
156
+ checkpoints/
157
+ gradio_cached_examples/
158
+ gfpgan/
159
+ start.sh
Dockerfile ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04
2
+ ENV DEBIAN_FRONTEND=noninteractive
3
+ RUN apt-get update && \
4
+ apt-get upgrade -y && \
5
+ apt-get install -y --no-install-recommends \
6
+ git \
7
+ zip \
8
+ unzip \
9
+ git-lfs \
10
+ wget \
11
+ curl \
12
+ # ffmpeg \
13
+ ffmpeg \
14
+ x264 \
15
+ # python build dependencies \
16
+ build-essential \
17
+ libssl-dev \
18
+ zlib1g-dev \
19
+ libbz2-dev \
20
+ libreadline-dev \
21
+ libsqlite3-dev \
22
+ libncursesw5-dev \
23
+ xz-utils \
24
+ tk-dev \
25
+ libxml2-dev \
26
+ libxmlsec1-dev \
27
+ libffi-dev \
28
+ liblzma-dev && \
29
+ apt-get clean && \
30
+ rm -rf /var/lib/apt/lists/*
31
+
32
+ RUN useradd -m -u 1000 user
33
+ USER user
34
+ ENV HOME=/home/user \
35
+ PATH=/home/user/.local/bin:${PATH}
36
+ WORKDIR ${HOME}/app
37
+
38
+ RUN curl https://pyenv.run | bash
39
+ ENV PATH=${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:${PATH}
40
+ ENV PYTHON_VERSION=3.10.9
41
+ RUN pyenv install ${PYTHON_VERSION} && \
42
+ pyenv global ${PYTHON_VERSION} && \
43
+ pyenv rehash && \
44
+ pip install --no-cache-dir -U pip setuptools wheel
45
+
46
+ RUN pip install --no-cache-dir -U torch==1.12.1 torchvision==0.13.1
47
+ COPY --chown=1000 requirements.txt /tmp/requirements.txt
48
+ RUN pip install --no-cache-dir -U -r /tmp/requirements.txt
49
+
50
+ COPY --chown=1000 . ${HOME}/app
51
+ RUN ls -a
52
+ ENV PYTHONPATH=${HOME}/app \
53
+ PYTHONUNBUFFERED=1 \
54
+ GRADIO_ALLOW_FLAGGING=never \
55
+ GRADIO_NUM_PORTS=1 \
56
+ GRADIO_SERVER_NAME=0.0.0.0 \
57
+ GRADIO_THEME=huggingface \
58
+ SYSTEM=spaces
59
+ CMD ["python", "app.py"]
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tencent AI Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,14 @@
1
  ---
2
  title: SadTalker
3
- emoji: 🏢
4
- colorFrom: indigo
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.31.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
  title: SadTalker
3
+ emoji: 😭
4
+ colorFrom: purple
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.23.0
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
app.py ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import platform
3
+ import torch
4
+ import gradio as gr
5
+ from huggingface_hub import snapshot_download
6
+ import uuid
7
+ import shutil
8
+ from pydub import AudioSegment
9
+ import spaces
10
+
11
+ from src.facerender.pirender_animate import AnimateFromCoeff_PIRender
12
+ from src.utils.preprocess import CropAndExtract
13
+ from src.test_audio2coeff import Audio2Coeff
14
+ from src.facerender.animate import AnimateFromCoeff
15
+ from src.generate_batch import get_data
16
+ from src.generate_facerender_batch import get_facerender_data
17
+ from src.utils.init_path import init_path
18
+
19
+
20
+ def get_source_image(image):
21
+ return image
22
+
23
+
24
+ def toggle_audio_file(choice):
25
+ if choice == False:
26
+ return gr.update(visible=True), gr.update(visible=False)
27
+ else:
28
+ return gr.update(visible=False), gr.update(visible=True)
29
+
30
+
31
+ def ref_video_fn(path_of_ref_video):
32
+ if path_of_ref_video is not None:
33
+ return gr.update(value=True)
34
+ else:
35
+ return gr.update(value=False)
36
+
37
+
38
+ if torch.cuda.is_available():
39
+ device = "cuda"
40
+ elif platform.system() == 'Darwin': # macos
41
+ device = "mps"
42
+ else:
43
+ device = "cpu"
44
+
45
+ os.environ['TORCH_HOME'] = 'checkpoints'
46
+
47
+ checkpoint_path = 'checkpoints'
48
+ config_path = 'src/config'
49
+
50
+ snapshot_download(repo_id='vinthony/SadTalker-V002rc',
51
+ local_dir='./checkpoints', local_dir_use_symlinks=True)
52
+
53
+
54
+ def mp3_to_wav(mp3_filename, wav_filename, frame_rate):
55
+ mp3_file = AudioSegment.from_file(file=mp3_filename)
56
+ mp3_file.set_frame_rate(frame_rate).export(wav_filename, format="wav")
57
+
58
+
59
+ @spaces.GPU()
60
+ def test(source_image, driven_audio, preprocess='crop',
61
+ still_mode=False, use_enhancer=False, batch_size=1, size=256,
62
+ pose_style=0,
63
+ facerender='facevid2vid',
64
+ exp_scale=1.0,
65
+ use_ref_video=False,
66
+ ref_video=None,
67
+ ref_info=None,
68
+ use_idle_mode=False,
69
+ length_of_audio=0, use_blink=True,
70
+ result_dir='./results/'):
71
+
72
+ sadtalker_paths = init_path(
73
+ checkpoint_path, config_path, size, False, preprocess)
74
+
75
+ audio_to_coeff = Audio2Coeff(sadtalker_paths, device)
76
+ preprocess_model = CropAndExtract(sadtalker_paths, device)
77
+
78
+ if facerender == 'facevid2vid' and device != 'mps':
79
+ animate_from_coeff = AnimateFromCoeff(
80
+ sadtalker_paths, device)
81
+ elif facerender == 'pirender' or device == 'mps':
82
+ animate_from_coeff = AnimateFromCoeff_PIRender(
83
+ sadtalker_paths, device)
84
+ facerender = 'pirender'
85
+ else:
86
+ raise (RuntimeError('Unknown model: {}'.format(facerender)))
87
+
88
+ time_tag = str(uuid.uuid4())
89
+ save_dir = os.path.join(result_dir, time_tag)
90
+ os.makedirs(save_dir, exist_ok=True)
91
+
92
+ input_dir = os.path.join(save_dir, 'input')
93
+ os.makedirs(input_dir, exist_ok=True)
94
+
95
+ print(source_image)
96
+ pic_path = os.path.join(input_dir, os.path.basename(source_image))
97
+ shutil.move(source_image, input_dir)
98
+
99
+ if driven_audio is not None and os.path.isfile(driven_audio):
100
+ audio_path = os.path.join(input_dir, os.path.basename(driven_audio))
101
+
102
+ # mp3 to wav
103
+ if '.mp3' in audio_path:
104
+ mp3_to_wav(driven_audio, audio_path.replace('.mp3', '.wav'), 16000)
105
+ audio_path = audio_path.replace('.mp3', '.wav')
106
+ else:
107
+ shutil.move(driven_audio, input_dir)
108
+
109
+ elif use_idle_mode:
110
+ # generate audio from this new audio_path
111
+ audio_path = os.path.join(
112
+ input_dir, 'idlemode_'+str(length_of_audio)+'.wav')
113
+ from pydub import AudioSegment
114
+ one_sec_segment = AudioSegment.silent(
115
+ duration=1000*length_of_audio) # duration in milliseconds
116
+ one_sec_segment.export(audio_path, format="wav")
117
+ else:
118
+ print(use_ref_video, ref_info)
119
+ assert use_ref_video == True and ref_info == 'all'
120
+
121
+ if use_ref_video and ref_info == 'all': # full ref mode
122
+ ref_video_videoname = os.path.basename(ref_video)
123
+ audio_path = os.path.join(save_dir, ref_video_videoname+'.wav')
124
+ print('new audiopath:', audio_path)
125
+ # if ref_video contains audio, set the audio from ref_video.
126
+ cmd = r"ffmpeg -y -hide_banner -loglevel error -i %s %s" % (
127
+ ref_video, audio_path)
128
+ os.system(cmd)
129
+
130
+ os.makedirs(save_dir, exist_ok=True)
131
+
132
+ # crop image and extract 3dmm from image
133
+ first_frame_dir = os.path.join(save_dir, 'first_frame_dir')
134
+ os.makedirs(first_frame_dir, exist_ok=True)
135
+ first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(
136
+ pic_path, first_frame_dir, preprocess, True, size)
137
+
138
+ if first_coeff_path is None:
139
+ raise AttributeError("No face is detected")
140
+
141
+ if use_ref_video:
142
+ print('using ref video for genreation')
143
+ ref_video_videoname = os.path.splitext(os.path.split(ref_video)[-1])[0]
144
+ ref_video_frame_dir = os.path.join(save_dir, ref_video_videoname)
145
+ os.makedirs(ref_video_frame_dir, exist_ok=True)
146
+ print('3DMM Extraction for the reference video providing pose')
147
+ ref_video_coeff_path, _, _ = preprocess_model.generate(
148
+ ref_video, ref_video_frame_dir, preprocess, source_image_flag=False)
149
+ else:
150
+ ref_video_coeff_path = None
151
+
152
+ if use_ref_video:
153
+ if ref_info == 'pose':
154
+ ref_pose_coeff_path = ref_video_coeff_path
155
+ ref_eyeblink_coeff_path = None
156
+ elif ref_info == 'blink':
157
+ ref_pose_coeff_path = None
158
+ ref_eyeblink_coeff_path = ref_video_coeff_path
159
+ elif ref_info == 'pose+blink':
160
+ ref_pose_coeff_path = ref_video_coeff_path
161
+ ref_eyeblink_coeff_path = ref_video_coeff_path
162
+ elif ref_info == 'all':
163
+ ref_pose_coeff_path = None
164
+ ref_eyeblink_coeff_path = None
165
+ else:
166
+ raise ('error in refinfo')
167
+ else:
168
+ ref_pose_coeff_path = None
169
+ ref_eyeblink_coeff_path = None
170
+
171
+ # audio2ceoff
172
+ if use_ref_video and ref_info == 'all':
173
+ # audio_to_coeff.generate(batch, save_dir, pose_style, ref_pose_coeff_path)
174
+ coeff_path = ref_video_coeff_path
175
+ else:
176
+ batch = get_data(first_coeff_path, audio_path, device, ref_eyeblink_coeff_path=ref_eyeblink_coeff_path, still=still_mode,
177
+ idlemode=use_idle_mode, length_of_audio=length_of_audio, use_blink=use_blink) # longer audio?
178
+ coeff_path = audio_to_coeff.generate(
179
+ batch, save_dir, pose_style, ref_pose_coeff_path)
180
+
181
+ # coeff2video
182
+ data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path, batch_size, still_mode=still_mode,
183
+ preprocess=preprocess, size=size, expression_scale=exp_scale, facemodel=facerender)
184
+ return_path = animate_from_coeff.generate(
185
+ data, save_dir, pic_path, crop_info, enhancer='gfpgan' if use_enhancer else None, preprocess=preprocess, img_size=size)
186
+ video_name = data['video_name']
187
+ print(f'The generated video is named {video_name} in {save_dir}')
188
+
189
+ del preprocess_model
190
+ del audio_to_coeff
191
+ del animate_from_coeff
192
+
193
+ if torch.cuda.is_available():
194
+ torch.cuda.empty_cache()
195
+ torch.cuda.synchronize()
196
+
197
+ import gc
198
+ gc.collect()
199
+
200
+ return return_path
201
+
202
+
203
+ with gr.Blocks(analytics_enabled=False) as demo:
204
+ with gr.Row().style(equal_height=False):
205
+ with gr.Column(variant='panel'):
206
+ with gr.Tabs(elem_id="sadtalker_source_image"):
207
+ with gr.TabItem('Source image'):
208
+ with gr.Row():
209
+ source_image = gr.Image(
210
+ label="Source image", source="upload", type="filepath", elem_id="img2img_image").style(width=512)
211
+
212
+ with gr.Tabs(elem_id="sadtalker_driven_audio"):
213
+ with gr.TabItem('Driving Methods'):
214
+ gr.Markdown(
215
+ "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) ")
216
+
217
+ with gr.Row():
218
+ driven_audio = gr.Audio(
219
+ label="Input audio", source="upload", type="filepath")
220
+ driven_audio_no = gr.Audio(
221
+ label="Use IDLE mode, no audio is required", source="upload", type="filepath", visible=False)
222
+
223
+ with gr.Column():
224
+ use_idle_mode = gr.Checkbox(
225
+ label="Use Idle Animation")
226
+ length_of_audio = gr.Number(
227
+ value=5, label="The length(seconds) of the generated video.")
228
+ use_idle_mode.change(toggle_audio_file, inputs=use_idle_mode, outputs=[
229
+ driven_audio, driven_audio_no]) # todo
230
+
231
+ with gr.Row():
232
+ ref_video = gr.Video(
233
+ label="Reference Video", source="upload", type="filepath", elem_id="vidref").style(width=512)
234
+
235
+ with gr.Column():
236
+ use_ref_video = gr.Checkbox(
237
+ label="Use Reference Video")
238
+ ref_info = gr.Radio(['pose', 'blink', 'pose+blink', 'all'], value='pose', label='Reference Video',
239
+ info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
240
+
241
+ ref_video.change(ref_video_fn, inputs=ref_video, outputs=[
242
+ use_ref_video]) # todo
243
+
244
+ with gr.Column(variant='panel'):
245
+ with gr.Tabs(elem_id="sadtalker_checkbox"):
246
+ with gr.TabItem('Settings'):
247
+ with gr.Column(variant='panel'):
248
+ # width = gr.Slider(minimum=64, elem_id="img2img_width", maximum=2048, step=8, label="Manually Crop Width", value=512) # img2img_width
249
+ # height = gr.Slider(minimum=64, elem_id="img2img_height", maximum=2048, step=8, label="Manually Crop Height", value=512) # img2img_width
250
+ with gr.Row():
251
+ pose_style = gr.Slider(
252
+ minimum=0, maximum=45, step=1, label="Pose style", value=0)
253
+ exp_weight = gr.Slider(
254
+ minimum=0, maximum=3, step=0.1, label="expression scale", value=1)
255
+ blink_every = gr.Checkbox(
256
+ label="use eye blink", value=True)
257
+
258
+ with gr.Row():
259
+ size_of_image = gr.Radio(
260
+ [256, 512], value=256, label='face model resolution', info="use 256/512 model?")
261
+ preprocess_type = gr.Radio(
262
+ ['crop', 'resize', 'full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
263
+
264
+ with gr.Row():
265
+ is_still_mode = gr.Checkbox(
266
+ label="Still Mode (fewer head motion, works with preprocess `full`)")
267
+ facerender = gr.Radio(
268
+ ['facevid2vid', 'pirender'], value='facevid2vid', label='facerender', info="which face render?")
269
+
270
+ with gr.Row():
271
+ batch_size = gr.Slider(
272
+ label="batch size in generation", step=1, maximum=10, value=1)
273
+ enhancer = gr.Checkbox(
274
+ label="GFPGAN as Face enhancer")
275
+
276
+ submit = gr.Button(
277
+ 'Generate', elem_id="sadtalker_generate", variant='primary')
278
+
279
+ with gr.Tabs(elem_id="sadtalker_genearted"):
280
+ gen_video = gr.Video(
281
+ label="Generated video", format="mp4").style(width=256)
282
+
283
+ submit.click(
284
+ fn=test,
285
+ inputs=[source_image,
286
+ driven_audio,
287
+ preprocess_type,
288
+ is_still_mode,
289
+ enhancer,
290
+ batch_size,
291
+ size_of_image,
292
+ pose_style,
293
+ facerender,
294
+ exp_weight,
295
+ use_ref_video,
296
+ ref_video,
297
+ ref_info,
298
+ use_idle_mode,
299
+ length_of_audio,
300
+ blink_every
301
+ ],
302
+ outputs=[gen_video],
303
+ )
304
+
305
+ with gr.Row():
306
+ examples = [
307
+ [
308
+ 'examples/source_image/full_body_1.png',
309
+ 'examples/driven_audio/bus_chinese.wav',
310
+ 'crop',
311
+ True,
312
+ False
313
+ ],
314
+ [
315
+ 'examples/source_image/full_body_2.png',
316
+ 'examples/driven_audio/japanese.wav',
317
+ 'crop',
318
+ False,
319
+ False
320
+ ],
321
+ [
322
+ 'examples/source_image/full3.png',
323
+ 'examples/driven_audio/deyu.wav',
324
+ 'crop',
325
+ False,
326
+ True
327
+ ],
328
+ [
329
+ 'examples/source_image/full4.jpeg',
330
+ 'examples/driven_audio/eluosi.wav',
331
+ 'full',
332
+ False,
333
+ True
334
+ ],
335
+ [
336
+ 'examples/source_image/full4.jpeg',
337
+ 'examples/driven_audio/imagine.wav',
338
+ 'full',
339
+ True,
340
+ True
341
+ ],
342
+ [
343
+ 'examples/source_image/full_body_1.png',
344
+ 'examples/driven_audio/bus_chinese.wav',
345
+ 'full',
346
+ True,
347
+ False
348
+ ],
349
+ [
350
+ 'examples/source_image/art_13.png',
351
+ 'examples/driven_audio/fayu.wav',
352
+ 'resize',
353
+ True,
354
+ False
355
+ ],
356
+ [
357
+ 'examples/source_image/art_5.png',
358
+ 'examples/driven_audio/chinese_news.wav',
359
+ 'resize',
360
+ False,
361
+ False
362
+ ],
363
+ [
364
+ 'examples/source_image/art_5.png',
365
+ 'examples/driven_audio/RD_Radio31_000.wav',
366
+ 'resize',
367
+ True,
368
+ True
369
+ ],
370
+ ]
371
+ gr.Examples(examples=examples,
372
+ inputs=[
373
+ source_image,
374
+ driven_audio,
375
+ preprocess_type,
376
+ is_still_mode,
377
+ enhancer],
378
+ outputs=[gen_video],
379
+ fn=test,
380
+ cache_examples=os.getenv('SYSTEM') == 'spaces')
381
+
382
+ demo.launch(debug=True)
docs/sadtalker_logo.png ADDED
examples/.DS_Store ADDED
Binary file (6.15 kB). View file
 
examples/driven_audio/RD_Radio31_000.wav ADDED
Binary file (512 kB). View file
 
examples/driven_audio/RD_Radio34_002.wav ADDED
Binary file (512 kB). View file
 
examples/driven_audio/RD_Radio36_000.wav ADDED
Binary file (512 kB). View file
 
examples/driven_audio/RD_Radio40_000.wav ADDED
Binary file (512 kB). View file
 
examples/driven_audio/bus_chinese.wav ADDED
Binary file (652 kB). View file
 
examples/driven_audio/chinese_news.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7b0f4d313a1ca671bc4831d60bcf0c12225efbffe6c0e93e54fbfe9bcd4021cb
3
+ size 1536078
examples/driven_audio/chinese_poem1.wav ADDED
Binary file (263 kB). View file
 
examples/driven_audio/chinese_poem2.wav ADDED
Binary file (461 kB). View file
 
examples/driven_audio/deyu.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba1839c57770a2ab0b593ce814344bfd4d750da02acc9be9e8cf5b9113a0f88a
3
+ size 2694784
examples/driven_audio/eluosi.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4a3593815dc7b68c256672baa61934c9479efa770af2065fb0886f02713606e
3
+ size 1786672
examples/driven_audio/fayu.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16ebd13626ae4171030b4ea05cceef06078483c352e4b68d469fc2a52bfffceb
3
+ size 1940428
examples/driven_audio/imagine.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2db410217e074d91ae6011e1c5dc0b94f02d05d381c50af8e54253eeacad17d2
3
+ size 1618510
examples/driven_audio/itosinger1.wav ADDED
Binary file (500 kB). View file
 
examples/driven_audio/japanese.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3db5426d0b158799e2be4f609b11f75bfbd4affffe18e9a1c8e6f241fcdedcfc
3
+ size 2622712
examples/source_image/art_0.png ADDED
examples/source_image/art_1.png ADDED
examples/source_image/art_10.png ADDED
examples/source_image/art_11.png ADDED
examples/source_image/art_12.png ADDED
examples/source_image/art_13.png ADDED
examples/source_image/art_14.png ADDED
examples/source_image/art_15.png ADDED
examples/source_image/art_16.png ADDED

Git LFS Details

  • SHA256: 3f6d350055eea3abe35ee3fe9df80dcd99d8edae66ef4fc20bf06168bf189f25
  • Pointer size: 132 Bytes
  • Size of remote file: 1.48 MB
examples/source_image/art_17.png ADDED

Git LFS Details

  • SHA256: 05747bb45dcf271d9bb24344bd1bce0e0746d24ce4e13545b27ad40b50c3bfe7
  • Pointer size: 132 Bytes
  • Size of remote file: 2.09 MB
examples/source_image/art_18.png ADDED
examples/source_image/art_19.png ADDED
examples/source_image/art_2.png ADDED
examples/source_image/art_20.png ADDED
examples/source_image/art_3.png ADDED

Git LFS Details

  • SHA256: 81be3a9cc605ab01cbf741330b406db5246e8bbbcb443ad43ffeca2ef161e005
  • Pointer size: 132 Bytes
  • Size of remote file: 1.35 MB
examples/source_image/art_4.png ADDED

Git LFS Details

  • SHA256: ab322220d8eab1bfefdaedea91ca5d08a34258c1ab1e585a9b1c85b32968f983
  • Pointer size: 132 Bytes
  • Size of remote file: 3.63 MB
examples/source_image/art_5.png ADDED

Git LFS Details

  • SHA256: 199217b4c839ed849577aedcad32f2bce934628b9783ba4654a93756b25e7896
  • Pointer size: 132 Bytes
  • Size of remote file: 1.23 MB
examples/source_image/art_6.png ADDED
examples/source_image/art_7.png ADDED
examples/source_image/art_8.png ADDED

Git LFS Details

  • SHA256: 1d704497947c07ac16534299451fc0526acddf286c2ab4ceb48161ff6facc2af
  • Pointer size: 132 Bytes
  • Size of remote file: 3.12 MB
examples/source_image/art_9.png ADDED

Git LFS Details

  • SHA256: 90f84739e2aa2388efaf0fac2b57a82df279b213a8dab9faa7af8ae7468b4e80
  • Pointer size: 132 Bytes
  • Size of remote file: 1.26 MB
examples/source_image/full3.png ADDED
examples/source_image/full4.jpeg ADDED
examples/source_image/full_body_1.png ADDED
examples/source_image/full_body_2.png ADDED
examples/source_image/happy.png ADDED
examples/source_image/happy1.png ADDED
examples/source_image/people_0.png ADDED