Spaces:
Paused
Paused
Upload 8 files
Browse files- .pre-commit-config.yaml +35 -0
- .style.yapf +3 -0
- requirements.txt +5 -0
- run_faceswapper.py +106 -0
- run_posetransfer.py +103 -0
- setup.py +21 -0
- test.sh +13 -0
- web_ui.py +194 -0
.pre-commit-config.yaml
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
repos:
|
| 2 |
+
- repo: local
|
| 3 |
+
hooks:
|
| 4 |
+
- id: yapf
|
| 5 |
+
name: yapf
|
| 6 |
+
entry: yapf --style .style.yapf -i
|
| 7 |
+
language: system
|
| 8 |
+
files: \.py$
|
| 9 |
+
|
| 10 |
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
| 11 |
+
rev: a11d9314b22d8f8c7556443875b731ef05965464
|
| 12 |
+
hooks:
|
| 13 |
+
- id: check-merge-conflict
|
| 14 |
+
- id: check-symlinks
|
| 15 |
+
- id: end-of-file-fixer
|
| 16 |
+
- id: trailing-whitespace
|
| 17 |
+
- id: detect-private-key
|
| 18 |
+
- id: check-added-large-files
|
| 19 |
+
|
| 20 |
+
- repo: local
|
| 21 |
+
hooks:
|
| 22 |
+
- id: flake8
|
| 23 |
+
name: flake8
|
| 24 |
+
entry: flake8 --count --select=E9,F63,F7,F82 --show-source --statistics
|
| 25 |
+
language: system
|
| 26 |
+
files: \.py$
|
| 27 |
+
|
| 28 |
+
- repo: local
|
| 29 |
+
hooks:
|
| 30 |
+
- id: clang-format-with-version-check
|
| 31 |
+
name: clang-format
|
| 32 |
+
description: Format files with ClangFormat
|
| 33 |
+
entry: bash .clang_format.hook -style=Google -i
|
| 34 |
+
language: system
|
| 35 |
+
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$
|
.style.yapf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[style]
|
| 2 |
+
based_on_style = pep8
|
| 3 |
+
column_limit = 80
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
moviepy
|
| 2 |
+
gradio>=4.8
|
| 3 |
+
insightface
|
| 4 |
+
flake8
|
| 5 |
+
yapf
|
run_faceswapper.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from dofaker import FaceSwapper
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def parse_args():
|
| 6 |
+
parser = argparse.ArgumentParser(description='running face swap')
|
| 7 |
+
parser.add_argument('--source',
|
| 8 |
+
help='select an image or video to be swapped',
|
| 9 |
+
dest='source',
|
| 10 |
+
required=True)
|
| 11 |
+
parser.add_argument('--dst_face_paths',
|
| 12 |
+
help='select images in source to be swapped',
|
| 13 |
+
dest='dst_face_paths',
|
| 14 |
+
nargs='+',
|
| 15 |
+
default=None)
|
| 16 |
+
parser.add_argument(
|
| 17 |
+
'--src_face_paths',
|
| 18 |
+
help='select images to replace dst_faces in source image or video.',
|
| 19 |
+
dest='src_face_paths',
|
| 20 |
+
nargs='+',
|
| 21 |
+
required=True)
|
| 22 |
+
parser.add_argument('--output_dir',
|
| 23 |
+
help='output directory',
|
| 24 |
+
dest='output_dir',
|
| 25 |
+
default='output')
|
| 26 |
+
parser.add_argument('--det_model_name',
|
| 27 |
+
help='detection model name for insightface',
|
| 28 |
+
dest='det_model_name',
|
| 29 |
+
default='buffalo_l')
|
| 30 |
+
parser.add_argument('--det_model_dir',
|
| 31 |
+
help='detection model dir for insightface',
|
| 32 |
+
dest='det_model_dir',
|
| 33 |
+
default='weights/models')
|
| 34 |
+
parser.add_argument('--swap_model_name',
|
| 35 |
+
help='swap model name',
|
| 36 |
+
dest='swap_model_name',
|
| 37 |
+
default='inswapper')
|
| 38 |
+
parser.add_argument('--image_sr_model',
|
| 39 |
+
help='image super resolution model',
|
| 40 |
+
dest='image_sr_model',
|
| 41 |
+
default='bsrgan')
|
| 42 |
+
parser.add_argument('--face_swap_model_dir',
|
| 43 |
+
help='swap model path',
|
| 44 |
+
dest='face_swap_model_dir',
|
| 45 |
+
default='weights/models')
|
| 46 |
+
parser.add_argument('--image_sr_model_dir',
|
| 47 |
+
help='image super resolution model dir',
|
| 48 |
+
dest='image_sr_model_dir',
|
| 49 |
+
default='weights/models')
|
| 50 |
+
parser.add_argument('--face_enhance_name',
|
| 51 |
+
help='face enhance model',
|
| 52 |
+
dest='face_enhance_name',
|
| 53 |
+
default='gfpgan')
|
| 54 |
+
parser.add_argument('--face_enhance_model_dir',
|
| 55 |
+
help='face enhance model dir',
|
| 56 |
+
dest='face_enhance_model_dir',
|
| 57 |
+
default='weights/models')
|
| 58 |
+
parser.add_argument('--face_sim_thre',
|
| 59 |
+
help='similarity of face embedding threshold',
|
| 60 |
+
dest='face_sim_thre',
|
| 61 |
+
default=0.5)
|
| 62 |
+
parser.add_argument('--log_iters',
|
| 63 |
+
help='print log intervals',
|
| 64 |
+
dest='log_iters',
|
| 65 |
+
default=10,
|
| 66 |
+
type=int)
|
| 67 |
+
parser.add_argument('--use_enhancer',
|
| 68 |
+
help='whether use face enhance model',
|
| 69 |
+
dest='use_enhancer',
|
| 70 |
+
action='store_true')
|
| 71 |
+
parser.add_argument('--use_sr',
|
| 72 |
+
help='whether use image super resolution model',
|
| 73 |
+
dest='use_sr',
|
| 74 |
+
action='store_true')
|
| 75 |
+
parser.add_argument('--sr_scale',
|
| 76 |
+
help='image super resolution scale',
|
| 77 |
+
dest='sr_scale',
|
| 78 |
+
default=1,
|
| 79 |
+
type=float)
|
| 80 |
+
return parser.parse_args()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == '__main__':
|
| 84 |
+
args = parse_args()
|
| 85 |
+
faker = FaceSwapper(
|
| 86 |
+
face_det_model=args.det_model_name,
|
| 87 |
+
face_det_model_dir=args.det_model_dir,
|
| 88 |
+
face_swap_model=args.swap_model_name,
|
| 89 |
+
face_swap_model_dir=args.face_swap_model_dir,
|
| 90 |
+
image_sr_model=args.image_sr_model,
|
| 91 |
+
image_sr_model_dir=args.image_sr_model_dir,
|
| 92 |
+
face_enhance_model=args.face_enhance_name,
|
| 93 |
+
face_enhance_model_dir=args.face_enhance_model_dir,
|
| 94 |
+
face_sim_thre=args.face_sim_thre,
|
| 95 |
+
log_iters=args.log_iters,
|
| 96 |
+
use_enhancer=args.use_enhancer,
|
| 97 |
+
use_sr=args.use_sr,
|
| 98 |
+
scale=args.sr_scale,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
faker.run(
|
| 102 |
+
input_path=args.source,
|
| 103 |
+
dst_face_paths=args.dst_face_paths,
|
| 104 |
+
src_face_paths=args.src_face_paths,
|
| 105 |
+
output_dir=args.output_dir,
|
| 106 |
+
)
|
run_posetransfer.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from dofaker import PoseSwapper
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def parse_args():
|
| 6 |
+
parser = argparse.ArgumentParser(description='running face swap')
|
| 7 |
+
parser.add_argument('--source',
|
| 8 |
+
help='select an image or video to be swapped',
|
| 9 |
+
dest='source',
|
| 10 |
+
required=True)
|
| 11 |
+
parser.add_argument('--target',
|
| 12 |
+
help='the target pose image',
|
| 13 |
+
dest='target',
|
| 14 |
+
required=True)
|
| 15 |
+
parser.add_argument('--output_dir',
|
| 16 |
+
help='output directory',
|
| 17 |
+
dest='output_dir',
|
| 18 |
+
default='output')
|
| 19 |
+
parser.add_argument('--pose_estimator_name',
|
| 20 |
+
help='pose estimator name',
|
| 21 |
+
dest='pose_estimator_name',
|
| 22 |
+
default='openpose_body')
|
| 23 |
+
parser.add_argument('--pose_estimator_model_dir',
|
| 24 |
+
help='pose estimator model dir',
|
| 25 |
+
dest='pose_estimator_model_dir',
|
| 26 |
+
default='weights/models')
|
| 27 |
+
parser.add_argument('--pose_transfer_name',
|
| 28 |
+
help='pose transfer name',
|
| 29 |
+
dest='pose_transfer_name',
|
| 30 |
+
default='pose_transfer')
|
| 31 |
+
parser.add_argument('--pose_transfer_model_dir',
|
| 32 |
+
help='pose transfer model dir',
|
| 33 |
+
dest='pose_transfer_model_dir',
|
| 34 |
+
default='weights/models')
|
| 35 |
+
parser.add_argument('--det_model_name',
|
| 36 |
+
help='detection model name for insightface',
|
| 37 |
+
dest='det_model_name',
|
| 38 |
+
default='buffalo_l')
|
| 39 |
+
parser.add_argument('--det_model_dir',
|
| 40 |
+
help='detection model dir for insightface',
|
| 41 |
+
dest='det_model_dir',
|
| 42 |
+
default='weights/models')
|
| 43 |
+
parser.add_argument('--image_sr_model',
|
| 44 |
+
help='image super resolution model',
|
| 45 |
+
dest='image_sr_model',
|
| 46 |
+
default='bsrgan')
|
| 47 |
+
parser.add_argument('--image_sr_model_dir',
|
| 48 |
+
help='image super resolution model dir',
|
| 49 |
+
dest='image_sr_model_dir',
|
| 50 |
+
default='weights/models')
|
| 51 |
+
parser.add_argument('--face_enhance_name',
|
| 52 |
+
help='face enhance model',
|
| 53 |
+
dest='face_enhance_name',
|
| 54 |
+
default='gfpgan')
|
| 55 |
+
parser.add_argument('--face_enhance_model_dir',
|
| 56 |
+
help='face enhance model dir',
|
| 57 |
+
dest='face_enhance_model_dir',
|
| 58 |
+
default='weights/models')
|
| 59 |
+
parser.add_argument('--log_iters',
|
| 60 |
+
help='print log intervals',
|
| 61 |
+
dest='log_iters',
|
| 62 |
+
default=10,
|
| 63 |
+
type=int)
|
| 64 |
+
parser.add_argument('--use_enhancer',
|
| 65 |
+
help='whether use face enhance model',
|
| 66 |
+
dest='use_enhancer',
|
| 67 |
+
action='store_true')
|
| 68 |
+
parser.add_argument('--use_sr',
|
| 69 |
+
help='whether use image super resolution model',
|
| 70 |
+
dest='use_sr',
|
| 71 |
+
action='store_true')
|
| 72 |
+
parser.add_argument('--sr_scale',
|
| 73 |
+
help='image super resolution scale',
|
| 74 |
+
dest='sr_scale',
|
| 75 |
+
default=1,
|
| 76 |
+
type=float)
|
| 77 |
+
return parser.parse_args()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == '__main__':
|
| 81 |
+
args = parse_args()
|
| 82 |
+
faker = PoseSwapper(
|
| 83 |
+
pose_estimator_name=args.pose_estimator_name,
|
| 84 |
+
pose_estimator_model_dir=args.pose_estimator_model_dir,
|
| 85 |
+
pose_transfer_name=args.pose_transfer_name,
|
| 86 |
+
pose_transfer_model_dir=args.pose_transfer_model_dir,
|
| 87 |
+
face_det_model=args.det_model_name,
|
| 88 |
+
face_det_model_dir=args.det_model_dir,
|
| 89 |
+
image_sr_model=args.image_sr_model,
|
| 90 |
+
image_sr_model_dir=args.image_sr_model_dir,
|
| 91 |
+
face_enhance_name=args.face_enhance_name,
|
| 92 |
+
face_enhance_model_dir=args.face_enhance_model_dir,
|
| 93 |
+
log_iters=args.log_iters,
|
| 94 |
+
use_enhancer=args.use_enhancer,
|
| 95 |
+
use_sr=args.use_sr,
|
| 96 |
+
scale=args.sr_scale,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
faker.run(
|
| 100 |
+
input_path=args.source,
|
| 101 |
+
target_path=args.target,
|
| 102 |
+
output_dir=args.output_dir,
|
| 103 |
+
)
|
setup.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import setup, find_packages
|
| 2 |
+
|
| 3 |
+
with open('requirements.txt') as file:
|
| 4 |
+
REQUIRED_PACKAGES = file.read()
|
| 5 |
+
|
| 6 |
+
setup(name='dofaker',
|
| 7 |
+
version='0.1',
|
| 8 |
+
keywords=('face swap'),
|
| 9 |
+
description='A simple face swap tool',
|
| 10 |
+
url='https://github.com/justld/dofaker',
|
| 11 |
+
author='justld',
|
| 12 |
+
author_email='[email protected]',
|
| 13 |
+
packages=find_packages(),
|
| 14 |
+
include_package_data=True,
|
| 15 |
+
platforms='any',
|
| 16 |
+
install_requires=REQUIRED_PACKAGES,
|
| 17 |
+
scripts=[],
|
| 18 |
+
license='GPL 3.0',
|
| 19 |
+
entry_points={'console_scripts': [
|
| 20 |
+
'dofaker = web_ui:main',
|
| 21 |
+
]})
|
test.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# python run_faceswapper.py --source docs/test/multi.png --dst_face_paths docs/test/dst1.png --src_face_paths docs/test/trump.jpg
|
| 2 |
+
|
| 3 |
+
# python run_faceswapper.py --source docs/test/multi.png --dst_face_paths docs/test/dst1.png docs/test/dst2.png --src_face_paths docs/test/trump.jpg docs/test/taitan.jpeg
|
| 4 |
+
|
| 5 |
+
# python run_faceswapper.py --source docs/test/multi.png --dst_face_paths docs/test/dst1.png docs/test/dst2.png --src_face_paths docs/test/trump.jpg docs/test/taitan.jpeg --use_enhancer
|
| 6 |
+
|
| 7 |
+
python run_faceswapper.py --source docs/test/multi.png --dst_face_paths docs/test/dst1.png docs/test/dst2.png --src_face_paths docs/test/trump.jpg docs/test/taitan.jpeg --use_enhancer --use_sr --sr_scale 2.0
|
| 8 |
+
|
| 9 |
+
# python run_posetransfer.py --source docs/test/condition.jpg --target docs/test/target_pose_reference.jpg
|
| 10 |
+
|
| 11 |
+
# python run_posetransfer.py --source docs/test/condition.jpg --target docs/test/target_pose_reference.jpg --use_enhancer
|
| 12 |
+
|
| 13 |
+
python run_posetransfer.py --source docs/test/condition.jpg --target docs/test/target_pose_reference.jpg --use_enhancer --use_sr --sr_scale 2.0
|
web_ui.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from dofaker import FaceSwapper, PoseSwapper
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def parse_args():
|
| 8 |
+
parser = argparse.ArgumentParser(description='running face swap')
|
| 9 |
+
parser.add_argument(
|
| 10 |
+
'--inbrowser',
|
| 11 |
+
help=
|
| 12 |
+
'whether to automatically launch the interface in a new tab on the default browser.',
|
| 13 |
+
dest='inbrowser',
|
| 14 |
+
default=True)
|
| 15 |
+
parser.add_argument(
|
| 16 |
+
'--server_port',
|
| 17 |
+
help=
|
| 18 |
+
'will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT. If None, will search for an available port starting at 7860.',
|
| 19 |
+
dest='server_port',
|
| 20 |
+
type=int,
|
| 21 |
+
default=None)
|
| 22 |
+
return parser.parse_args()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def swap_face(input_path, dst_path, src_path, use_enhancer, use_sr, scale,
|
| 26 |
+
face_sim_thre):
|
| 27 |
+
faker = FaceSwapper(use_enhancer=use_enhancer,
|
| 28 |
+
use_sr=use_sr,
|
| 29 |
+
scale=scale,
|
| 30 |
+
face_sim_thre=face_sim_thre)
|
| 31 |
+
output_path = faker.run(input_path, dst_path, src_path)
|
| 32 |
+
return output_path
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def swap_pose(input_path, target_path, use_enhancer, use_sr, scale):
|
| 36 |
+
faker = PoseSwapper(use_enhancer=use_enhancer, use_sr=use_sr, scale=scale)
|
| 37 |
+
output_path = faker.run(input_path, target_path)
|
| 38 |
+
return output_path
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def main():
|
| 42 |
+
args = parse_args()
|
| 43 |
+
|
| 44 |
+
with gr.Blocks(title='DoFaker') as web_ui:
|
| 45 |
+
gr.Markdown('DoFaker: Face Swap and pose swap web ui')
|
| 46 |
+
with gr.Tab('FaceSwapper'):
|
| 47 |
+
gr.Markdown('DoFaker: Face Swap Web UI')
|
| 48 |
+
with gr.Tab('Image'):
|
| 49 |
+
with gr.Row():
|
| 50 |
+
with gr.Column():
|
| 51 |
+
gr.Markdown('The source image to be swapped')
|
| 52 |
+
image_input = gr.Image(type='filepath')
|
| 53 |
+
with gr.Row():
|
| 54 |
+
with gr.Column():
|
| 55 |
+
gr.Markdown(
|
| 56 |
+
'target face included in source image')
|
| 57 |
+
dst_face_image = gr.Image(type='filepath')
|
| 58 |
+
with gr.Column():
|
| 59 |
+
gr.Markdown(
|
| 60 |
+
'source face to replace target face')
|
| 61 |
+
src_face_image = gr.Image(type='filepath')
|
| 62 |
+
|
| 63 |
+
with gr.Column():
|
| 64 |
+
output_image = gr.Image(type='filepath')
|
| 65 |
+
use_enhancer = gr.Checkbox(
|
| 66 |
+
label="face enhance",
|
| 67 |
+
info="Whether use face enhance model.")
|
| 68 |
+
with gr.Row():
|
| 69 |
+
use_sr = gr.Checkbox(
|
| 70 |
+
label="super resolution",
|
| 71 |
+
info="Whether use image resolution model.")
|
| 72 |
+
scale = gr.Number(
|
| 73 |
+
value=1, label='image super resolution scale')
|
| 74 |
+
with gr.Row():
|
| 75 |
+
face_sim_thre = gr.Number(
|
| 76 |
+
value=0.6,
|
| 77 |
+
label='face similarity threshold',
|
| 78 |
+
minimum=0.0,
|
| 79 |
+
maximum=1.0)
|
| 80 |
+
convert_button = gr.Button('Swap')
|
| 81 |
+
convert_button.click(fn=swap_face,
|
| 82 |
+
inputs=[
|
| 83 |
+
image_input, dst_face_image,
|
| 84 |
+
src_face_image, use_enhancer,
|
| 85 |
+
use_sr, scale, face_sim_thre
|
| 86 |
+
],
|
| 87 |
+
outputs=[output_image],
|
| 88 |
+
api_name='image swap')
|
| 89 |
+
|
| 90 |
+
with gr.Tab('Video'):
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column():
|
| 93 |
+
gr.Markdown('The source video to be swapped')
|
| 94 |
+
video_input = gr.Video()
|
| 95 |
+
with gr.Row():
|
| 96 |
+
with gr.Column():
|
| 97 |
+
gr.Markdown(
|
| 98 |
+
'target face included in source image')
|
| 99 |
+
dst_face_image = gr.Image(type='filepath')
|
| 100 |
+
with gr.Column():
|
| 101 |
+
gr.Markdown(
|
| 102 |
+
'source face to replace target face')
|
| 103 |
+
src_face_image = gr.Image(type='filepath')
|
| 104 |
+
|
| 105 |
+
with gr.Column():
|
| 106 |
+
output_video = gr.Video()
|
| 107 |
+
use_enhancer = gr.Checkbox(
|
| 108 |
+
label="face enhance",
|
| 109 |
+
info="Whether use face enhance model.")
|
| 110 |
+
with gr.Row():
|
| 111 |
+
use_sr = gr.Checkbox(
|
| 112 |
+
label="super resolution",
|
| 113 |
+
info="Whether use image resolution model.")
|
| 114 |
+
scale = gr.Number(
|
| 115 |
+
value=1, label='image super resolution scale')
|
| 116 |
+
with gr.Row():
|
| 117 |
+
face_sim_thre = gr.Number(
|
| 118 |
+
value=0.6,
|
| 119 |
+
label='face similarity threshold',
|
| 120 |
+
minimum=0.0,
|
| 121 |
+
maximum=1.0)
|
| 122 |
+
convert_button = gr.Button('Swap')
|
| 123 |
+
convert_button.click(fn=swap_face,
|
| 124 |
+
inputs=[
|
| 125 |
+
video_input, dst_face_image,
|
| 126 |
+
src_face_image, use_enhancer,
|
| 127 |
+
use_sr, scale, face_sim_thre
|
| 128 |
+
],
|
| 129 |
+
outputs=[output_video],
|
| 130 |
+
api_name='video swap')
|
| 131 |
+
|
| 132 |
+
with gr.Tab('PoseSwapper'):
|
| 133 |
+
gr.Markdown('DoFaker: Pose Swap Web UI')
|
| 134 |
+
with gr.Tab('Image'):
|
| 135 |
+
with gr.Row():
|
| 136 |
+
with gr.Column():
|
| 137 |
+
gr.Markdown('The source image to be swapped')
|
| 138 |
+
image_input = gr.Image(type='filepath')
|
| 139 |
+
gr.Markdown('The target image with pose')
|
| 140 |
+
target = gr.Image(type='filepath')
|
| 141 |
+
|
| 142 |
+
with gr.Column():
|
| 143 |
+
output_image = gr.Image(type='filepath')
|
| 144 |
+
use_enhancer = gr.Checkbox(
|
| 145 |
+
label="face enhance",
|
| 146 |
+
info="Whether use face enhance model.")
|
| 147 |
+
with gr.Row():
|
| 148 |
+
use_sr = gr.Checkbox(
|
| 149 |
+
label="super resolution",
|
| 150 |
+
info="Whether use image resolution model.")
|
| 151 |
+
scale = gr.Number(
|
| 152 |
+
value=1, label='image super resolution scale')
|
| 153 |
+
convert_button = gr.Button('Swap')
|
| 154 |
+
convert_button.click(fn=swap_pose,
|
| 155 |
+
inputs=[
|
| 156 |
+
image_input, target,
|
| 157 |
+
use_enhancer, use_sr, scale
|
| 158 |
+
],
|
| 159 |
+
outputs=[output_image],
|
| 160 |
+
api_name='image swap')
|
| 161 |
+
|
| 162 |
+
# with gr.Tab('Video'):
|
| 163 |
+
# with gr.Row():
|
| 164 |
+
# with gr.Column():
|
| 165 |
+
# gr.Markdown('The source video to be swapped')
|
| 166 |
+
# video_input = gr.Image(type='filepath')
|
| 167 |
+
# gr.Markdown('The target image with pose')
|
| 168 |
+
# target = gr.Video()
|
| 169 |
+
|
| 170 |
+
# with gr.Column():
|
| 171 |
+
# output_video = gr.Video()
|
| 172 |
+
# use_enhancer = gr.Checkbox(
|
| 173 |
+
# label="face enhance",
|
| 174 |
+
# info="Whether use face enhance model.")
|
| 175 |
+
# with gr.Row():
|
| 176 |
+
# use_sr = gr.Checkbox(
|
| 177 |
+
# label="super resolution",
|
| 178 |
+
# info="Whether use image resolution model.")
|
| 179 |
+
# scale = gr.Number(value=1,
|
| 180 |
+
# label='image super resolution scale')
|
| 181 |
+
# convert_button = gr.Button('Swap')
|
| 182 |
+
# convert_button.click(fn=swap_pose,
|
| 183 |
+
# inputs=[
|
| 184 |
+
# video_input, target, use_enhancer,
|
| 185 |
+
# use_sr, scale
|
| 186 |
+
# ],
|
| 187 |
+
# outputs=[output_video],
|
| 188 |
+
# api_name='video swap')
|
| 189 |
+
|
| 190 |
+
web_ui.launch(inbrowser=args.inbrowser, server_port=args.server_port)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
if __name__ == '__main__':
|
| 194 |
+
main()
|