Industry leading face manipulation platform
Patch 3.9.2 (#1259)
Henry Ruhsdecc6c9d8f8e
diff --git a/facefusion/audio.py b/facefusion/audio.pyindex 723fb8d4..d941e321 100644--- a/facefusion/audio.py+++ b/facefusion/audio.py@@ -71,7 +71,7 @@ def extract_audio_frames(spectrogram : Spectrogram, fps : Fps) -> List[AudioFramfor index in indices:start = max(0, index - audio_step_size)- audio_frames.append(spectrogram[:, start:index])+ audio_frames.append(spectrogram[:, start:index]) #type:ignore[index, misc]return audio_framesdiff --git a/facefusion/curl_builder.py b/facefusion/curl_builder.pyindex 08ac7a87..a2d572f1 100644--- a/facefusion/curl_builder.py+++ b/facefusion/curl_builder.py@@ -9,7 +9,7 @@ from facefusion.types import Commanddef run(commands : List[Command]) -> List[Command]:user_agent = metadata.get('name') + '/' + metadata.get('version')- return [ shutil.which('curl'), '--user-agent', user_agent, '--location', '--silent', '--ssl-no-revoke' ] + commands+ return [ shutil.which('curl'), '--user-agent', user_agent, '--location', '--silent', '--fail', '--ssl-no-revoke' ] + commandsdef chain(*commands : List[Command]) -> List[Command]:diff --git a/facefusion/download.py b/facefusion/download.pyindex d473d613..2eec3595 100644--- a/facefusion/download.py+++ b/facefusion/download.py@@ -53,11 +53,12 @@ def get_static_download_size(url : str) -> int:process = open_curl(commands)lines = reversed(process.stdout.readlines())- for line in lines:- __line__ = line.decode().lower()- if 'content-length:' in __line__:- _, content_length = __line__.split('content-length:')- return int(content_length)+ if process.wait() == 0:+ for line in lines:+ __line__ = line.decode().lower()+ if 'content-length:' in __line__:+ _, content_length = __line__.split('content-length:')+ return int(content_length)return 0@@ -96,8 +97,7 @@ def conditional_download_hashes(hash_set : DownloadSet) -> bool:invalid_hash_file_name = get_file_name(invalid_hash_path)logger.error(translator.get('validating_hash_failed').format(hash_file_name = invalid_hash_file_name), __name__)- if not invalid_hash_paths:- process_manager.end()+ process_manager.end()return not invalid_hash_paths@@ -126,8 +126,7 @@ def conditional_download_sources(source_set : DownloadSet) -> bool:if remove_file(invalid_source_path):logger.error(translator.get('deleting_corrupt_source').format(source_file_name = invalid_source_file_name), __name__)- if not invalid_source_paths:- process_manager.end()+ process_manager.end()return not invalid_source_pathsdiff --git a/facefusion/execution.py b/facefusion/execution.pyindex 746c7019..e79aff32 100644--- a/facefusion/execution.py+++ b/facefusion/execution.py@@ -198,7 +198,7 @@ def create_value_and_unit(text : str) -> Optional[ValueAndUnit]:return\{- 'value': int(value),+ 'value': float(value),'unit': str(unit)}return Nonediff --git a/facefusion/face_landmarker.py b/facefusion/face_landmarker.pyindex 1af1b002..5cf7add4 100644--- a/facefusion/face_landmarker.py+++ b/facefusion/face_landmarker.py@@ -182,7 +182,7 @@ def detect_face_landmark(vision_frame : VisionFrame, bounding_box : BoundingBox,return face_landmark_peppa_wutz, face_landmark_score_peppa_wutz-def detect_with_2dfan4(temp_vision_frame: VisionFrame, bounding_box: BoundingBox, face_angle: Angle) -> Tuple[FaceLandmark68, Score]:+def detect_with_2dfan4(temp_vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:model_size = create_static_model_set('full').get('2dfan4').get('size')scale = 195 / numpy.subtract(bounding_box[2:], bounding_box[:2]).max().clip(1, None)translation = (model_size[0] - numpy.add(bounding_box[2:], bounding_box[:2]) * scale) * 0.5diff --git a/facefusion/face_masker.py b/facefusion/face_masker.pyindex 20f02484..410295a0 100755--- a/facefusion/face_masker.py+++ b/facefusion/face_masker.py@@ -234,7 +234,7 @@ def create_area_mask(crop_vision_frame : VisionFrame, face_landmark_68 : FaceLanconvex_hull = cv2.convexHull(face_landmark_68[landmark_points].astype(numpy.int32))area_mask = numpy.zeros(crop_size).astype(numpy.float32)cv2.fillConvexPoly(area_mask, convex_hull, 1.0) #type:ignore[call-overload]- area_mask = (cv2.GaussianBlur(area_mask.clip(0, 1), (0, 0), 5).clip(0.5, 1) - 0.5) * 2+ area_mask = (cv2.GaussianBlur(area_mask.clip(0, 1), (0, 0), 5).clip(0.5, 1) - 0.5) * 2 #type:ignore[assignment]return area_maskdiff --git a/facefusion/ffmpeg.py b/facefusion/ffmpeg.pyindex b2971d20..8362b021 100644--- a/facefusion/ffmpeg.py+++ b/facefusion/ffmpeg.py@@ -28,7 +28,9 @@ def run_ffmpeg_with_progress(commands : List[Command], update_progress : UpdatePif 'frame=' in __line__:_, frame_number = __line__.split('frame=')- update_progress(int(frame_number))+ __frame_number__ = int(frame_number)++ update_progress(__frame_number__)if log_level == 'debug':log_debug(process)@@ -37,6 +39,9 @@ def run_ffmpeg_with_progress(commands : List[Command], update_progress : UpdatePcontinuereturn process+ if process_manager.is_stopping():+ process.terminate()+return process@@ -139,14 +144,14 @@ def get_available_encoder_set() -> EncoderSet:audio_encoder = line.split()[1]if audio_encoder in facefusion.choices.output_audio_encoders:- index = facefusion.choices.output_audio_encoders.index(audio_encoder) #type:ignore[arg-type]- available_encoder_set['audio'].insert(index, audio_encoder) #type:ignore[arg-type]+ index = facefusion.choices.output_audio_encoders.index(cast(AudioEncoder, audio_encoder))+ available_encoder_set['audio'].insert(index, cast(AudioEncoder, audio_encoder))if line.startswith(' v'):video_encoder = line.split()[1]if video_encoder in facefusion.choices.output_video_encoders:- index = facefusion.choices.output_video_encoders.index(video_encoder) #type:ignore[arg-type]- available_encoder_set['video'].insert(index, video_encoder) #type:ignore[arg-type]+ index = facefusion.choices.output_video_encoders.index(cast(VideoEncoder, video_encoder))+ available_encoder_set['video'].insert(index, cast(VideoEncoder, video_encoder))return available_encoder_setdiff --git a/facefusion/installer.py b/facefusion/installer.pyindex 9604414d..b3e4b362 100644--- a/facefusion/installer.py+++ b/facefusion/installer.py@@ -19,15 +19,15 @@ LOCALES =\}ONNXRUNTIME_SET =\{- 'default': ('onnxruntime', '1.30.0')+ 'default': ('onnxruntime', '1.31.0')}if is_windows() or is_linux():ONNXRUNTIME_SET['cuda@12'] = ('onnxruntime-gpu', '1.24.4')- ONNXRUNTIME_SET['cuda@13'] = ('onnxruntime-gpu', '1.30.0')+ ONNXRUNTIME_SET['cuda@13'] = ('onnxruntime-gpu', '1.31.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', '2.6.0')+ ONNXRUNTIME_SET['qnn'] = ('onnxruntime-qnn', '2.7.0')if is_linux():ONNXRUNTIME_SET['migraphx'] = ('onnxruntime-migraphx', '1.27.1')ONNXRUNTIME_SET['rocm'] = ('onnxruntime-rocm', '1.22.2.post3')diff --git a/facefusion/jobs/job_manager.py b/facefusion/jobs/job_manager.pyindex ca1cd8b5..bd524515 100644--- a/facefusion/jobs/job_manager.py+++ b/facefusion/jobs/job_manager.py@@ -1,6 +1,6 @@import osfrom copy import copy-from typing import List, Optional+from typing import List, Optional, castimport facefusion.choicesfrom facefusion.filesystem import create_directory, get_file_name, is_directory, is_file, move_file, remove_directory, remove_file, resolve_file_pattern@@ -8,7 +8,7 @@ from facefusion.jobs.job_helper import get_step_output_pathfrom facefusion.json import read_json, write_jsonfrom facefusion.sanitizer import sanitize_job_idfrom facefusion.time_helper import get_current_date_time-from facefusion.types import Args, Job, JobSet, JobStatus, JobStep, JobStepStatus+from facefusion.types import Args, Content, Job, JobSet, JobStatus, JobStep, JobStepStatusJOBS_PATH : str = '.jobs'@@ -207,7 +207,7 @@ def set_steps_status(job_id : str, step_status : JobStepStatus) -> bool:def read_job_file(job_id : str) -> Optional[Job]:job_path = find_job_path(job_id)- return read_json(job_path) #type:ignore[return-value]+ return cast(Job, read_json(job_path))def create_job_file(job_id : str, job : Job) -> bool:@@ -215,7 +215,7 @@ def create_job_file(job_id : str, job : Job) -> bool:if not is_file(job_path):job_create_path = suggest_job_path(job_id, 'drafted')- return write_json(job_create_path, job) #type:ignore[arg-type]+ return write_json(job_create_path, cast(Content, job))return False@@ -224,7 +224,7 @@ def update_job_file(job_id : str, job : Job) -> bool:if is_file(job_path):job['date_updated'] = get_current_date_time().isoformat()- return write_json(job_path, job) #type:ignore[arg-type]+ return write_json(job_path, cast(Content, job))return Falsediff --git a/facefusion/metadata.py b/facefusion/metadata.pyindex d1921c69..9120fee9 100644--- a/facefusion/metadata.py+++ b/facefusion/metadata.py@@ -4,7 +4,7 @@ METADATA =\{'name': 'FaceFusion','description': 'Industry leading face manipulation platform',- 'version': '3.9.1',+ 'version': '3.9.2','license': 'OpenRAIL-AS','author': 'Henry Ruhs','url': 'https://facefusion.io'diff --git a/facefusion/processors/modules/age_modifier/core.py b/facefusion/processors/modules/age_modifier/core.pyindex d442f21b..99dd217c 100755--- a/facefusion/processors/modules/age_modifier/core.py+++ b/facefusion/processors/modules/age_modifier/core.py@@ -56,11 +56,11 @@ def create_static_model_set(download_scope : DownloadScope) -> ModelSet:},'templates':{- 'target': 'ffhq_512',+ 'target': 'ffhq_512'},'sizes':{- 'target': (1024, 1024),+ 'target': (1024, 1024)},'mean': [ 0.0, 0.0, 0.0 ],'standard_deviation': [ 1.0, 1.0, 1.0 ]diff --git a/facefusion/types.py b/facefusion/types.pyindex dcf4ee84..07e171d1 100755--- a/facefusion/types.py+++ b/facefusion/types.py@@ -236,7 +236,7 @@ InferenceProvider : TypeAlias = AnyInferenceOptionSet : TypeAlias = Dict[str, Any]ValueAndUnit = TypedDict('ValueAndUnit',{- 'value' : int,+ 'value' : float,'unit' : str})ExecutionDeviceFramework = TypedDict('ExecutionDeviceFramework',diff --git a/facefusion/uis/components/benchmark_options.py b/facefusion/uis/components/benchmark_options.pyindex 58d1ac76..db7b8963 100644--- a/facefusion/uis/components/benchmark_options.py+++ b/facefusion/uis/components/benchmark_options.py@@ -27,7 +27,7 @@ def render() -> None:choices = facefusion.choices.benchmark_resolutions,value = state_manager.get_item('benchmark_resolutions'))- BENCHMARK_CYCLE_COUNT_SLIDER = gradio.Slider(+ BENCHMARK_CYCLE_COUNT_SLIDER = gradio.Slider( #type:ignore[assignment]label = translator.get('uis.benchmark_cycle_count_slider'),value = state_manager.get_item('benchmark_cycle_count'),step = calculate_int_step(facefusion.choices.benchmark_cycle_count_range),@@ -39,7 +39,7 @@ def render() -> None:def listen() -> None:BENCHMARK_MODE_DROPDOWN.change(update_benchmark_mode, inputs = BENCHMARK_MODE_DROPDOWN)BENCHMARK_RESOLUTIONS_CHECKBOX_GROUP.change(update_benchmark_resolutions, inputs = BENCHMARK_RESOLUTIONS_CHECKBOX_GROUP)- BENCHMARK_CYCLE_COUNT_SLIDER.release(update_benchmark_cycle_count, inputs = BENCHMARK_CYCLE_COUNT_SLIDER)+ BENCHMARK_CYCLE_COUNT_SLIDER.release(update_benchmark_cycle_count, inputs = BENCHMARK_CYCLE_COUNT_SLIDER) #type:ignore[union-attr]def update_benchmark_mode(benchmark_mode : BenchmarkMode) -> None:diff --git a/facefusion/uis/components/face_selector.py b/facefusion/uis/components/face_selector.pyindex ea744f93..e47ce011 100644--- a/facefusion/uis/components/face_selector.py+++ b/facefusion/uis/components/face_selector.py@@ -66,12 +66,12 @@ def render() -> None:)FACE_SELECTOR_GENDER_DROPDOWN = gradio.Dropdown(label = translator.get('uis.face_selector_gender_dropdown'),- choices = [ 'none' ] + facefusion.choices.face_selector_genders,+ choices = [ 'none' ] + facefusion.choices.face_selector_genders, #type:ignore[operator]value = state_manager.get_item('face_selector_gender') or 'none')FACE_SELECTOR_RACE_DROPDOWN = gradio.Dropdown(label = translator.get('uis.face_selector_race_dropdown'),- choices = [ 'none' ] + facefusion.choices.face_selector_races,+ choices = [ 'none' ] + facefusion.choices.face_selector_races, #type:ignore[operator]value = state_manager.get_item('face_selector_race') or 'none')with gradio.Row():diff --git a/facefusion/uis/core.py b/facefusion/uis/core.pyindex 8adf1ecd..cbba2262 100644--- a/facefusion/uis/core.py+++ b/facefusion/uis/core.py@@ -77,7 +77,7 @@ def init() -> None:warnings.filterwarnings('ignore', category = UserWarning, module = 'gradio')gradio.processing_utils._check_allowed = uis_overrides.mockgradio.processing_utils.convert_video_to_playable_mp4 = uis_overrides.convert_video_to_playable_mp4- gradio.components.Number.raise_if_out_of_bounds = uis_overrides.mock+ gradio.components.Number.raise_if_out_of_bounds = uis_overrides.mock #type:ignore[method-assign]def launch() -> None:diff --git a/requirements.txt b/requirements.txtindex 8f6223a0..58f8cebd 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,8 +1,8 @@gradio-rangeslider==0.0.8gradio==5.50.0-numpy==2.4.6-onnx==1.23.1-onnxruntime==1.30.0+numpy==2.5.4+onnx==1.23.2+onnxruntime==1.31.0opencv-python-headless==5.0.0.93tqdm==4.70.1scipy==1.18.1diff --git a/tests/test_curl_builder.py b/tests/test_curl_builder.pyindex 261e165e..f2d5c47b 100644--- a/tests/test_curl_builder.py+++ b/tests/test_curl_builder.py@@ -7,7 +7,7 @@ from facefusion.curl_builder import chain, ping, run, set_timeoutdef test_run() -> None:user_agent = metadata.get('name') + '/' + metadata.get('version')- assert run([]) == [ which('curl'), '--user-agent', user_agent, '--location', '--silent', '--ssl-no-revoke' ]+ assert run([]) == [ which('curl'), '--user-agent', user_agent, '--location', '--silent', '--fail', '--ssl-no-revoke' ]def test_chain() -> None:diff --git a/tests/test_download.py b/tests/test_download.pyindex 48698aad..d16c44b4 100644--- a/tests/test_download.py+++ b/tests/test_download.py@@ -1,9 +1,12 @@-from facefusion.download import get_static_download_size, ping_static_url, resolve_download_url_by_provider+from facefusion import process_manager+from facefusion.download import conditional_download_hashes, conditional_download_sources, get_static_download_size, ping_static_url, resolve_download_url_by_provider+from facefusion.types import DownloadSetdef test_get_static_download_size() -> None:- assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx') == 85170772- assert get_static_download_size('https://huggingface.co/facefusion/models-3.0.0/resolve/main/fairface.onnx') == 85170772+ assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx') == 232475+ assert get_static_download_size('https://huggingface.co/facefusion/models-3.4.0/resolve/main/yunet_2023_mar.onnx') == 232475+ assert get_static_download_size('https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/invalid.onnx') == 0assert get_static_download_size('invalid') == 0@@ -13,6 +16,58 @@ def test_static_ping_url() -> None:assert ping_static_url('invalid') is False+def test_conditional_download_hashes() -> None:+ hash_set : DownloadSet =\+ {+ 'yunet':+ {+ 'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.hash',+ 'path': '.assets/models/yunet_2023_mar.hash'+ }+ }++ assert conditional_download_hashes(hash_set) is True+ assert process_manager.is_pending() is True++ hash_set =\+ {+ 'invalid':+ {+ 'url': 'invalid',+ 'path': 'invalid'+ }+ }++ assert conditional_download_hashes(hash_set) is False+ assert process_manager.is_pending() is True+++def test_conditional_download_sources() -> None:+ source_set : DownloadSet =\+ {+ 'yunet':+ {+ 'url': 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx',+ 'path': '.assets/models/yunet_2023_mar.onnx'+ }+ }++ assert conditional_download_sources(source_set) is True+ assert process_manager.is_pending() is True++ source_set =\+ {+ 'invalid':+ {+ 'url': 'invalid',+ 'path': 'invalid'+ }+ }++ assert conditional_download_sources(source_set) is False+ assert process_manager.is_pending() is True++def test_resolve_download_url_by_provider() -> None:- assert resolve_download_url_by_provider('github', 'models-3.0.0', 'fairface.onnx') == 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.0.0/fairface.onnx'- assert resolve_download_url_by_provider('huggingface', 'models-3.0.0', 'fairface.onnx') == 'https://huggingface.co/facefusion/models-3.0.0/resolve/main/fairface.onnx'+ assert resolve_download_url_by_provider('github', 'models-3.4.0', 'yunet_2023_mar.onnx') == 'https://github.com/facefusion/facefusion-assets/releases/download/models-3.4.0/yunet_2023_mar.onnx'+ assert resolve_download_url_by_provider('huggingface', 'models-3.4.0', 'yunet_2023_mar.onnx') == 'https://huggingface.co/facefusion/models-3.4.0/resolve/main/yunet_2023_mar.onnx'