diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..1abafb3e8d53b49d7969ad40695be36ff5f92dcd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,26 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +docs/example_crop_still.gif filter=lfs diff=lfs merge=lfs -text +docs/example_crop.gif filter=lfs diff=lfs merge=lfs -text +docs/example_full_enhanced.gif filter=lfs diff=lfs merge=lfs -text +docs/example_full.gif filter=lfs diff=lfs merge=lfs -text +docs/free_view_result.gif filter=lfs diff=lfs merge=lfs -text +docs/resize_good.gif filter=lfs diff=lfs merge=lfs -text +docs/resize_no.gif filter=lfs diff=lfs merge=lfs -text +docs/using_ref_video.gif filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/chinese_news.wav filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/deyu.wav filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/eluosi.wav filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/fayu.wav filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/imagine.wav filter=lfs diff=lfs merge=lfs -text +examples/driven_audio/japanese.wav filter=lfs diff=lfs merge=lfs -text +examples/ref_video/WDA_AlexandriaOcasioCortez_000.mp4 filter=lfs diff=lfs merge=lfs -text +examples/ref_video/WDA_KatieHill_000.mp4 filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_16.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_17.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_3.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_4.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_5.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_8.png filter=lfs diff=lfs merge=lfs -text +examples/source_image/art_9.png filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..73c66b605152ba0e143900f8140e24655358d940 --- /dev/null +++ b/.gitignore @@ -0,0 +1,174 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ + +examples/results/* +gfpgan/* +checkpoints/* +assets/* +results/* +Dockerfile +start_docker.sh +start.sh + +checkpoints + +# Mac +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..153196259f6547168e21ab2832b431721836d993 --- /dev/null +++ b/LICENSE @@ -0,0 +1,209 @@ +Tencent is pleased to support the open source community by making SadTalker available. + +Copyright (C), a Tencent company. All rights reserved. + +SadTalker is licensed under the Apache 2.0 License, except for the third-party components listed below. + +Terms of the Apache License Version 2.0: +--------------------------------------------- + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/app_sadtalker.py b/app_sadtalker.py new file mode 100644 index 0000000000000000000000000000000000000000..1401a6005e0e3267a36365540c0fad81343f81f9 --- /dev/null +++ b/app_sadtalker.py @@ -0,0 +1,111 @@ +import os, sys +import gradio as gr +from src.gradio_demo import SadTalker + + +try: + import webui # in webui + in_webui = True +except: + in_webui = False + + +def toggle_audio_file(choice): + if choice == False: + return gr.update(visible=True), gr.update(visible=False) + else: + return gr.update(visible=False), gr.update(visible=True) + +def ref_video_fn(path_of_ref_video): + if path_of_ref_video is not None: + return gr.update(value=True) + else: + return gr.update(value=False) + +def sadtalker_demo(checkpoint_path='checkpoints', config_path='src/config', warpfn=None): + + sad_talker = SadTalker(checkpoint_path, config_path, lazy_load=True) + + with gr.Blocks(analytics_enabled=False) as sadtalker_interface: + gr.Markdown("
|  |  |
+
+
+In `resize` mode, we resize the whole images to generate the fully talking head video. Thus, an image similar to the ID photo can be produced. ⚠️ It will produce bad results for full person images.
+
+
+
+
+|
|
|
+|:--------------------: |:--------------------: |
+| ❌ not suitable for resize mode | ✅ good for resize mode |
+|
|
|
+
+In `full` mode, our model will automatically process the croped region and paste back to the original image. Remember to use `--still` to keep the original head pose.
+
+| input | `--still` | `--still` & `enhancer` |
+|:--------------------: |:--------------------: | :--:|
+|
|
|
+
+
+### About `--enhancer`
+
+For higher resolution, we intergate [gfpgan](https://github.com/TencentARC/GFPGAN) and [real-esrgan](https://github.com/xinntao/Real-ESRGAN) for different purpose. Just adding `--enhancer
| |
+
+> Kindly ensure to activate the audio as the default audio playing is incompatible with GitHub.
+
+
+
+#### Reference eye-link mode.
+
+| Input, w/ reference video , reference video |
+|:-------------: |
+| |
+| If the reference video is shorter than the input audio, we will loop the reference video .
+
+
+
+#### Generating 4D free-view talking examples from audio and a single image
+
+We use `input_yaw`, `input_pitch`, `input_roll` to control head pose. For example, `--input_yaw -20 30 10` means the input head yaw degree changes from -20 to 30 and then changes from 30 to 10.
+```bash
+python inference.py --driven_audio
+
+2. Download the checkpoints manually, for Linux and Mac:
+
+ ```bash
+
+ cd SOMEWHERE_YOU_LIKE
+
+ bash <(wget -qO- https://raw.githubusercontent.com/Winfredy/OpenTalker/main/scripts/download_models.sh)
+ ```
+
+ For Windows, you can download all the checkpoints [here](https://github.com/OpenTalker/SadTalker/tree/main#2-download-models).
+
+3.1. Option 1: put the checkpoint in `stable-diffusion-webui/models/SadTalker` or `stable-diffusion-webui/extensions/SadTalker/checkpoints/`, the checkpoints will be detected automatically.
+
+3.2. Option 2: Set the path of `SADTALKTER_CHECKPOINTS` in `webui_user.sh`(linux) or `webui_user.bat`(windows) by:
+
+ > only works if you are directly starting webui from `webui_user.sh` or `webui_user.bat`.
+
+ ```bash
+ # Windows (webui_user.bat)
+ set SADTALKER_CHECKPOINTS=D:\SadTalker\checkpoints
+
+ # Linux/macOS (webui_user.sh)
+ export SADTALKER_CHECKPOINTS=/path/to/SadTalker/checkpoints
+ ```
+
+4. Start the WebUI via `webui.sh or webui_user.sh(linux)` or `webui_user.bat(windows)` or any other method. SadTalker can also be used in stable-diffusion-webui directly.
+
+
+
+## Questions
+
+1. if you are running on CPU, you need to specific `--disable-safe-unpickle` in `webui_user.sh` or `webui_user.bat`.
+
+ ```bash
+ # windows (webui_user.bat)
+ set COMMANDLINE_ARGS="--disable-safe-unpickle"
+
+ # linux (webui_user.sh)
+ export COMMANDLINE_ARGS="--disable-safe-unpickle"
+ ```
+
+
+
+(If you're unable to use the `full` mode, please read this [discussion](https://github.com/Winfredy/SadTalker/issues/78).)
diff --git a/examples/driven_audio/RD_Radio31_000.wav b/examples/driven_audio/RD_Radio31_000.wav
new file mode 100644
index 0000000000000000000000000000000000000000..3b04940a0bff7481179c29bfc47553d9c4224bcf
Binary files /dev/null and b/examples/driven_audio/RD_Radio31_000.wav differ
diff --git a/examples/driven_audio/RD_Radio34_002.wav b/examples/driven_audio/RD_Radio34_002.wav
new file mode 100644
index 0000000000000000000000000000000000000000..6813e812a8d1c57cb2f02eee3fece68a0864d96e
Binary files /dev/null and b/examples/driven_audio/RD_Radio34_002.wav differ
diff --git a/examples/driven_audio/RD_Radio36_000.wav b/examples/driven_audio/RD_Radio36_000.wav
new file mode 100644
index 0000000000000000000000000000000000000000..c73adfed5f142886940bc249904d77f9e54befda
Binary files /dev/null and b/examples/driven_audio/RD_Radio36_000.wav differ
diff --git a/examples/driven_audio/RD_Radio40_000.wav b/examples/driven_audio/RD_Radio40_000.wav
new file mode 100644
index 0000000000000000000000000000000000000000..88ce964e1734210451e3a364f87f8661db388b74
Binary files /dev/null and b/examples/driven_audio/RD_Radio40_000.wav differ
diff --git a/examples/driven_audio/bus_chinese.wav b/examples/driven_audio/bus_chinese.wav
new file mode 100644
index 0000000000000000000000000000000000000000..888647738d72dfaee99b8d40bb0ddf6f7a1872e7
Binary files /dev/null and b/examples/driven_audio/bus_chinese.wav differ
diff --git a/examples/driven_audio/chinese_news.wav b/examples/driven_audio/chinese_news.wav
new file mode 100644
index 0000000000000000000000000000000000000000..9232795586cbcb926cca70f90691a9e281d32ab9
--- /dev/null
+++ b/examples/driven_audio/chinese_news.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7b0f4d313a1ca671bc4831d60bcf0c12225efbffe6c0e93e54fbfe9bcd4021cb
+size 1536078
diff --git a/examples/driven_audio/chinese_poem1.wav b/examples/driven_audio/chinese_poem1.wav
new file mode 100644
index 0000000000000000000000000000000000000000..17c0871100d454bcd95b4281ab6b153c04724fe5
Binary files /dev/null and b/examples/driven_audio/chinese_poem1.wav differ
diff --git a/examples/driven_audio/chinese_poem2.wav b/examples/driven_audio/chinese_poem2.wav
new file mode 100644
index 0000000000000000000000000000000000000000..e3b294eceff5c5ee43124b7cfa42e4a70196a45f
Binary files /dev/null and b/examples/driven_audio/chinese_poem2.wav differ
diff --git a/examples/driven_audio/deyu.wav b/examples/driven_audio/deyu.wav
new file mode 100644
index 0000000000000000000000000000000000000000..438cd45b36be0d7cec6732d1ffa1c396141a563e
--- /dev/null
+++ b/examples/driven_audio/deyu.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ba1839c57770a2ab0b593ce814344bfd4d750da02acc9be9e8cf5b9113a0f88a
+size 2694784
diff --git a/examples/driven_audio/eluosi.wav b/examples/driven_audio/eluosi.wav
new file mode 100644
index 0000000000000000000000000000000000000000..336e85fe5cb8d7110fbade7684cce4a33fdffb98
--- /dev/null
+++ b/examples/driven_audio/eluosi.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d4a3593815dc7b68c256672baa61934c9479efa770af2065fb0886f02713606e
+size 1786672
diff --git a/examples/driven_audio/fayu.wav b/examples/driven_audio/fayu.wav
new file mode 100644
index 0000000000000000000000000000000000000000..bf5cb6e65b2f959174facc80e13ce145226991cc
--- /dev/null
+++ b/examples/driven_audio/fayu.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:16ebd13626ae4171030b4ea05cceef06078483c352e4b68d469fc2a52bfffceb
+size 1940428
diff --git a/examples/driven_audio/imagine.wav b/examples/driven_audio/imagine.wav
new file mode 100644
index 0000000000000000000000000000000000000000..c02a95b80b8e2b5c4353a4047239c361e9e3d01a
--- /dev/null
+++ b/examples/driven_audio/imagine.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:2db410217e074d91ae6011e1c5dc0b94f02d05d381c50af8e54253eeacad17d2
+size 1618510
diff --git a/examples/driven_audio/itosinger1.wav b/examples/driven_audio/itosinger1.wav
new file mode 100644
index 0000000000000000000000000000000000000000..4937dbb264e2fc24d4752baf8b802b0bac41be24
Binary files /dev/null and b/examples/driven_audio/itosinger1.wav differ
diff --git a/examples/driven_audio/japanese.wav b/examples/driven_audio/japanese.wav
new file mode 100644
index 0000000000000000000000000000000000000000..63db9ffc287a9186f144b635f87bf352ba30ff22
--- /dev/null
+++ b/examples/driven_audio/japanese.wav
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3db5426d0b158799e2be4f609b11f75bfbd4affffe18e9a1c8e6f241fcdedcfc
+size 2622712
diff --git a/examples/ref_video/WDA_AlexandriaOcasioCortez_000.mp4 b/examples/ref_video/WDA_AlexandriaOcasioCortez_000.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..a9d1219ed3f515765753a3c2e4bb97655781bcc4
--- /dev/null
+++ b/examples/ref_video/WDA_AlexandriaOcasioCortez_000.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:a85242c3fc4d50e2202cea393b9e7ee59019759b68e78e26a254d528c22615a7
+size 2257667
diff --git a/examples/ref_video/WDA_KatieHill_000.mp4 b/examples/ref_video/WDA_KatieHill_000.mp4
new file mode 100644
index 0000000000000000000000000000000000000000..61bf40411df95054efee238debd31c7d38ab6a3d
--- /dev/null
+++ b/examples/ref_video/WDA_KatieHill_000.mp4
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1fbb4cfd64eedc49b170c441714a9c4fd5e2c2f8a11592070ad89fbd257f2817
+size 3548230
diff --git a/examples/source_image/art_0.png b/examples/source_image/art_0.png
new file mode 100644
index 0000000000000000000000000000000000000000..d8d97645a4ecd9018bf2ad6d9094cf581f816f58
Binary files /dev/null and b/examples/source_image/art_0.png differ
diff --git a/examples/source_image/art_1.png b/examples/source_image/art_1.png
new file mode 100644
index 0000000000000000000000000000000000000000..4388abe026a5ba1f6c2e9f3a782564bb611f5781
Binary files /dev/null and b/examples/source_image/art_1.png differ
diff --git a/examples/source_image/art_10.png b/examples/source_image/art_10.png
new file mode 100644
index 0000000000000000000000000000000000000000..5f6568b30f063b09cef08c54df629dae7ff54360
Binary files /dev/null and b/examples/source_image/art_10.png differ
diff --git a/examples/source_image/art_11.png b/examples/source_image/art_11.png
new file mode 100644
index 0000000000000000000000000000000000000000..4caf17ca866fe54cc5c3af33fb0e93114da1bfb9
Binary files /dev/null and b/examples/source_image/art_11.png differ
diff --git a/examples/source_image/art_12.png b/examples/source_image/art_12.png
new file mode 100644
index 0000000000000000000000000000000000000000..e15306c30f09807f7df80504032cc39b1c265b6a
Binary files /dev/null and b/examples/source_image/art_12.png differ
diff --git a/examples/source_image/art_13.png b/examples/source_image/art_13.png
new file mode 100644
index 0000000000000000000000000000000000000000..129374120f1f01580a9baa0f37d8bbbe904b2373
Binary files /dev/null and b/examples/source_image/art_13.png differ
diff --git a/examples/source_image/art_14.png b/examples/source_image/art_14.png
new file mode 100644
index 0000000000000000000000000000000000000000..0f0489bf7cebb41346f029421fdf41dc2e52519b
Binary files /dev/null and b/examples/source_image/art_14.png differ
diff --git a/examples/source_image/art_15.png b/examples/source_image/art_15.png
new file mode 100644
index 0000000000000000000000000000000000000000..a0af242a4b3e962aef8ce5c10a5026646509bfc6
Binary files /dev/null and b/examples/source_image/art_15.png differ
diff --git a/examples/source_image/art_16.png b/examples/source_image/art_16.png
new file mode 100644
index 0000000000000000000000000000000000000000..afb659b641b564a3d850229c67d014483516af67
--- /dev/null
+++ b/examples/source_image/art_16.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3f6d350055eea3abe35ee3fe9df80dcd99d8edae66ef4fc20bf06168bf189f25
+size 1480263
diff --git a/examples/source_image/art_17.png b/examples/source_image/art_17.png
new file mode 100644
index 0000000000000000000000000000000000000000..875a3e3c2e985efe7407b6c8fff99faa591b9811
--- /dev/null
+++ b/examples/source_image/art_17.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:05747bb45dcf271d9bb24344bd1bce0e0746d24ce4e13545b27ad40b50c3bfe7
+size 2092096
diff --git a/examples/source_image/art_18.png b/examples/source_image/art_18.png
new file mode 100644
index 0000000000000000000000000000000000000000..96358e0e542f66d1f4fd92acd092124e738fc6fe
Binary files /dev/null and b/examples/source_image/art_18.png differ
diff --git a/examples/source_image/art_19.png b/examples/source_image/art_19.png
new file mode 100644
index 0000000000000000000000000000000000000000..4f477a1ab58994e3cb4140b1a8ca59dcc428f387
Binary files /dev/null and b/examples/source_image/art_19.png differ
diff --git a/examples/source_image/art_2.png b/examples/source_image/art_2.png
new file mode 100644
index 0000000000000000000000000000000000000000..9560673430d461ad94980731ee0b404fcda32084
Binary files /dev/null and b/examples/source_image/art_2.png differ
diff --git a/examples/source_image/art_20.png b/examples/source_image/art_20.png
new file mode 100644
index 0000000000000000000000000000000000000000..de1ea5c975dbed93ce80c1aa70f6298703acf70f
Binary files /dev/null and b/examples/source_image/art_20.png differ
diff --git a/examples/source_image/art_3.png b/examples/source_image/art_3.png
new file mode 100644
index 0000000000000000000000000000000000000000..f2d3c117ed2d7074ec5427ebd1e68147e4476031
--- /dev/null
+++ b/examples/source_image/art_3.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:81be3a9cc605ab01cbf741330b406db5246e8bbbcb443ad43ffeca2ef161e005
+size 1353396
diff --git a/examples/source_image/art_4.png b/examples/source_image/art_4.png
new file mode 100644
index 0000000000000000000000000000000000000000..ce5fda1d95dd1d6d497648fbfb95dc53380d367e
--- /dev/null
+++ b/examples/source_image/art_4.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:ab322220d8eab1bfefdaedea91ca5d08a34258c1ab1e585a9b1c85b32968f983
+size 3625669
diff --git a/examples/source_image/art_5.png b/examples/source_image/art_5.png
new file mode 100644
index 0000000000000000000000000000000000000000..2726da0cb91b4ab9d54eef21efa653d2f8cda959
--- /dev/null
+++ b/examples/source_image/art_5.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:199217b4c839ed849577aedcad32f2bce934628b9783ba4654a93756b25e7896
+size 1228028
diff --git a/examples/source_image/art_6.png b/examples/source_image/art_6.png
new file mode 100644
index 0000000000000000000000000000000000000000..e9f6d8f272dc9bf971285667ecbe765ede41c967
Binary files /dev/null and b/examples/source_image/art_6.png differ
diff --git a/examples/source_image/art_7.png b/examples/source_image/art_7.png
new file mode 100644
index 0000000000000000000000000000000000000000..d8cc380aacb76a6ce9f5e41086bb1fb375a4e7db
Binary files /dev/null and b/examples/source_image/art_7.png differ
diff --git a/examples/source_image/art_8.png b/examples/source_image/art_8.png
new file mode 100644
index 0000000000000000000000000000000000000000..169035fba5a1ab690564e661e2e5ea95a5a71e87
--- /dev/null
+++ b/examples/source_image/art_8.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1d704497947c07ac16534299451fc0526acddf286c2ab4ceb48161ff6facc2af
+size 3119298
diff --git a/examples/source_image/art_9.png b/examples/source_image/art_9.png
new file mode 100644
index 0000000000000000000000000000000000000000..61a02dd4a57d382f215a73d635959ae45c208635
--- /dev/null
+++ b/examples/source_image/art_9.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:90f84739e2aa2388efaf0fac2b57a82df279b213a8dab9faa7af8ae7468b4e80
+size 1262963
diff --git a/examples/source_image/full3.png b/examples/source_image/full3.png
new file mode 100644
index 0000000000000000000000000000000000000000..40cd6d6d3c5b95c29d6648c2ba7d7e27c9781970
Binary files /dev/null and b/examples/source_image/full3.png differ
diff --git a/examples/source_image/full4.jpeg b/examples/source_image/full4.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..79f17f52123e8d173600e0df138a30e98ba2c6f3
Binary files /dev/null and b/examples/source_image/full4.jpeg differ
diff --git a/examples/source_image/full_body_1.png b/examples/source_image/full_body_1.png
new file mode 100644
index 0000000000000000000000000000000000000000..4fca65c949b7c7e7f7ed9459c473314a38be791f
Binary files /dev/null and b/examples/source_image/full_body_1.png differ
diff --git a/examples/source_image/full_body_2.png b/examples/source_image/full_body_2.png
new file mode 100644
index 0000000000000000000000000000000000000000..b7bc6228cb2f4e8c01af8d2f52bbbf62540e2412
Binary files /dev/null and b/examples/source_image/full_body_2.png differ
diff --git a/examples/source_image/happy.png b/examples/source_image/happy.png
new file mode 100644
index 0000000000000000000000000000000000000000..9d194ba9a03dfda0867703d54ea6233819c46a73
Binary files /dev/null and b/examples/source_image/happy.png differ
diff --git a/examples/source_image/happy1.png b/examples/source_image/happy1.png
new file mode 100644
index 0000000000000000000000000000000000000000..b702974cca1a648ec70efee776e484284b527c90
Binary files /dev/null and b/examples/source_image/happy1.png differ
diff --git a/examples/source_image/people_0.png b/examples/source_image/people_0.png
new file mode 100644
index 0000000000000000000000000000000000000000..8895eeb07a3e300b9bcfa3bb53e7a6a552182bc3
Binary files /dev/null and b/examples/source_image/people_0.png differ
diff --git a/examples/source_image/sad.png b/examples/source_image/sad.png
new file mode 100644
index 0000000000000000000000000000000000000000..6584467fdac971207883cdcd84b31da1dbc4dfa6
Binary files /dev/null and b/examples/source_image/sad.png differ
diff --git a/examples/source_image/sad1.png b/examples/source_image/sad1.png
new file mode 100644
index 0000000000000000000000000000000000000000..341e0cb70886995ecf72eebb4b8a4474ab7d287b
Binary files /dev/null and b/examples/source_image/sad1.png differ
diff --git a/inference.py b/inference.py
new file mode 100644
index 0000000000000000000000000000000000000000..a0b007901c9848ef8b3409607a4a73cc5a3a5ab9
--- /dev/null
+++ b/inference.py
@@ -0,0 +1,145 @@
+from glob import glob
+import shutil
+import torch
+from time import strftime
+import os, sys, time
+from argparse import ArgumentParser
+
+from src.utils.preprocess import CropAndExtract
+from src.test_audio2coeff import Audio2Coeff
+from src.facerender.animate import AnimateFromCoeff
+from src.generate_batch import get_data
+from src.generate_facerender_batch import get_facerender_data
+from src.utils.init_path import init_path
+
+def main(args):
+ #torch.backends.cudnn.enabled = False
+
+ pic_path = args.source_image
+ audio_path = args.driven_audio
+ save_dir = os.path.join(args.result_dir, strftime("%Y_%m_%d_%H.%M.%S"))
+ os.makedirs(save_dir, exist_ok=True)
+ pose_style = args.pose_style
+ device = args.device
+ batch_size = args.batch_size
+ input_yaw_list = args.input_yaw
+ input_pitch_list = args.input_pitch
+ input_roll_list = args.input_roll
+ ref_eyeblink = args.ref_eyeblink
+ ref_pose = args.ref_pose
+
+ current_root_path = os.path.split(sys.argv[0])[0]
+
+ sadtalker_paths = init_path(args.checkpoint_dir, os.path.join(current_root_path, 'src/config'), args.size, args.old_version, args.preprocess)
+
+ #init model
+ preprocess_model = CropAndExtract(sadtalker_paths, device)
+
+ audio_to_coeff = Audio2Coeff(sadtalker_paths, device)
+
+ animate_from_coeff = AnimateFromCoeff(sadtalker_paths, device)
+
+ #crop image and extract 3dmm from image
+ first_frame_dir = os.path.join(save_dir, 'first_frame_dir')
+ os.makedirs(first_frame_dir, exist_ok=True)
+ print('3DMM Extraction for source image')
+ first_coeff_path, crop_pic_path, crop_info = preprocess_model.generate(pic_path, first_frame_dir, args.preprocess,\
+ source_image_flag=True, pic_size=args.size)
+ if first_coeff_path is None:
+ print("Can't get the coeffs of the input")
+ return
+
+ if ref_eyeblink is not None:
+ ref_eyeblink_videoname = os.path.splitext(os.path.split(ref_eyeblink)[-1])[0]
+ ref_eyeblink_frame_dir = os.path.join(save_dir, ref_eyeblink_videoname)
+ os.makedirs(ref_eyeblink_frame_dir, exist_ok=True)
+ print('3DMM Extraction for the reference video providing eye blinking')
+ ref_eyeblink_coeff_path, _, _ = preprocess_model.generate(ref_eyeblink, ref_eyeblink_frame_dir, args.preprocess, source_image_flag=False)
+ else:
+ ref_eyeblink_coeff_path=None
+
+ if ref_pose is not None:
+ if ref_pose == ref_eyeblink:
+ ref_pose_coeff_path = ref_eyeblink_coeff_path
+ else:
+ ref_pose_videoname = os.path.splitext(os.path.split(ref_pose)[-1])[0]
+ ref_pose_frame_dir = os.path.join(save_dir, ref_pose_videoname)
+ os.makedirs(ref_pose_frame_dir, exist_ok=True)
+ print('3DMM Extraction for the reference video providing pose')
+ ref_pose_coeff_path, _, _ = preprocess_model.generate(ref_pose, ref_pose_frame_dir, args.preprocess, source_image_flag=False)
+ else:
+ ref_pose_coeff_path=None
+
+ #audio2ceoff
+ batch = get_data(first_coeff_path, audio_path, device, ref_eyeblink_coeff_path, still=args.still)
+ coeff_path = audio_to_coeff.generate(batch, save_dir, pose_style, ref_pose_coeff_path)
+
+ # 3dface render
+ if args.face3dvis:
+ from src.face3d.visualize import gen_composed_video
+ gen_composed_video(args, device, first_coeff_path, coeff_path, audio_path, os.path.join(save_dir, '3dface.mp4'))
+
+ #coeff2video
+ data = get_facerender_data(coeff_path, crop_pic_path, first_coeff_path, audio_path,
+ batch_size, input_yaw_list, input_pitch_list, input_roll_list,
+ expression_scale=args.expression_scale, still_mode=args.still, preprocess=args.preprocess, size=args.size)
+
+ result = animate_from_coeff.generate(data, save_dir, pic_path, crop_info, \
+ enhancer=args.enhancer, background_enhancer=args.background_enhancer, preprocess=args.preprocess, img_size=args.size)
+
+ shutil.move(result, save_dir+'.mp4')
+ print('The generated video is named:', save_dir+'.mp4')
+
+ if not args.verbose:
+ shutil.rmtree(save_dir)
+
+
+if __name__ == '__main__':
+
+ parser = ArgumentParser()
+ parser.add_argument("--driven_audio", default='./examples/driven_audio/bus_chinese.wav', help="path to driven audio")
+ parser.add_argument("--source_image", default='./examples/source_image/full_body_1.png', help="path to source image")
+ parser.add_argument("--ref_eyeblink", default=None, help="path to reference video providing eye blinking")
+ parser.add_argument("--ref_pose", default=None, help="path to reference video providing pose")
+ parser.add_argument("--checkpoint_dir", default='./checkpoints', help="path to output")
+ parser.add_argument("--result_dir", default='./results', help="path to output")
+ parser.add_argument("--pose_style", type=int, default=0, help="input pose style from [0, 46)")
+ parser.add_argument("--batch_size", type=int, default=2, help="the batch size of facerender")
+ parser.add_argument("--size", type=int, default=256, help="the image size of the facerender")
+ parser.add_argument("--expression_scale", type=float, default=1., help="the batch size of facerender")
+ parser.add_argument('--input_yaw', nargs='+', type=int, default=None, help="the input yaw degree of the user ")
+ parser.add_argument('--input_pitch', nargs='+', type=int, default=None, help="the input pitch degree of the user")
+ parser.add_argument('--input_roll', nargs='+', type=int, default=None, help="the input roll degree of the user")
+ parser.add_argument('--enhancer', type=str, default=None, help="Face enhancer, [gfpgan, RestoreFormer]")
+ parser.add_argument('--background_enhancer', type=str, default=None, help="background enhancer, [realesrgan]")
+ parser.add_argument("--cpu", dest="cpu", action="store_true")
+ parser.add_argument("--face3dvis", action="store_true", help="generate 3d face and 3d landmarks")
+ parser.add_argument("--still", action="store_true", help="can crop back to the original videos for the full body aniamtion")
+ parser.add_argument("--preprocess", default='crop', choices=['crop', 'extcrop', 'resize', 'full', 'extfull'], help="how to preprocess the images" )
+ parser.add_argument("--verbose",action="store_true", help="saving the intermedia output or not" )
+ parser.add_argument("--old_version",action="store_true", help="use the pth other than safetensor version" )
+
+
+ # net structure and parameters
+ parser.add_argument('--net_recon', type=str, default='resnet50', choices=['resnet18', 'resnet34', 'resnet50'], help='useless')
+ parser.add_argument('--init_path', type=str, default=None, help='Useless')
+ parser.add_argument('--use_last_fc',default=False, help='zero initialize the last fc')
+ parser.add_argument('--bfm_folder', type=str, default='./checkpoints/BFM_Fitting/')
+ parser.add_argument('--bfm_model', type=str, default='BFM_model_front.mat', help='bfm model')
+
+ # default renderer parameters
+ parser.add_argument('--focal', type=float, default=1015.)
+ parser.add_argument('--center', type=float, default=112.)
+ parser.add_argument('--camera_d', type=float, default=10.)
+ parser.add_argument('--z_near', type=float, default=5.)
+ parser.add_argument('--z_far', type=float, default=15.)
+
+ args = parser.parse_args()
+
+ if torch.cuda.is_available() and not args.cpu:
+ args.device = "cuda"
+ else:
+ args.device = "cpu"
+
+ main(args)
+
diff --git a/launcher.py b/launcher.py
new file mode 100644
index 0000000000000000000000000000000000000000..17ce9f1a18c3d563333bbb0eacc2922fb8524e3f
--- /dev/null
+++ b/launcher.py
@@ -0,0 +1,204 @@
+# this scripts installs necessary requirements and launches main program in webui.py
+# borrow from : https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/launch.py
+import subprocess
+import os
+import sys
+import importlib.util
+import shlex
+import platform
+import json
+
+python = sys.executable
+git = os.environ.get('GIT', "git")
+index_url = os.environ.get('INDEX_URL', "")
+stored_commit_hash = None
+skip_install = False
+dir_repos = "repositories"
+script_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+if 'GRADIO_ANALYTICS_ENABLED' not in os.environ:
+ os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
+
+
+def check_python_version():
+ is_windows = platform.system() == "Windows"
+ major = sys.version_info.major
+ minor = sys.version_info.minor
+ micro = sys.version_info.micro
+
+ if is_windows:
+ supported_minors = [10]
+ else:
+ supported_minors = [7, 8, 9, 10, 11]
+
+ if not (major == 3 and minor in supported_minors):
+
+ raise (f"""
+INCOMPATIBLE PYTHON VERSION
+This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}.
+If you encounter an error with "RuntimeError: Couldn't install torch." message,
+or any other error regarding unsuccessful package (library) installation,
+please downgrade (or upgrade) to the latest version of 3.10 Python
+and delete current Python and "venv" folder in WebUI's directory.
+You can download 3.10 Python from here: https://www.python.org/downloads/release/python-3109/
+{"Alternatively, use a binary release of WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases" if is_windows else ""}
+Use --skip-python-version-check to suppress this warning.
+""")
+
+
+def commit_hash():
+ global stored_commit_hash
+
+ if stored_commit_hash is not None:
+ return stored_commit_hash
+
+ try:
+ stored_commit_hash = run(f"{git} rev-parse HEAD").strip()
+ except Exception:
+ stored_commit_hash = "