From 91b7301f32c9c8dd331748c5c558c51c4a115f94 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 31 May 2023 21:03:44 +0200 Subject: [PATCH] Proper exiting via ctrl+c --- core/processor.py | 10 +++++----- run.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/processor.py b/core/processor.py index d604d68..f601e89 100644 --- a/core/processor.py +++ b/core/processor.py @@ -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): diff --git a/run.py b/run.py index 3775973..2f24ce6 100755 --- a/run.py +++ b/run.py @@ -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')