diff --git a/roop/core.py b/roop/core.py index 23a0883d6..5f4a32dfb 100755 --- a/roop/core.py +++ b/roop/core.py @@ -57,8 +57,8 @@ def parse_args() -> None: roop.globals.source_path = args.source_path roop.globals.target_path = args.target_path - roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, args.output_path) # type: ignore - roop.globals.headless = roop.globals.source_path and roop.globals.target_path and roop.globals.output_path + roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, args.output_path) + roop.globals.headless = roop.globals.source_path is None and roop.globals.target_path is None and roop.globals.output_path is None roop.globals.frame_processors = args.frame_processor roop.globals.keep_fps = args.keep_fps roop.globals.keep_frames = args.keep_frames diff --git a/roop/globals.py b/roop/globals.py index f7c68e650..3eca8d0d0 100644 --- a/roop/globals.py +++ b/roop/globals.py @@ -1,22 +1,22 @@ -from typing import List +from typing import List, Optional -source_path = None -target_path = None -output_path = None -headless = None +source_path: Optional[str] = None +target_path: Optional[str] = None +output_path: Optional[str] = None +headless: Optional[bool] = None frame_processors: List[str] = [] -keep_fps = None -keep_frames = None -skip_audio = None -many_faces = None -reference_face_position = None -reference_frame_number = None -similar_face_distance = None -temp_frame_format = None -temp_frame_quality = None -output_video_encoder = None -output_video_quality = None -max_memory = None +keep_fps: Optional[bool] = None +keep_frames: Optional[bool] = None +skip_audio: Optional[bool] = None +many_faces: Optional[bool] = None +reference_face_position: Optional[int] = None +reference_frame_number: Optional[int] = None +similar_face_distance: Optional[float] = None +temp_frame_format: Optional[str] = None +temp_frame_quality: Optional[int] = None +output_video_encoder: Optional[str] = None +output_video_quality: Optional[int] = None +max_memory: Optional[int] = None execution_providers: List[str] = [] -execution_threads = None -log_level = 'error' +execution_threads: Optional[int] = None +log_level: str = 'error' diff --git a/roop/processors/frame/face_swapper.py b/roop/processors/frame/face_swapper.py index 7824d9cf0..b8072076f 100644 --- a/roop/processors/frame/face_swapper.py +++ b/roop/processors/frame/face_swapper.py @@ -75,10 +75,7 @@ def process_frame(source_face: Face, reference_face: Face, temp_frame: Frame) -> def process_frames(source_path: str, temp_frame_paths: List[str], update: Callable[[], None]) -> None: source_face = get_one_face(cv2.imread(source_path)) - if roop.globals.many_faces: - reference_face = None - else: - reference_face = get_face_reference() + reference_face = None if roop.globals.many_faces else get_face_reference() for temp_frame_path in temp_frame_paths: temp_frame = cv2.imread(temp_frame_path) result = process_frame(source_face, reference_face, temp_frame) @@ -90,10 +87,7 @@ def process_frames(source_path: str, temp_frame_paths: List[str], update: Callab def process_image(source_path: str, target_path: str, output_path: str) -> None: source_face = get_one_face(cv2.imread(source_path)) target_frame = cv2.imread(target_path) - if roop.globals.many_faces: - reference_face = None - else: - reference_face = get_one_face(target_frame, roop.globals.reference_face_position) + reference_face = None if roop.globals.many_faces else get_one_face(target_frame, roop.globals.reference_face_position) result = process_frame(source_face, reference_face, target_frame) cv2.imwrite(output_path, result) diff --git a/roop/ui.py b/roop/ui.py index 67ec32a52..cebe6a20c 100644 --- a/roop/ui.py +++ b/roop/ui.py @@ -152,7 +152,7 @@ def select_source_path(source_path: Optional[str] = None) -> None: if source_path is None: source_path = ctk.filedialog.askopenfilename(title='select an source image', initialdir=RECENT_DIRECTORY_SOURCE) if is_image(source_path): - roop.globals.source_path = source_path # type: ignore + roop.globals.source_path = source_path RECENT_DIRECTORY_SOURCE = os.path.dirname(roop.globals.source_path) image = render_image_preview(roop.globals.source_path, (200, 200)) source_label.configure(image=image) @@ -170,12 +170,12 @@ def select_target_path(target_path: Optional[str] = None) -> None: if target_path is None: target_path = ctk.filedialog.askopenfilename(title='select an target image or video', initialdir=RECENT_DIRECTORY_TARGET) if is_image(target_path): - roop.globals.target_path = target_path # type: ignore + roop.globals.target_path = target_path RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path) image = render_image_preview(roop.globals.target_path, (200, 200)) target_label.configure(image=image) elif is_video(target_path): - roop.globals.target_path = target_path # type: ignore + roop.globals.target_path = target_path RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path) video_frame = render_video_preview(target_path, (200, 200)) target_label.configure(image=video_frame) @@ -273,8 +273,8 @@ def update_preview(frame_number: int = 0) -> None: def update_face_reference(steps: int) -> None: clear_face_reference() - reference_frame_number = preview_slider.get() - roop.globals.reference_face_position += steps # type: ignore + reference_frame_number = int(preview_slider.get()) + roop.globals.reference_face_position += steps roop.globals.reference_frame_number = reference_frame_number update_preview(reference_frame_number)