Introduce lint pipeline and fix some minor issues flake8 complained about

This commit is contained in:
henryruhs 2023-05-31 10:32:40 +02:00
parent 4867f356ef
commit 7abb42724e
6 changed files with 25 additions and 9 deletions

2
.flake8 Normal file
View File

@ -0,0 +1,2 @@
[flake8]
select = E3, E4, F

16
.github/workflows/ci.yml vendored Normal file
View File

@ -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

View File

@ -1,4 +1,3 @@
import torch
import onnxruntime
use_gpu = False

View File

@ -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

View File

@ -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)

8
run.py
View File

@ -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...")