Proper exiting via ctrl+c

This commit is contained in:
henryruhs 2023-05-31 21:03:44 +02:00
parent 7c385cc4f4
commit 91b7301f32
2 changed files with 7 additions and 5 deletions

View File

@ -18,7 +18,7 @@ def get_face_swapper():
def process_video(source_img, frame_paths):
source_face = get_face(cv2.imread(source_img))
with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]') as pbar:
with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]') as progress:
for frame_path in frame_paths:
frame = cv2.imread(frame_path)
try:
@ -26,13 +26,13 @@ def process_video(source_img, frame_paths):
if face:
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
cv2.imwrite(frame_path, result)
pbar.set_postfix(status='.', refresh=True)
progress.set_postfix(status='.', refresh=True)
else:
pbar.set_postfix(status='S', refresh=True)
progress.set_postfix(status='S', refresh=True)
except Exception:
pbar.set_postfix(status='E', refresh=True)
progress.set_postfix(status='E', refresh=True)
pass
pbar.update(1)
progress.update(1)
def process_img(source_img, target_path, output_file):

2
run.py
View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import platform
import signal
import sys
import time
import shutil
@ -30,6 +31,7 @@ if 'ROCMExecutionProvider' in core.globals.providers:
pool = None
args = {}
signal.signal(signal.SIGINT, lambda signal_number, frame: quit())
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--face', help='use this face', dest='source_img')
parser.add_argument('-t', '--target', help='replace this face', dest='target_path')