diff --git a/facefusion/config.py b/facefusion/config.py index e8e307ce..63aab509 100644 --- a/facefusion/config.py +++ b/facefusion/config.py @@ -1,29 +1,20 @@ from configparser import ConfigParser +from functools import lru_cache from typing import List, Optional from facefusion import state_manager from facefusion.common_helper import cast_bool, cast_float, cast_int -CONFIG_PARSER = None - -def get_config_parser() -> ConfigParser: - global CONFIG_PARSER - - if CONFIG_PARSER is None: - CONFIG_PARSER = ConfigParser() - CONFIG_PARSER.read(state_manager.get_item('config_path'), encoding = 'utf-8') - return CONFIG_PARSER - - -def clear_config_parser() -> None: - global CONFIG_PARSER - - CONFIG_PARSER = None +@lru_cache +def get_static_config_parser() -> ConfigParser: + config_parser = ConfigParser() + config_parser.read(state_manager.get_item('config_path'), encoding = 'utf-8') + return config_parser def get_str_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[str]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return config_parser.get(section, option) @@ -31,7 +22,7 @@ def get_str_value(section : str, option : str, fallback : Optional[str] = None) def get_int_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[int]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return config_parser.getint(section, option) @@ -39,7 +30,7 @@ def get_int_value(section : str, option : str, fallback : Optional[str] = None) def get_float_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[float]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return config_parser.getfloat(section, option) @@ -47,7 +38,7 @@ def get_float_value(section : str, option : str, fallback : Optional[str] = None def get_bool_value(section : str, option : str, fallback : Optional[str] = None) -> Optional[bool]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return config_parser.getboolean(section, option) @@ -55,7 +46,7 @@ def get_bool_value(section : str, option : str, fallback : Optional[str] = None) def get_str_list(section : str, option : str, fallback : Optional[str] = None) -> Optional[List[str]]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return config_parser.get(section, option).split() @@ -65,7 +56,7 @@ def get_str_list(section : str, option : str, fallback : Optional[str] = None) - def get_int_list(section : str, option : str, fallback : Optional[str] = None) -> Optional[List[int]]: - config_parser = get_config_parser() + config_parser = get_static_config_parser() if config_parser.has_option(section, option) and config_parser.get(section, option).strip(): return list(map(int, config_parser.get(section, option).split())) diff --git a/facefusion/installer.py b/facefusion/installer.py index 9b7189f4..7bbcaa7c 100644 --- a/facefusion/installer.py +++ b/facefusion/installer.py @@ -19,16 +19,16 @@ LOCALES =\ } ONNXRUNTIME_SET =\ { - 'default': ('onnxruntime', '1.24.4') + 'default': ('onnxruntime', '1.26.0') } if is_windows() or is_linux(): - ONNXRUNTIME_SET['cuda'] = ('onnxruntime-gpu', '1.24.4') + ONNXRUNTIME_SET['cuda'] = ('onnxruntime-gpu', '1.26.0') ONNXRUNTIME_SET['openvino'] = ('onnxruntime-openvino', '1.24.1') if is_windows(): ONNXRUNTIME_SET['directml'] = ('onnxruntime-directml', '1.24.4') ONNXRUNTIME_SET['qnn'] = ('onnxruntime-qnn', '1.24.4') if is_linux(): - ONNXRUNTIME_SET['migraphx'] = ('onnxruntime-migraphx', '1.24.2') + ONNXRUNTIME_SET['migraphx'] = ('onnxruntime-migraphx', '1.25.0') ONNXRUNTIME_SET['rocm'] = ('onnxruntime-rocm', '1.22.2.post1') diff --git a/facefusion/jobs/job_manager.py b/facefusion/jobs/job_manager.py index 8abc34b8..4c9acda8 100644 --- a/facefusion/jobs/job_manager.py +++ b/facefusion/jobs/job_manager.py @@ -6,6 +6,7 @@ import facefusion.choices from facefusion.filesystem import create_directory, get_file_name, is_directory, is_file, move_file, remove_directory, remove_file, resolve_file_pattern from facefusion.jobs.job_helper import get_step_output_path from facefusion.json import read_json, write_json +from facefusion.sanitizer import sanitize_job_id from facefusion.time_helper import get_current_date_time from facefusion.types import Args, Job, JobSet, JobStatus, JobStep, JobStepStatus @@ -261,5 +262,6 @@ def find_job_path(job_id : str) -> Optional[str]: def get_job_file_name(job_id : str) -> Optional[str]: if job_id: + job_id = sanitize_job_id(job_id) return job_id + '.json' return None diff --git a/facefusion/sanitizer.py b/facefusion/sanitizer.py index e8c7a920..3f85e532 100644 --- a/facefusion/sanitizer.py +++ b/facefusion/sanitizer.py @@ -9,6 +9,7 @@ def sanitize_job_id(job_id : str) -> str: if __job_id__.isalnum(): return job_id + return hashlib.sha1(job_id.encode()).hexdigest() diff --git a/facefusion/streamer.py b/facefusion/streamer.py index 6cfccdd5..2f82e896 100644 --- a/facefusion/streamer.py +++ b/facefusion/streamer.py @@ -2,7 +2,7 @@ import os import subprocess from collections import deque from concurrent.futures import ThreadPoolExecutor -from typing import Deque, Iterator +from typing import Deque, Iterator, List import cv2 import numpy @@ -20,6 +20,7 @@ from facefusion.vision import extract_vision_mask, read_static_images def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) -> Iterator[VisionFrame]: capture_deque : Deque[VisionFrame] = deque() + source_vision_frames = read_static_images(state_manager.get_item('source_paths')) with tqdm(desc = translator.get('streaming'), unit = 'frame', disable = state_manager.get_item('log_level') in [ 'warn', 'error' ]) as progress: with ThreadPoolExecutor(max_workers = state_manager.get_item('execution_thread_count')) as executor: @@ -32,7 +33,7 @@ def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) - if numpy.any(capture_frame): audio_frame = create_empty_audio_frame() - future = executor.submit(process_frame, audio_frame, capture_frame) + future = executor.submit(process_frame, source_vision_frames, audio_frame, capture_frame) futures.append(future) for future_done in [ future for future in futures if future.done() ]: @@ -45,8 +46,7 @@ def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) - yield capture_deque.popleft() -def process_frame(stream_audio_frame : AudioFrame, stream_vision_frame : VisionFrame) -> VisionFrame: - source_vision_frames = read_static_images(state_manager.get_item('source_paths')) +def process_frame(source_vision_frames : List[VisionFrame], stream_audio_frame : AudioFrame, stream_vision_frame : VisionFrame) -> VisionFrame: source_voice_frame = create_empty_audio_frame() temp_vision_frame = stream_vision_frame.copy() temp_vision_mask = extract_vision_mask(temp_vision_frame) diff --git a/requirements.txt b/requirements.txt index 4c9e41fd..7e67d4df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ numpy==2.4.2 onnx==1.20.1 -onnxruntime==1.24.1 +onnxruntime==1.26.0 opencv-python==4.13.0.92 psutil==7.2.2 python-multipart==0.0.28 diff --git a/tests/test_config.py b/tests/test_config.py index cae75778..ba821508 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,14 +1,13 @@ -from configparser import ConfigParser - import pytest -from facefusion import config +from facefusion import config, state_manager @pytest.fixture(scope = 'module', autouse = True) def before_all() -> None: - config.CONFIG_PARSER = ConfigParser() - config.CONFIG_PARSER.read_dict( + state_manager.init_item('config_path', 'facefusion.ini') + config_parser = config.get_static_config_parser() + config_parser.read_dict( { 'str': {