Spaces:
Build error
Build error
tdnathmlenthusiast
commited on
Commit
•
2473bb6
1
Parent(s):
4347350
Upload 8 files
Browse files- .gitattributes +52 -35
- .gitignore +159 -0
- Dockerfile +59 -0
- LICENSE +21 -0
- README.md +12 -13
- app.py +217 -0
- packages.txt +2 -0
- requirements.txt +24 -0
.gitattributes
CHANGED
@@ -1,35 +1,52 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar 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 |
-
*.
|
29 |
-
*.
|
30 |
-
*.
|
31 |
-
*.
|
32 |
-
*.
|
33 |
-
*.
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar 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
|
31 |
+
*.xz 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,13 +1,12 @@
|
|
1 |
-
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
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
|
|
app.py
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import platform
|
3 |
+
import uuid
|
4 |
+
import shutil
|
5 |
+
from pydub import AudioSegment
|
6 |
+
import spaces
|
7 |
+
import torch
|
8 |
+
import gradio as gr
|
9 |
+
from huggingface_hub import snapshot_download
|
10 |
+
|
11 |
+
from examples.get_examples import get_examples
|
12 |
+
from src.facerender.pirender_animate import AnimateFromCoeff_PIRender
|
13 |
+
from src.utils.preprocess import CropAndExtract
|
14 |
+
from src.test_audio2coeff import Audio2Coeff
|
15 |
+
from src.facerender.animate import AnimateFromCoeff
|
16 |
+
from src.generate_batch import get_data
|
17 |
+
from src.generate_facerender_batch import get_facerender_data
|
18 |
+
from src.utils.init_path import init_path
|
19 |
+
|
20 |
+
checkpoint_path = 'checkpoints'
|
21 |
+
config_path = 'src/config'
|
22 |
+
device = "cuda" if torch.cuda.is_available(
|
23 |
+
) else "mps" if platform.system() == 'Darwin' else "cpu"
|
24 |
+
|
25 |
+
os.environ['TORCH_HOME'] = checkpoint_path
|
26 |
+
snapshot_download(repo_id='vinthony/SadTalker-V002rc',
|
27 |
+
local_dir=checkpoint_path, local_dir_use_symlinks=True)
|
28 |
+
|
29 |
+
|
30 |
+
def mp3_to_wav(mp3_filename, wav_filename, frame_rate):
|
31 |
+
AudioSegment.from_file(file=mp3_filename).set_frame_rate(
|
32 |
+
frame_rate).export(wav_filename, format="wav")
|
33 |
+
|
34 |
+
|
35 |
+
@spaces.GPU(duration=120)
|
36 |
+
def generate_video(source_image, driven_audio, preprocess='crop', still_mode=False, use_enhancer=False,
|
37 |
+
batch_size=1, size=256, pose_style=0, facerender='facevid2vid', exp_scale=1.0,
|
38 |
+
use_ref_video=False, ref_video=None, ref_info=None, use_idle_mode=False,
|
39 |
+
length_of_audio=0, use_blink=True, result_dir='./results/'):
|
40 |
+
# Initialize models and paths
|
41 |
+
sadtalker_paths = init_path(
|
42 |
+
checkpoint_path, config_path, size, False, preprocess)
|
43 |
+
audio_to_coeff = Audio2Coeff(sadtalker_paths, device)
|
44 |
+
preprocess_model = CropAndExtract(sadtalker_paths, device)
|
45 |
+
animate_from_coeff = AnimateFromCoeff(sadtalker_paths, device) if facerender == 'facevid2vid' and device != 'mps' \
|
46 |
+
else AnimateFromCoeff_PIRender(sadtalker_paths, device)
|
47 |
+
|
48 |
+
# Create directories for saving results
|
49 |
+
time_tag = str(uuid.uuid4())
|
50 |
+
save_dir = os.path.join(result_dir, time_tag)
|
51 |
+
os.makedirs(save_dir, exist_ok=True)
|
52 |
+
input_dir = os.path.join(save_dir, 'input')
|
53 |
+
os.makedirs(input_dir, exist_ok=True)
|
54 |
+
|
55 |
+
# Process source image
|
56 |
+
pic_path = os.path.join(input_dir, os.path.basename(source_image))
|
57 |
+
shutil.move(source_image, input_dir)
|
58 |
+
|
59 |
+
# Process driven audio
|
60 |
+
if driven_audio and os.path.isfile(driven_audio):
|
61 |
+
audio_path = os.path.join(input_dir, os.path.basename(driven_audio))
|
62 |
+
if '.mp3' in audio_path:
|
63 |
+
mp3_to_wav(driven_audio, audio_path.replace('.mp3', '.wav'), 16000)
|
64 |
+
audio_path = audio_path.replace('.mp3', '.wav')
|
65 |
+
else:
|
66 |
+
shutil.move(driven_audio, input_dir)
|
67 |
+
elif use_idle_mode:
|
68 |
+
audio_path = os.path.join(
|
69 |
+
input_dir, 'idlemode_'+str(length_of_audio)+'.wav')
|
70 |
+
AudioSegment.silent(
|
71 |
+
duration=1000*length_of_audio).export(audio_path, format="wav")
|
72 |
+
else:
|
73 |
+
assert use_ref_video and ref_info == 'all'
|
74 |
+
|
75 |
+
# Process reference video
|
76 |
+
if use_ref_video and ref_info == 'all':
|
77 |
+
ref_video_videoname = os.path.splitext(os.path.split(ref_video)[-1])[0]
|
78 |
+
audio_path = os.path.join(save_dir, ref_video_videoname+'.wav')
|
79 |
+
os.system(
|
80 |
+
f"ffmpeg -y -hide_banner -loglevel error -i {ref_video} {audio_path}")
|
81 |
+
ref_video_frame_dir = os.path.join(save_dir, ref_video_videoname)
|
82 |
+
os.makedirs(ref_video_frame_dir, exist_ok=True)
|
83 |
+
ref_video_coeff_path, _, _ = preprocess_model.generate(
|
84 |
+
ref_video, ref_video_frame_dir, preprocess, source_image_flag=False)
|
85 |
+
else:
|
86 |
+
ref_video_coeff_path = None
|
87 |
+
|
88 |
+
# Preprocess source image
|
89 |
+
first_frame_dir = os.path.join(save_dir, 'first_frame_dir')
|
90 |
+
os.makedirs(first_frame_dir, exist_ok=True)
|
91 |
+
first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(
|
92 |
+
pic_path, first_frame_dir, preprocess, True, size)
|
93 |
+
if first_coeff_path is None:
|
94 |
+
raise AttributeError("No face is detected")
|
95 |
+
|
96 |
+
# Determine reference coefficients
|
97 |
+
ref_pose_coeff_path, ref_eyeblink_coeff_path = None, None
|
98 |
+
if use_ref_video:
|
99 |
+
if ref_info == 'pose':
|
100 |
+
ref_pose_coeff_path = ref_video_coeff_path
|
101 |
+
elif ref_info == 'blink':
|
102 |
+
ref_eyeblink_coeff_path = ref_video_coeff_path
|
103 |
+
elif ref_info == 'pose+blink':
|
104 |
+
ref_pose_coeff_path = ref_eyeblink_coeff_path = ref_video_coeff_path
|
105 |
+
else:
|
106 |
+
ref_pose_coeff_path = ref_eyeblink_coeff_path = None
|
107 |
+
|
108 |
+
# Generate coefficients from audio or reference video
|
109 |
+
if use_ref_video and ref_info == 'all':
|
110 |
+
coeff_path = ref_video_coeff_path
|
111 |
+
else:
|
112 |
+
batch = get_data(first_coeff_path, audio_path, device, ref_eyeblink_coeff_path=ref_eyeblink_coeff_path,
|
113 |
+
still=still_mode, idlemode=use_idle_mode, length_of_audio=length_of_audio, use_blink=use_blink)
|
114 |
+
coeff_path = audio_to_coeff.generate(
|
115 |
+
batch, save_dir, pose_style, ref_pose_coeff_path)
|
116 |
+
|
117 |
+
# Generate video from coefficients
|
118 |
+
data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path, batch_size, still_mode=still_mode,
|
119 |
+
preprocess=preprocess, size=size, expression_scale=exp_scale, facemodel=facerender)
|
120 |
+
return_path = animate_from_coeff.generate(data, save_dir, pic_path, crop_info, enhancer='gfpgan' if use_enhancer else None,
|
121 |
+
preprocess=preprocess, img_size=size)
|
122 |
+
video_name = data['video_name']
|
123 |
+
print(f'The generated video is named {video_name} in {save_dir}')
|
124 |
+
|
125 |
+
return return_path
|
126 |
+
|
127 |
+
|
128 |
+
# Gradio UI
|
129 |
+
with gr.Blocks(analytics_enabled=False) as demo:
|
130 |
+
with gr.Row():
|
131 |
+
with gr.Column(variant='panel'):
|
132 |
+
with gr.Tabs(elem_id="sadtalker_source_image"):
|
133 |
+
with gr.TabItem('Source image'):
|
134 |
+
with gr.Row():
|
135 |
+
source_image = gr.Image(
|
136 |
+
label="Source image", sources="upload", type="filepath", elem_id="img2img_image")
|
137 |
+
|
138 |
+
with gr.Tabs(elem_id="sadtalker_driven_audio"):
|
139 |
+
with gr.TabItem('Driving Methods'):
|
140 |
+
gr.Markdown(
|
141 |
+
"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) ")
|
142 |
+
|
143 |
+
with gr.Row():
|
144 |
+
driven_audio = gr.Audio(
|
145 |
+
label="Input audio", sources="upload", type="filepath")
|
146 |
+
driven_audio_no = gr.Audio(
|
147 |
+
label="Use IDLE mode, no audio is required", sources="upload", type="filepath", visible=False)
|
148 |
+
|
149 |
+
with gr.Column():
|
150 |
+
use_idle_mode = gr.Checkbox(
|
151 |
+
label="Use Idle Animation")
|
152 |
+
length_of_audio = gr.Number(
|
153 |
+
value=5, label="The length(seconds) of the generated video.")
|
154 |
+
use_idle_mode.change(lambda choice: (gr.update(visible=not choice), gr.update(visible=choice)),
|
155 |
+
inputs=use_idle_mode, outputs=[driven_audio, driven_audio_no])
|
156 |
+
|
157 |
+
with gr.Row():
|
158 |
+
ref_video = gr.Video(
|
159 |
+
label="Reference Video", sources="upload", elem_id="vidref")
|
160 |
+
|
161 |
+
with gr.Column():
|
162 |
+
use_ref_video = gr.Checkbox(
|
163 |
+
label="Use Reference Video")
|
164 |
+
ref_info = gr.Radio(['pose', 'blink', 'pose+blink', 'all'], value='pose', label='Reference Video',
|
165 |
+
info="How to borrow from reference Video?((fully transfer, aka, video driving mode))")
|
166 |
+
|
167 |
+
ref_video.change(lambda path: gr.update(
|
168 |
+
value=path is not None), inputs=ref_video, outputs=use_ref_video)
|
169 |
+
|
170 |
+
with gr.Column(variant='panel'):
|
171 |
+
with gr.Tabs(elem_id="sadtalker_checkbox"):
|
172 |
+
with gr.TabItem('Settings'):
|
173 |
+
with gr.Column(variant='panel'):
|
174 |
+
with gr.Row():
|
175 |
+
pose_style = gr.Slider(
|
176 |
+
minimum=0, maximum=45, step=1, label="Pose style", value=0)
|
177 |
+
exp_weight = gr.Slider(
|
178 |
+
minimum=0, maximum=3, step=0.1, label="expression scale", value=1)
|
179 |
+
blink_every = gr.Checkbox(
|
180 |
+
label="use eye blink", value=True)
|
181 |
+
|
182 |
+
with gr.Row():
|
183 |
+
size_of_image = gr.Radio(
|
184 |
+
[256, 512], value=256, label='face model resolution', info="use 256/512 model?")
|
185 |
+
preprocess_type = gr.Radio(
|
186 |
+
['crop', 'resize', 'full', 'extcrop', 'extfull'], value='crop', label='preprocess', info="How to handle input image?")
|
187 |
+
|
188 |
+
with gr.Row():
|
189 |
+
is_still_mode = gr.Checkbox(
|
190 |
+
label="Still Mode (fewer head motion, works with preprocess `full`)")
|
191 |
+
facerender = gr.Radio(
|
192 |
+
['facevid2vid', 'pirender'], value='facevid2vid', label='facerender', info="which face render?")
|
193 |
+
|
194 |
+
with gr.Row():
|
195 |
+
batch_size = gr.Slider(
|
196 |
+
label="batch size in generation", step=1, maximum=10, value=1)
|
197 |
+
enhancer = gr.Checkbox(
|
198 |
+
label="GFPGAN as Face enhancer", value=True)
|
199 |
+
|
200 |
+
submit = gr.Button(
|
201 |
+
'Generate', elem_id="sadtalker_generate", variant='primary')
|
202 |
+
|
203 |
+
with gr.Tabs(elem_id="sadtalker_generated"):
|
204 |
+
gen_video = gr.Video(label="Generated video")
|
205 |
+
|
206 |
+
submit.click(
|
207 |
+
fn=generate_video,
|
208 |
+
inputs=[source_image, driven_audio, preprocess_type, is_still_mode, enhancer, batch_size, size_of_image,
|
209 |
+
pose_style, facerender, exp_weight, use_ref_video, ref_video, ref_info, use_idle_mode, length_of_audio, blink_every],
|
210 |
+
outputs=[gen_video],
|
211 |
+
)
|
212 |
+
|
213 |
+
with gr.Row():
|
214 |
+
gr.Examples(examples=get_examples(), inputs=[source_image, driven_audio, preprocess_type, is_still_mode, enhancer],
|
215 |
+
outputs=[gen_video], fn=generate_video)
|
216 |
+
|
217 |
+
demo.launch(debug=True)
|
packages.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ffmpeg
|
2 |
+
libsndfile1
|
requirements.txt
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision==0.15.2
|
3 |
+
torchaudio
|
4 |
+
numpy==1.23.5
|
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 |
+
basicsr
|
20 |
+
facexlib
|
21 |
+
dlib-bin
|
22 |
+
gfpgan
|
23 |
+
av
|
24 |
+
safetensors
|