Feat/custom file format handling (#845)
* Purge filetype dependency, Rename file_extension to file_format, Introduce custom format detections * Changed a lot * Purge filetype dependency, Rename file_extension to file_format, Introduce custom format detections * Fix stuff * Fix stuff * Simplify all the is_ and has_ methods * Simplify all the is_ and has_ methods * Use the new helper on more places * Introduce are_ next to is_ and has_ * Get rid of the type-ignores * Add more video types
This commit is contained in:
@@ -9,7 +9,7 @@ import gradio
|
||||
|
||||
from facefusion import state_manager, wording
|
||||
from facefusion.core import conditional_process
|
||||
from facefusion.filesystem import is_video
|
||||
from facefusion.filesystem import get_file_extension, is_video
|
||||
from facefusion.memory import limit_system_memory
|
||||
from facefusion.uis.core import get_ui_component
|
||||
from facefusion.vision import count_video_frame_total, detect_video_fps, detect_video_resolution, pack_resolution
|
||||
@@ -72,8 +72,8 @@ def listen() -> None:
|
||||
|
||||
def suggest_output_path(target_path : str) -> Optional[str]:
|
||||
if is_video(target_path):
|
||||
_, target_extension = os.path.splitext(target_path)
|
||||
return os.path.join(tempfile.gettempdir(), hashlib.sha1().hexdigest()[:8] + target_extension)
|
||||
target_file_extension = get_file_extension(target_path)
|
||||
return os.path.join(tempfile.gettempdir(), hashlib.sha1().hexdigest()[:8] + target_file_extension)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import gradio
|
||||
|
||||
import facefusion.choices
|
||||
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, state_manager, voice_extractor, wording
|
||||
from facefusion.filesystem import list_directory
|
||||
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.typing import DownloadProvider
|
||||
|
||||
@@ -36,7 +36,7 @@ def update_download_providers(download_providers : List[DownloadProvider]) -> gr
|
||||
face_masker,
|
||||
voice_extractor
|
||||
]
|
||||
available_processors = [ file.get('name') for file in list_directory('facefusion/processors/modules') ]
|
||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||
processor_modules = get_processors_modules(available_processors)
|
||||
|
||||
for module in common_modules + processor_modules:
|
||||
|
||||
@@ -4,7 +4,7 @@ import gradio
|
||||
|
||||
from facefusion import content_analyser, face_classifier, face_detector, face_landmarker, face_masker, face_recognizer, state_manager, voice_extractor, wording
|
||||
from facefusion.execution import get_available_execution_providers
|
||||
from facefusion.filesystem import list_directory
|
||||
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.typing import ExecutionProvider
|
||||
|
||||
@@ -36,7 +36,7 @@ def update_execution_providers(execution_providers : List[ExecutionProvider]) ->
|
||||
face_recognizer,
|
||||
voice_extractor
|
||||
]
|
||||
available_processors = [ file.get('name') for file in list_directory('facefusion/processors/modules') ]
|
||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||
processor_modules = get_processors_modules(available_processors)
|
||||
|
||||
for module in common_modules + processor_modules:
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import List, Optional
|
||||
import gradio
|
||||
|
||||
from facefusion import state_manager, wording
|
||||
from facefusion.filesystem import list_directory
|
||||
from facefusion.filesystem import get_file_name, resolve_file_paths
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.uis.core import register_ui_component
|
||||
|
||||
@@ -39,5 +39,5 @@ def update_processors(processors : List[str]) -> gradio.CheckboxGroup:
|
||||
|
||||
|
||||
def sort_processors(processors : List[str]) -> List[str]:
|
||||
available_processors = [ file.get('name') for file in list_directory('facefusion/processors/modules') ]
|
||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||
return sorted(available_processors, key = lambda processor : processors.index(processor) if processor in processors else len(processors))
|
||||
|
||||
@@ -23,11 +23,6 @@ def render() -> None:
|
||||
SOURCE_FILE = gradio.File(
|
||||
label = wording.get('uis.source_file'),
|
||||
file_count = 'multiple',
|
||||
file_types =
|
||||
[
|
||||
'audio',
|
||||
'image'
|
||||
],
|
||||
value = state_manager.get_item('source_paths') if has_source_audio or has_source_image else None
|
||||
)
|
||||
source_file_names = [ source_file_value.get('path') for source_file_value in SOURCE_FILE.value ] if SOURCE_FILE.value else None
|
||||
|
||||
@@ -26,11 +26,6 @@ def render() -> None:
|
||||
TARGET_FILE = gradio.File(
|
||||
label = wording.get('uis.target_file'),
|
||||
file_count = 'single',
|
||||
file_types =
|
||||
[
|
||||
'image',
|
||||
'video'
|
||||
],
|
||||
value = state_manager.get_item('target_path') if is_target_image or is_target_video else None
|
||||
)
|
||||
target_image_options : ComponentOptions =\
|
||||
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
from typing import Optional
|
||||
|
||||
from facefusion import state_manager
|
||||
from facefusion.filesystem import is_image, is_video
|
||||
from facefusion.filesystem import get_file_extension, is_image, is_video
|
||||
|
||||
|
||||
def convert_int_none(value : int) -> Optional[int]:
|
||||
@@ -20,7 +20,7 @@ def convert_str_none(value : str) -> Optional[str]:
|
||||
|
||||
def suggest_output_path(output_directory_path : str, target_path : str) -> Optional[str]:
|
||||
if is_image(target_path) or is_video(target_path):
|
||||
_, target_extension = os.path.splitext(target_path)
|
||||
output_name = hashlib.sha1(str(state_manager.get_state()).encode()).hexdigest()[:8]
|
||||
return os.path.join(output_directory_path, output_name + target_extension)
|
||||
output_file_name = hashlib.sha1(str(state_manager.get_state()).encode()).hexdigest()[:8]
|
||||
target_file_extension = get_file_extension(target_path)
|
||||
return os.path.join(output_directory_path, output_file_name + target_file_extension)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user