From 7abb42724e334c1da502ac4032b2862dda06c99c Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 31 May 2023 10:32:40 +0200 Subject: [PATCH 1/3] Introduce lint pipeline and fix some minor issues flake8 complained about --- .flake8 | 2 ++ .github/workflows/ci.yml | 16 ++++++++++++++++ core/globals.py | 1 - core/processor.py | 3 +-- core/utils.py | 4 ++-- run.py | 8 ++++---- 6 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/ci.yml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..cc99296 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +select = E3, E4, F \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1d6de8c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: ci + +on: [ push, pull_request ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - run: pip install flake8 + - run: flake8 run.py core diff --git a/core/globals.py b/core/globals.py index 65d3283..3525c9d 100644 --- a/core/globals.py +++ b/core/globals.py @@ -1,4 +1,3 @@ -import torch import onnxruntime use_gpu = False diff --git a/core/processor.py b/core/processor.py index 398431d..26cb3df 100644 --- a/core/processor.py +++ b/core/processor.py @@ -3,7 +3,6 @@ import os import cv2 import insightface from core.config import get_face -from core.utils import rreplace FACE_SWAPPER = None @@ -28,7 +27,7 @@ def process_video(source_img, frame_paths): print('.', end='', flush=True) else: print('S', end='', flush=True) - except Exception as e: + except Exception: print('E', end='', flush=True) pass diff --git a/core/utils.py b/core/utils.py index 66dab65..419d178 100644 --- a/core/utils.py +++ b/core/utils.py @@ -47,11 +47,11 @@ def extract_frames(input_path, output_dir): def add_audio(output_dir, target_path, keep_frames, output_file): video = target_path.split("/")[-1] video_name = video.split(".")[0] - save_to = output_file if output_file else output_dir + f"/swapped-" + video_name + ".mp4" + save_to = output_file if output_file else output_dir + "/swapped-" + video_name + ".mp4" save_to_ff, output_dir_ff = path(save_to), path(output_dir) os.system(f'ffmpeg -i "{output_dir_ff}{sep}output.mp4" -i "{output_dir_ff}{sep}{video}" -c:v copy -map 0:v:0 -map 1:a:0 -y "{save_to_ff}"') if not os.path.isfile(save_to): - shutil.move(output_dir + f"/output.mp4", save_to) + shutil.move(output_dir + "/output.mp4", save_to) if not keep_frames: shutil.rmtree(output_dir) diff --git a/run.py b/run.py index af45389..6449de9 100644 --- a/run.py +++ b/run.py @@ -58,7 +58,7 @@ def limit_resources(): def pre_check(): if sys.version_info < (3, 8): - quit(f'Python version is not supported - please upgrade to 3.8 or higher') + quit('Python version is not supported - please upgrade to 3.8 or higher') if not shutil.which('ffmpeg'): quit('ffmpeg is not installed!') model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'inswapper_128.onnx') @@ -72,7 +72,7 @@ def pre_check(): if not torch.cuda.is_available() or not CUDA_VERSION: quit("You are using --gpu flag but CUDA isn't available or properly installed on your system.") if CUDA_VERSION > '11.8': - quit(f"CUDA version {CUDA_VERSION} is not supported - please downgrade to 11.8.") + quit(f"CUDA version {CUDA_VERSION} is not supported - please downgrade to 11.8") if CUDA_VERSION < '11.4': quit(f"CUDA version {CUDA_VERSION} is not supported - please upgrade to 11.8") if CUDNN_VERSION < 8220: @@ -179,7 +179,7 @@ def start(): print("\n[WARNING] Please select a video/image to swap face in.") return if not args['output_file']: - args['output_file'] = rreplace(args['target_path'], "/", "/swapped-", 1) if "/" in target_path else "swapped-"+target_path + args['output_file'] = rreplace(args['target_path'], "/", "/swapped-", 1) if "/" in target_path else "swapped-" + target_path global pool pool = mp.Pool(args['cores_count']) target_path = args['target_path'] @@ -206,7 +206,7 @@ def start(): status("extracting frames...") extract_frames(target_path, output_dir) args['frame_paths'] = tuple(sorted( - glob.glob(output_dir + f"/*.png"), + glob.glob(output_dir + "/*.png"), key=lambda x: int(x.split(sep)[-1].replace(".png", "")) )) status("swapping in progress...") From a8317003a84f52562a630d42e2ef403f6cde3787 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 31 May 2023 11:00:35 +0200 Subject: [PATCH 2/3] Add chmod +x --- run.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 run.py diff --git a/run.py b/run.py old mode 100644 new mode 100755 From ef28e3ad7fbec03c6c3451c25122081baf5df9ed Mon Sep 17 00:00:00 2001 From: Somdev Sangwan Date: Wed, 31 May 2023 14:43:21 +0530 Subject: [PATCH 3/3] fix target_path undefined --- run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run.py b/run.py index 6449de9..e169f39 100755 --- a/run.py +++ b/run.py @@ -179,7 +179,8 @@ def start(): print("\n[WARNING] Please select a video/image to swap face in.") return if not args['output_file']: - args['output_file'] = rreplace(args['target_path'], "/", "/swapped-", 1) if "/" in target_path else "swapped-" + target_path + target_path = args['target_path'] + args['output_file'] = rreplace(target_path, "/", "/swapped-", 1) if "/" in target_path else "swapped-" + target_path global pool pool = mp.Pool(args['cores_count']) target_path = args['target_path']