mirror of
https://github.com/s0md3v/roop.git
synced 2025-12-06 18:08:29 +00:00
Allow to initialize UI with source path and target path
This commit is contained in:
parent
7529ba6708
commit
0b178d5f0e
@ -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)
|
||||
roop.globals.headless = roop.globals.source_path and roop.globals.target_path and roop.globals.output_path
|
||||
roop.globals.frame_processors = args.frame_processor
|
||||
roop.globals.headless = args.source_path or args.target_path or args.output_path
|
||||
roop.globals.keep_fps = args.keep_fps
|
||||
roop.globals.keep_frames = args.keep_frames
|
||||
roop.globals.skip_audio = args.skip_audio
|
||||
|
||||
@ -3,6 +3,7 @@ from typing import List
|
||||
source_path = None
|
||||
target_path = None
|
||||
output_path = None
|
||||
headless = None
|
||||
frame_processors: List[str] = []
|
||||
keep_fps = None
|
||||
keep_frames = None
|
||||
@ -16,5 +17,4 @@ video_quality = None
|
||||
max_memory = None
|
||||
execution_providers: List[str] = []
|
||||
execution_threads = None
|
||||
headless = None
|
||||
log_level = 'error'
|
||||
|
||||
20
roop/ui.py
20
roop/ui.py
@ -58,9 +58,13 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||
|
||||
source_label = ctk.CTkLabel(root, text=None)
|
||||
source_label.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.25)
|
||||
if roop.globals.source_path:
|
||||
select_source_path(roop.globals.source_path)
|
||||
|
||||
target_label = ctk.CTkLabel(root, text=None)
|
||||
target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25)
|
||||
if roop.globals.target_path:
|
||||
select_target_path(roop.globals.target_path)
|
||||
|
||||
source_button = ctk.CTkButton(root, text='Select a face', cursor='hand2', command=lambda: select_source_path())
|
||||
source_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1)
|
||||
@ -127,11 +131,13 @@ def update_status(text: str) -> None:
|
||||
ROOT.update()
|
||||
|
||||
|
||||
def select_source_path() -> None:
|
||||
def select_source_path(source_path: str = None) -> None:
|
||||
global RECENT_DIRECTORY_SOURCE
|
||||
|
||||
PREVIEW.withdraw()
|
||||
source_path = ctk.filedialog.askopenfilename(title='select an source image', initialdir=RECENT_DIRECTORY_SOURCE)
|
||||
if PREVIEW:
|
||||
PREVIEW.withdraw()
|
||||
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
|
||||
RECENT_DIRECTORY_SOURCE = os.path.dirname(roop.globals.source_path)
|
||||
@ -142,12 +148,14 @@ def select_source_path() -> None:
|
||||
source_label.configure(image=None)
|
||||
|
||||
|
||||
def select_target_path() -> None:
|
||||
def select_target_path(target_path: str = None) -> None:
|
||||
global RECENT_DIRECTORY_TARGET
|
||||
|
||||
PREVIEW.withdraw()
|
||||
if PREVIEW:
|
||||
PREVIEW.withdraw()
|
||||
clear_face_reference()
|
||||
target_path = ctk.filedialog.askopenfilename(title='select an target image or video', initialdir=RECENT_DIRECTORY_TARGET)
|
||||
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
|
||||
RECENT_DIRECTORY_TARGET = os.path.dirname(roop.globals.target_path)
|
||||
|
||||
@ -7,7 +7,7 @@ import ssl
|
||||
import subprocess
|
||||
import urllib
|
||||
from pathlib import Path
|
||||
from typing import List, Any
|
||||
from typing import List, Optional
|
||||
from tqdm import tqdm
|
||||
|
||||
import roop.globals
|
||||
@ -76,8 +76,8 @@ def get_temp_output_path(target_path: str) -> str:
|
||||
return os.path.join(temp_directory_path, TEMP_FILE)
|
||||
|
||||
|
||||
def normalize_output_path(source_path: str, target_path: str, output_path: str) -> Any:
|
||||
if source_path and target_path:
|
||||
def normalize_output_path(source_path: str, target_path: str, output_path: str) -> Optional[str]:
|
||||
if source_path and target_path and output_path:
|
||||
source_name, _ = os.path.splitext(os.path.basename(source_path))
|
||||
target_name, target_extension = os.path.splitext(os.path.basename(target_path))
|
||||
if os.path.isdir(output_path):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user