Spaces:
Running
Running
Upload folder using huggingface_hub
#2
by imseldrith - opened
This view is limited to 50 files because it contains too many changes. See the raw diff here.
Files changed (50)
- DeepFakeAI/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/__pycache__/capturer.cpython-310.pyc
- DeepFakeAI/__pycache__/choices.cpython-310.pyc
- DeepFakeAI/__pycache__/core.cpython-310.pyc
- DeepFakeAI/__pycache__/face_analyser.cpython-310.pyc
- DeepFakeAI/__pycache__/face_reference.cpython-310.pyc
- DeepFakeAI/__pycache__/globals.cpython-310.pyc
- DeepFakeAI/__pycache__/metadata.cpython-310.pyc
- DeepFakeAI/__pycache__/predictor.cpython-310.pyc
- DeepFakeAI/__pycache__/typing.cpython-310.pyc
- DeepFakeAI/__pycache__/utilities.cpython-310.pyc
- DeepFakeAI/__pycache__/wording.cpython-310.pyc
- DeepFakeAI/capturer.py+1-1
- DeepFakeAI/choices.py+1-1
- DeepFakeAI/core.py+69-69
- DeepFakeAI/face_analyser.py+9-9
- DeepFakeAI/face_reference.py+1-1
- DeepFakeAI/globals.py+1-1
- DeepFakeAI/metadata.py+1-1
- DeepFakeAI/predictor.py+1-1
- DeepFakeAI/processors/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/processors/frame/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/processors/frame/__pycache__/core.cpython-310.pyc
- DeepFakeAI/processors/frame/core.py+11-11
- DeepFakeAI/processors/frame/modules/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/processors/frame/modules/__pycache__/face_swapper.cpython-310.pyc
- DeepFakeAI/processors/frame/modules/face_enhancer.py+10-10
- DeepFakeAI/processors/frame/modules/face_swapper.py+21-21
- DeepFakeAI/processors/frame/modules/frame_enhancer.py+4-4
- DeepFakeAI/uis/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/uis/__pycache__/core.cpython-310.pyc
- DeepFakeAI/uis/__pycache__/typing.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/__init__.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/about.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/execution.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/face_analyser.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/face_selector.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/output.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/output_settings.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/preview.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/processors.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/settings.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/source.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/target.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/temp_frame.cpython-310.pyc
- DeepFakeAI/uis/components/__pycache__/trim_frame.cpython-310.pyc
- DeepFakeAI/uis/components/about.py+1-1
- DeepFakeAI/uis/components/benchmark.py+13-13
- DeepFakeAI/uis/components/execution.py+12-12
- DeepFakeAI/uis/components/face_analyser.py+13-13
12344567from typing import Optionalimport cv2
from facefusion.typing import Framefrom DeepFakeAI.typing import Frame
def get_video_frame(video_path : str, frame_number : int = 0) -> Optional[Frame]:1233456from typing import List
from facefusion.typing import FaceRecognition, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGender, TempFrameFormat, OutputVideoEncoderfrom DeepFakeAI.typing import FaceRecognition, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGender, TempFrameFormat, OutputVideoEncoder
face_recognition : List[FaceRecognition] = [ 'reference', 'many' ]face_analyser_direction : List[FaceAnalyserDirection] = [ 'left-right', 'right-left', 'top-bottom', 'bottom-top', 'small-large', 'large-small']14 unmodified lines1516171819202122231819202122232425265 unmodified lines323334353635363738394041424340414243444546474849495051515253543 unmodified lines5859606162636465666768697071727374757677787980818283848586616263646566676869707172737475767778798081828384858687888914 unmodified lines10410510610710810710810911011011111211318 unmodified lines1321331341351351361371371381391391401411411421431441441451461471481491501511511521531531541551551561571581581591601601611621621631641641651661671681691701711711721731741751751761771771781791801801811821831831841851851861871881891901911921921931941951951961971971981992003 unmodified lines20420520620720720820921021121121221321421421521621721821922022122022122214 unmodified linesimport onnxruntimeimport tensorflow
import facefusion.choicesimport facefusion.globalsfrom facefusion import wording, metadatafrom facefusion.predictor import predict_image, predict_videofrom facefusion.processors.frame.core import get_frame_processors_modulesfrom facefusion.utilities import is_image, is_video, detect_fps, create_video, extract_frames, get_temp_frame_paths, restore_audio, create_temp, move_temp, clear_temp, normalize_output_path, list_module_names, decode_execution_providers, encode_execution_providersimport DeepFakeAI.choicesimport DeepFakeAI.globalsfrom DeepFakeAI import wording, metadatafrom DeepFakeAI.predictor import predict_image, predict_videofrom DeepFakeAI.processors.frame.core import get_frame_processors_modulesfrom DeepFakeAI.utilities import is_image, is_video, detect_fps, create_video, extract_frames, get_temp_frame_paths, restore_audio, create_temp, move_temp, clear_temp, normalize_output_path, list_module_names, decode_execution_providers, encode_execution_providers
warnings.filterwarnings('ignore', category = FutureWarning, module = 'insightface')warnings.filterwarnings('ignore', category = UserWarning, module = 'torchvision')5 unmodified lines program.add_argument('-s', '--source', help = wording.get('source_help'), dest = 'source_path') program.add_argument('-t', '--target', help = wording.get('target_help'), dest = 'target_path') program.add_argument('-o', '--output', help = wording.get('output_help'), dest = 'output_path') program.add_argument('--frame-processors', help = wording.get('frame_processors_help').format(choices = ', '.join(list_module_names('facefusion/processors/frame/modules'))), dest = 'frame_processors', default = ['face_swapper'], nargs='+') program.add_argument('--ui-layouts', help = wording.get('ui_layouts_help').format(choices = ', '.join(list_module_names('facefusion/uis/layouts'))), dest = 'ui_layouts', default = ['default'], nargs='+') program.add_argument('--frame-processors', help = wording.get('frame_processors_help').format(choices = ', '.join(list_module_names('DeepFakeAI/processors/frame/modules'))), dest = 'frame_processors', default = ['face_swapper'], nargs='+') program.add_argument('--ui-layouts', help = wording.get('ui_layouts_help').format(choices = ', '.join(list_module_names('DeepFakeAI/uis/layouts'))), dest = 'ui_layouts', default = ['default'], nargs='+') program.add_argument('--keep-fps', help = wording.get('keep_fps_help'), dest = 'keep_fps', action='store_true') program.add_argument('--keep-temp', help = wording.get('keep_temp_help'), dest = 'keep_temp', action='store_true') program.add_argument('--skip-audio', help = wording.get('skip_audio_help'), dest = 'skip_audio', action='store_true') program.add_argument('--face-recognition', help = wording.get('face_recognition_help'), dest = 'face_recognition', default = 'reference', choices = facefusion.choices.face_recognition) program.add_argument('--face-analyser-direction', help = wording.get('face_analyser_direction_help'), dest = 'face_analyser_direction', default = 'left-right', choices = facefusion.choices.face_analyser_direction) program.add_argument('--face-analyser-age', help = wording.get('face_analyser_age_help'), dest = 'face_analyser_age', choices = facefusion.choices.face_analyser_age) program.add_argument('--face-analyser-gender', help = wording.get('face_analyser_gender_help'), dest = 'face_analyser_gender', choices = facefusion.choices.face_analyser_gender) program.add_argument('--face-recognition', help = wording.get('face_recognition_help'), dest = 'face_recognition', default = 'reference', choices = DeepFakeAI.choices.face_recognition) program.add_argument('--face-analyser-direction', help = wording.get('face_analyser_direction_help'), dest = 'face_analyser_direction', default = 'left-right', choices = DeepFakeAI.choices.face_analyser_direction) program.add_argument('--face-analyser-age', help = wording.get('face_analyser_age_help'), dest = 'face_analyser_age', choices = DeepFakeAI.choices.face_analyser_age) program.add_argument('--face-analyser-gender', help = wording.get('face_analyser_gender_help'), dest = 'face_analyser_gender', choices = DeepFakeAI.choices.face_analyser_gender) program.add_argument('--reference-face-position', help = wording.get('reference_face_position_help'), dest = 'reference_face_position', type = int, default = 0) program.add_argument('--reference-face-distance', help = wording.get('reference_face_distance_help'), dest = 'reference_face_distance', type = float, default = 1.5) program.add_argument('--reference-frame-number', help = wording.get('reference_frame_number_help'), dest = 'reference_frame_number', type = int, default = 0) program.add_argument('--trim-frame-start', help = wording.get('trim_frame_start_help'), dest = 'trim_frame_start', type = int) program.add_argument('--trim-frame-end', help = wording.get('trim_frame_end_help'), dest = 'trim_frame_end', type = int) program.add_argument('--temp-frame-format', help = wording.get('temp_frame_format_help'), dest = 'temp_frame_format', default = 'jpg', choices = facefusion.choices.temp_frame_format) program.add_argument('--temp-frame-format', help = wording.get('temp_frame_format_help'), dest = 'temp_frame_format', default = 'jpg', choices = DeepFakeAI.choices.temp_frame_format) program.add_argument('--temp-frame-quality', help = wording.get('temp_frame_quality_help'), dest = 'temp_frame_quality', type = int, default = 100, choices = range(101), metavar = '[0-100]') program.add_argument('--output-video-encoder', help = wording.get('output_video_encoder_help'), dest = 'output_video_encoder', default = 'libx264', choices = facefusion.choices.output_video_encoder) program.add_argument('--output-video-encoder', help = wording.get('output_video_encoder_help'), dest = 'output_video_encoder', default = 'libx264', choices = DeepFakeAI.choices.output_video_encoder) program.add_argument('--output-video-quality', help = wording.get('output_video_quality_help'), dest = 'output_video_quality', type = int, default = 90, choices = range(101), metavar = '[0-100]') program.add_argument('--max-memory', help = wording.get('max_memory_help'), dest = 'max_memory', type = int) program.add_argument('--execution-providers', help = wording.get('execution_providers_help').format(choices = 'cpu'), dest = 'execution_providers', default = ['cpu'], choices = suggest_execution_providers_choices(), nargs='+')3 unmodified lines
args = program.parse_args()
facefusion.globals.source_path = args.source_path facefusion.globals.target_path = args.target_path facefusion.globals.output_path = normalize_output_path(facefusion.globals.source_path, facefusion.globals.target_path, args.output_path) facefusion.globals.headless = facefusion.globals.source_path is not None and facefusion.globals.target_path is not None and facefusion.globals.output_path is not None facefusion.globals.frame_processors = args.frame_processors facefusion.globals.ui_layouts = args.ui_layouts facefusion.globals.keep_fps = args.keep_fps facefusion.globals.keep_temp = args.keep_temp facefusion.globals.skip_audio = args.skip_audio facefusion.globals.face_recognition = args.face_recognition facefusion.globals.face_analyser_direction = args.face_analyser_direction facefusion.globals.face_analyser_age = args.face_analyser_age facefusion.globals.face_analyser_gender = args.face_analyser_gender facefusion.globals.reference_face_position = args.reference_face_position facefusion.globals.reference_frame_number = args.reference_frame_number facefusion.globals.reference_face_distance = args.reference_face_distance facefusion.globals.trim_frame_start = args.trim_frame_start facefusion.globals.trim_frame_end = args.trim_frame_end facefusion.globals.temp_frame_format = args.temp_frame_format facefusion.globals.temp_frame_quality = args.temp_frame_quality facefusion.globals.output_video_encoder = args.output_video_encoder facefusion.globals.output_video_quality = args.output_video_quality facefusion.globals.max_memory = args.max_memory facefusion.globals.execution_providers = decode_execution_providers(args.execution_providers) facefusion.globals.execution_thread_count = args.execution_thread_count facefusion.globals.execution_queue_count = args.execution_queue_count DeepFakeAI.globals.source_path = args.source_path DeepFakeAI.globals.target_path = args.target_path DeepFakeAI.globals.output_path = normalize_output_path(DeepFakeAI.globals.source_path, DeepFakeAI.globals.target_path, args.output_path) DeepFakeAI.globals.headless = DeepFakeAI.globals.source_path is not None and DeepFakeAI.globals.target_path is not None and DeepFakeAI.globals.output_path is not None DeepFakeAI.globals.frame_processors = args.frame_processors DeepFakeAI.globals.ui_layouts = args.ui_layouts DeepFakeAI.globals.keep_fps = args.keep_fps DeepFakeAI.globals.keep_temp = args.keep_temp DeepFakeAI.globals.skip_audio = args.skip_audio DeepFakeAI.globals.face_recognition = args.face_recognition DeepFakeAI.globals.face_analyser_direction = args.face_analyser_direction DeepFakeAI.globals.face_analyser_age = args.face_analyser_age DeepFakeAI.globals.face_analyser_gender = args.face_analyser_gender DeepFakeAI.globals.reference_face_position = args.reference_face_position DeepFakeAI.globals.reference_frame_number = args.reference_frame_number DeepFakeAI.globals.reference_face_distance = args.reference_face_distance DeepFakeAI.globals.trim_frame_start = args.trim_frame_start DeepFakeAI.globals.trim_frame_end = args.trim_frame_end DeepFakeAI.globals.temp_frame_format = args.temp_frame_format DeepFakeAI.globals.temp_frame_quality = args.temp_frame_quality DeepFakeAI.globals.output_video_encoder = args.output_video_encoder DeepFakeAI.globals.output_video_quality = args.output_video_quality DeepFakeAI.globals.max_memory = args.max_memory DeepFakeAI.globals.execution_providers = decode_execution_providers(args.execution_providers) DeepFakeAI.globals.execution_thread_count = args.execution_thread_count DeepFakeAI.globals.execution_queue_count = args.execution_queue_count
def suggest_execution_providers_choices() -> List[str]:14 unmodified lines tensorflow.config.experimental.VirtualDeviceConfiguration(memory_limit = 1024) ]) # limit memory usage if facefusion.globals.max_memory: memory = facefusion.globals.max_memory * 1024 ** 3 if DeepFakeAI.globals.max_memory: memory = DeepFakeAI.globals.max_memory * 1024 ** 3 if platform.system().lower() == 'darwin': memory = facefusion.globals.max_memory * 1024 ** 6 memory = DeepFakeAI.globals.max_memory * 1024 ** 6 if platform.system().lower() == 'windows': import ctypes kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]18 unmodified lines
def process_image() -> None: if predict_image(facefusion.globals.target_path): if predict_image(DeepFakeAI.globals.target_path): return shutil.copy2(facefusion.globals.target_path, facefusion.globals.output_path) shutil.copy2(DeepFakeAI.globals.target_path, DeepFakeAI.globals.output_path) # process frame for frame_processor_module in get_frame_processors_modules(facefusion.globals.frame_processors): for frame_processor_module in get_frame_processors_modules(DeepFakeAI.globals.frame_processors): update_status(wording.get('processing'), frame_processor_module.NAME) frame_processor_module.process_image(facefusion.globals.source_path, facefusion.globals.output_path, facefusion.globals.output_path) frame_processor_module.process_image(DeepFakeAI.globals.source_path, DeepFakeAI.globals.output_path, DeepFakeAI.globals.output_path) frame_processor_module.post_process() # validate image if is_image(facefusion.globals.target_path): if is_image(DeepFakeAI.globals.target_path): update_status(wording.get('processing_image_succeed')) else: update_status(wording.get('processing_image_failed'))
def process_video() -> None: if predict_video(facefusion.globals.target_path): if predict_video(DeepFakeAI.globals.target_path): return fps = detect_fps(facefusion.globals.target_path) if facefusion.globals.keep_fps else 25.0 fps = detect_fps(DeepFakeAI.globals.target_path) if DeepFakeAI.globals.keep_fps else 25.0 update_status(wording.get('creating_temp')) create_temp(facefusion.globals.target_path) create_temp(DeepFakeAI.globals.target_path) # extract frames update_status(wording.get('extracting_frames_fps').format(fps = fps)) extract_frames(facefusion.globals.target_path, fps) extract_frames(DeepFakeAI.globals.target_path, fps) # process frame temp_frame_paths = get_temp_frame_paths(facefusion.globals.target_path) temp_frame_paths = get_temp_frame_paths(DeepFakeAI.globals.target_path) if temp_frame_paths: for frame_processor_module in get_frame_processors_modules(facefusion.globals.frame_processors): for frame_processor_module in get_frame_processors_modules(DeepFakeAI.globals.frame_processors): update_status(wording.get('processing'), frame_processor_module.NAME) frame_processor_module.process_video(facefusion.globals.source_path, temp_frame_paths) frame_processor_module.process_video(DeepFakeAI.globals.source_path, temp_frame_paths) frame_processor_module.post_process() else: update_status(wording.get('temp_frames_not_found')) return # create video update_status(wording.get('creating_video_fps').format(fps = fps)) if not create_video(facefusion.globals.target_path, fps): if not create_video(DeepFakeAI.globals.target_path, fps): update_status(wording.get('creating_video_failed')) return # handle audio if facefusion.globals.skip_audio: if DeepFakeAI.globals.skip_audio: update_status(wording.get('skipping_audio')) move_temp(facefusion.globals.target_path, facefusion.globals.output_path) move_temp(DeepFakeAI.globals.target_path, DeepFakeAI.globals.output_path) else: update_status(wording.get('restoring_audio')) restore_audio(facefusion.globals.target_path, facefusion.globals.output_path) restore_audio(DeepFakeAI.globals.target_path, DeepFakeAI.globals.output_path) # clear temp update_status(wording.get('clearing_temp')) clear_temp(facefusion.globals.target_path) clear_temp(DeepFakeAI.globals.target_path) # validate video if is_video(facefusion.globals.target_path): if is_video(DeepFakeAI.globals.target_path): update_status(wording.get('processing_video_succeed')) else: update_status(wording.get('processing_video_failed'))
def conditional_process() -> None: for frame_processor_module in get_frame_processors_modules(facefusion.globals.frame_processors): for frame_processor_module in get_frame_processors_modules(DeepFakeAI.globals.frame_processors): if not frame_processor_module.pre_process(): return if is_image(facefusion.globals.target_path): if is_image(DeepFakeAI.globals.target_path): process_image() if is_video(facefusion.globals.target_path): if is_video(DeepFakeAI.globals.target_path): process_video()
3 unmodified lines # pre check if not pre_check(): return for frame_processor in get_frame_processors_modules(facefusion.globals.frame_processors): for frame_processor in get_frame_processors_modules(DeepFakeAI.globals.frame_processors): if not frame_processor.pre_check(): return # process or launch if facefusion.globals.headless: if DeepFakeAI.globals.headless: conditional_process() else: import facefusion.uis.core as ui import DeepFakeAI.uis.core as ui
ui.launch()
def destroy() -> None: if facefusion.globals.target_path: clear_temp(facefusion.globals.target_path) if DeepFakeAI.globals.target_path: clear_temp(DeepFakeAI.globals.target_path) sys.exit()2 unmodified lines345676789104 unmodified lines151617181819202117 unmodified lines3940414243444546474243444546474849502 unmodified linesimport insightfaceimport numpy
import facefusion.globalsfrom facefusion.typing import Frame, Face, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGenderimport DeepFakeAI.globalsfrom DeepFakeAI.typing import Frame, Face, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGender
FACE_ANALYSER = NoneTHREAD_LOCK = threading.Lock()4 unmodified lines
with THREAD_LOCK: if FACE_ANALYSER is None: FACE_ANALYSER = insightface.app.FaceAnalysis(name = 'buffalo_l', providers = facefusion.globals.execution_providers) FACE_ANALYSER = insightface.app.FaceAnalysis(name = 'buffalo_l', providers = DeepFakeAI.globals.execution_providers) FACE_ANALYSER.prepare(ctx_id = 0) return FACE_ANALYSER
17 unmodified linesdef get_many_faces(frame : Frame) -> List[Face]: try: faces = get_face_analyser().get(frame) if facefusion.globals.face_analyser_direction: faces = sort_by_direction(faces, facefusion.globals.face_analyser_direction) if facefusion.globals.face_analyser_age: faces = filter_by_age(faces, facefusion.globals.face_analyser_age) if facefusion.globals.face_analyser_gender: faces = filter_by_gender(faces, facefusion.globals.face_analyser_gender) if DeepFakeAI.globals.face_analyser_direction: faces = sort_by_direction(faces, DeepFakeAI.globals.face_analyser_direction) if DeepFakeAI.globals.face_analyser_age: faces = filter_by_age(faces, DeepFakeAI.globals.face_analyser_age) if DeepFakeAI.globals.face_analyser_gender: faces = filter_by_gender(faces, DeepFakeAI.globals.face_analyser_gender) return faces except (AttributeError, ValueError): return []1233456from typing import Optional
from facefusion.typing import Facefrom DeepFakeAI.typing import Face
FACE_REFERENCE = None
1233456from typing import List, Optional
from facefusion.typing import FaceRecognition, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGender, TempFrameFormatfrom DeepFakeAI.typing import FaceRecognition, FaceAnalyserDirection, FaceAnalyserAge, FaceAnalyserGender, TempFrameFormat
source_path : Optional[str] = Nonetarget_path : Optional[str] = None4 unmodified lines56788910114 unmodified lines 'version': '1.0.0', 'license': 'MIT', 'author': 'Henry Ruhs', 'url': 'https://facefusion.io' 'url': 'https://DeepFakeAI.io'}
3 unmodified lines4567789103 unmodified linesfrom PIL import Imagefrom keras import Model
from facefusion.typing import Framefrom DeepFakeAI.typing import Frame
PREDICTOR = NoneTHREAD_LOCK = threading.Lock()7 unmodified lines89101112111213141512 unmodified lines282930313132333417 unmodified lines5253545555565758596061616263646465666729 unmodified lines9798991001011021001011021031041051061071081091091101111111121137 unmodified linesfrom typing import Any, List, Callablefrom tqdm import tqdm
import facefusion.globalsfrom facefusion import wordingimport DeepFakeAI.globalsfrom DeepFakeAI import wording
FRAME_PROCESSORS_MODULES : List[ModuleType] = []FRAME_PROCESSORS_METHODS =\12 unmodified lines
def load_frame_processor_module(frame_processor : str) -> Any: try: frame_processor_module = importlib.import_module('facefusion.processors.frame.modules.' + frame_processor) frame_processor_module = importlib.import_module('DeepFakeAI.processors.frame.modules.' + frame_processor) for method_name in FRAME_PROCESSORS_METHODS: if not hasattr(frame_processor_module, method_name): raise NotImplementedError17 unmodified linesdef clear_frame_processors_modules() -> None: global FRAME_PROCESSORS_MODULES
for frame_processor_module in get_frame_processors_modules(facefusion.globals.frame_processors): for frame_processor_module in get_frame_processors_modules(DeepFakeAI.globals.frame_processors): frame_processor_module.clear_frame_processor() FRAME_PROCESSORS_MODULES = []
def multi_process_frame(source_path : str, temp_frame_paths : List[str], process_frames: Callable[[str, List[str], Any], None], update: Callable[[], None]) -> None: with ThreadPoolExecutor(max_workers = facefusion.globals.execution_thread_count) as executor: with ThreadPoolExecutor(max_workers = DeepFakeAI.globals.execution_thread_count) as executor: futures = [] queue = create_queue(temp_frame_paths) queue_per_future = max(len(temp_frame_paths) // facefusion.globals.execution_thread_count * facefusion.globals.execution_queue_count, 1) queue_per_future = max(len(temp_frame_paths) // DeepFakeAI.globals.execution_thread_count * DeepFakeAI.globals.execution_queue_count, 1) while not queue.empty(): future = executor.submit(process_frames, source_path, pick_queue(queue, queue_per_future), update) futures.append(future)29 unmodified lines progress.set_postfix( { 'memory_usage': '{:.2f}'.format(memory_usage).zfill(5) + 'GB', 'execution_providers': facefusion.globals.execution_providers, 'execution_thread_count': facefusion.globals.execution_thread_count, 'execution_queue_count': facefusion.globals.execution_queue_count 'execution_providers': DeepFakeAI.globals.execution_providers, 'execution_thread_count': DeepFakeAI.globals.execution_thread_count, 'execution_queue_count': DeepFakeAI.globals.execution_queue_count }) progress.refresh() progress.update(1)
def get_device() -> str: if 'CUDAExecutionProvider' in facefusion.globals.execution_providers: if 'CUDAExecutionProvider' in DeepFakeAI.globals.execution_providers: return 'cuda' if 'CoreMLExecutionProvider' in facefusion.globals.execution_providers: if 'CoreMLExecutionProvider' in DeepFakeAI.globals.execution_providers: return 'mps' return 'cpu'2 unmodified lines3456789101112678910111213141523 unmodified lines394041424243444546474748495046 unmodified lines9798991001002 unmodified linesimport threadingfrom gfpgan.utils import GFPGANer
import facefusion.globalsimport facefusion.processors.frame.core as frame_processorsfrom facefusion import wordingfrom facefusion.core import update_statusfrom facefusion.face_analyser import get_many_facesfrom facefusion.typing import Frame, Facefrom facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_videoimport DeepFakeAI.globalsimport DeepFakeAI.processors.frame.core as frame_processorsfrom DeepFakeAI import wordingfrom DeepFakeAI.core import update_statusfrom DeepFakeAI.face_analyser import get_many_facesfrom DeepFakeAI.typing import Frame, Facefrom DeepFakeAI.utilities import conditional_download, resolve_relative_path, is_image, is_video
FRAME_PROCESSOR = NoneTHREAD_SEMAPHORE = threading.Semaphore()23 unmodified lines
def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/GFPGANv1.4.pth']) conditional_download(download_directory_path, ['https://github.com/DeepFakeAI/DeepFakeAI-assets/releases/download/models/GFPGANv1.4.pth']) return True
def pre_process() -> bool: if not is_image(facefusion.globals.target_path) and not is_video(facefusion.globals.target_path): if not is_image(DeepFakeAI.globals.target_path) and not is_video(DeepFakeAI.globals.target_path): update_status(wording.get('select_image_or_video_target') + wording.get('exclamation_mark'), NAME) return False return True46 unmodified lines
def process_video(source_path : str, temp_frame_paths : List[str]) -> None: facefusion.processors.frame.core.process_video(None, temp_frame_paths, process_frames) DeepFakeAI.processors.frame.core.process_video(None, temp_frame_paths, process_frames)2 unmodified lines3456789101112136789101112131415166 unmodified lines23242526262728295 unmodified lines353637383839404142434344454646474849495051528 unmodified lines6162636465646566676869697071723 unmodified lines76777879798081825 unmodified lines88899091919293944 unmodified lines991001011021031041021031041052 unmodified linesimport insightfaceimport threading
import facefusion.globalsimport facefusion.processors.frame.core as frame_processorsfrom facefusion import wordingfrom facefusion.core import update_statusfrom facefusion.face_analyser import get_one_face, get_many_faces, find_similar_facesfrom facefusion.face_reference import get_face_reference, set_face_referencefrom facefusion.typing import Face, Framefrom facefusion.utilities import conditional_download, resolve_relative_path, is_image, is_videoimport DeepFakeAI.globalsimport DeepFakeAI.processors.frame.core as frame_processorsfrom DeepFakeAI import wordingfrom DeepFakeAI.core import update_statusfrom DeepFakeAI.face_analyser import get_one_face, get_many_faces, find_similar_facesfrom DeepFakeAI.face_reference import get_face_reference, set_face_referencefrom DeepFakeAI.typing import Face, Framefrom DeepFakeAI.utilities import conditional_download, resolve_relative_path, is_image, is_video
FRAME_PROCESSOR = NoneTHREAD_LOCK = threading.Lock()6 unmodified lines with THREAD_LOCK: if FRAME_PROCESSOR is None: model_path = resolve_relative_path('../.assets/models/inswapper_128.onnx') FRAME_PROCESSOR = insightface.model_zoo.get_model(model_path, providers = facefusion.globals.execution_providers) FRAME_PROCESSOR = insightface.model_zoo.get_model(model_path, providers = DeepFakeAI.globals.execution_providers) return FRAME_PROCESSOR
5 unmodified lines
def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx']) conditional_download(download_directory_path, ['https://github.com/DeepFakeAI/DeepFakeAI-assets/releases/download/models/inswapper_128.onnx']) return True
def pre_process() -> bool: if not is_image(facefusion.globals.source_path): if not is_image(DeepFakeAI.globals.source_path): update_status(wording.get('select_image_source') + wording.get('exclamation_mark'), NAME) return False elif not get_one_face(cv2.imread(facefusion.globals.source_path)): elif not get_one_face(cv2.imread(DeepFakeAI.globals.source_path)): update_status(wording.get('no_source_face_detected') + wording.get('exclamation_mark'), NAME) return False if not is_image(facefusion.globals.target_path) and not is_video(facefusion.globals.target_path): if not is_image(DeepFakeAI.globals.target_path) and not is_video(DeepFakeAI.globals.target_path): update_status(wording.get('select_image_or_video_target') + wording.get('exclamation_mark'), NAME) return False return True8 unmodified lines
def process_frame(source_face : Face, reference_face : Face, temp_frame : Frame) -> Frame: if 'reference' in facefusion.globals.face_recognition: similar_faces = find_similar_faces(temp_frame, reference_face, facefusion.globals.reference_face_distance) if 'reference' in DeepFakeAI.globals.face_recognition: similar_faces = find_similar_faces(temp_frame, reference_face, DeepFakeAI.globals.reference_face_distance) if similar_faces: for similar_face in similar_faces: temp_frame = swap_face(source_face, similar_face, temp_frame) if 'many' in facefusion.globals.face_recognition: if 'many' in DeepFakeAI.globals.face_recognition: many_faces = get_many_faces(temp_frame) if many_faces: for target_face in many_faces:3 unmodified lines
def process_frames(source_path : str, temp_frame_paths : List[str], update: Callable[[], None]) -> None: source_face = get_one_face(cv2.imread(source_path)) reference_face = get_face_reference() if 'reference' in facefusion.globals.face_recognition else None reference_face = get_face_reference() if 'reference' in DeepFakeAI.globals.face_recognition else None for temp_frame_path in temp_frame_paths: temp_frame = cv2.imread(temp_frame_path) result_frame = process_frame(source_face, reference_face, temp_frame)5 unmodified linesdef 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) reference_face = get_one_face(target_frame, facefusion.globals.reference_face_position) if 'reference' in facefusion.globals.face_recognition else None reference_face = get_one_face(target_frame, DeepFakeAI.globals.reference_face_position) if 'reference' in DeepFakeAI.globals.face_recognition else None result_frame = process_frame(source_face, reference_face, target_frame) cv2.imwrite(output_path, result_frame)
4 unmodified lines
def conditional_set_face_reference(temp_frame_paths : List[str]) -> None: if 'reference' in facefusion.globals.face_recognition and not get_face_reference(): reference_frame = cv2.imread(temp_frame_paths[facefusion.globals.reference_frame_number]) reference_face = get_one_face(reference_frame, facefusion.globals.reference_face_position) if 'reference' in DeepFakeAI.globals.face_recognition and not get_face_reference(): reference_frame = cv2.imread(temp_frame_paths[DeepFakeAI.globals.reference_frame_number]) reference_face = get_one_face(reference_frame, DeepFakeAI.globals.reference_face_position) set_face_reference(reference_face)3 unmodified lines45678978910111234 unmodified lines47484950505152533 unmodified linesfrom basicsr.archs.rrdbnet_arch import RRDBNetfrom realesrgan import RealESRGANer
import facefusion.processors.frame.core as frame_processorsfrom facefusion.typing import Frame, Facefrom facefusion.utilities import conditional_download, resolve_relative_pathimport DeepFakeAI.processors.frame.core as frame_processorsfrom DeepFakeAI.typing import Frame, Facefrom DeepFakeAI.utilities import conditional_download, resolve_relative_path
FRAME_PROCESSOR = NoneTHREAD_SEMAPHORE = threading.Semaphore()34 unmodified lines
def pre_check() -> bool: download_directory_path = resolve_relative_path('../.assets/models') conditional_download(download_directory_path, ['https://github.com/facefusion/facefusion-assets/releases/download/models/RealESRGAN_x4plus.pth']) conditional_download(download_directory_path, ['https://github.com/DeepFakeAI/DeepFakeAI-assets/releases/download/models/RealESRGAN_x4plus.pth']) return True
12344567from typing import Optionalimport gradio
from facefusion import metadatafrom DeepFakeAI import metadata
ABOUT_HTML : Optional[gradio.HTML] = None
3 unmodified lines45678910111278910111213141549 unmodified lines656667686869707112 unmodified lines8485868788898788899091928 unmodified lines1011021031041041051061073 unmodified lines1111121131141151141151163 unmodified linesimport statisticsimport gradio
import facefusion.globalsfrom facefusion import wordingfrom facefusion.capturer import get_video_frame_totalfrom facefusion.core import conditional_processfrom facefusion.uis.typing import Updatefrom facefusion.utilities import normalize_output_path, clear_tempimport DeepFakeAI.globalsfrom DeepFakeAI import wordingfrom DeepFakeAI.capturer import get_video_frame_totalfrom DeepFakeAI.core import conditional_processfrom DeepFakeAI.uis.typing import Updatefrom DeepFakeAI.utilities import normalize_output_path, clear_temp
BENCHMARK_RESULT_DATAFRAME : Optional[gradio.Dataframe] = NoneBENCHMARK_CYCLES_SLIDER : Optional[gradio.Button] = None49 unmodified lines
def update(benchmark_cycles : int) -> Update: facefusion.globals.source_path = '.assets/examples/source.jpg' DeepFakeAI.globals.source_path = '.assets/examples/source.jpg' target_paths =\ [ '.assets/examples/target-240p.mp4',12 unmodified lines process_times = [] total_fps = 0.0 for i in range(benchmark_cycles + 1): facefusion.globals.target_path = target_path facefusion.globals.output_path = normalize_output_path(facefusion.globals.source_path, facefusion.globals.target_path, tempfile.gettempdir()) video_frame_total = get_video_frame_total(facefusion.globals.target_path) DeepFakeAI.globals.target_path = target_path DeepFakeAI.globals.output_path = normalize_output_path(DeepFakeAI.globals.source_path, DeepFakeAI.globals.target_path, tempfile.gettempdir()) video_frame_total = get_video_frame_total(DeepFakeAI.globals.target_path) start_time = time.perf_counter() conditional_process() end_time = time.perf_counter()8 unmodified lines relative_fps = round(total_fps / benchmark_cycles, 2) return\ [ facefusion.globals.target_path, DeepFakeAI.globals.target_path, benchmark_cycles, average_run, fastest_run,3 unmodified lines
def clear() -> Update: if facefusion.globals.target_path: clear_temp(facefusion.globals.target_path) if DeepFakeAI.globals.target_path: clear_temp(DeepFakeAI.globals.target_path) return gradio.update(value = None)1 unmodified line234567891056789101112139 unmodified lines2324252626272829303031323334353637373839409 unmodified lines5051525353545556575858596061626363641 unmodified lineimport gradioimport onnxruntime
import facefusion.globalsfrom facefusion import wordingfrom facefusion.face_analyser import clear_face_analyserfrom facefusion.processors.frame.core import clear_frame_processors_modulesfrom facefusion.uis.typing import Updatefrom facefusion.utilities import encode_execution_providers, decode_execution_providersimport DeepFakeAI.globalsfrom DeepFakeAI import wordingfrom DeepFakeAI.face_analyser import clear_face_analyserfrom DeepFakeAI.processors.frame.core import clear_frame_processors_modulesfrom DeepFakeAI.uis.typing import Updatefrom DeepFakeAI.utilities import encode_execution_providers, decode_execution_providers
EXECUTION_PROVIDERS_CHECKBOX_GROUP : Optional[gradio.CheckboxGroup] = NoneEXECUTION_THREAD_COUNT_SLIDER : Optional[gradio.Slider] = None9 unmodified lines EXECUTION_PROVIDERS_CHECKBOX_GROUP = gradio.CheckboxGroup( label = wording.get('execution_providers_checkbox_group_label'), choices = encode_execution_providers(onnxruntime.get_available_providers()), value = encode_execution_providers(facefusion.globals.execution_providers) value = encode_execution_providers(DeepFakeAI.globals.execution_providers) ) EXECUTION_THREAD_COUNT_SLIDER = gradio.Slider( label = wording.get('execution_thread_count_slider_label'), value = facefusion.globals.execution_thread_count, value = DeepFakeAI.globals.execution_thread_count, step = 1, minimum = 1, maximum = 128 ) EXECUTION_QUEUE_COUNT_SLIDER = gradio.Slider( label = wording.get('execution_queue_count_slider_label'), value = facefusion.globals.execution_queue_count, value = DeepFakeAI.globals.execution_queue_count, step = 1, minimum = 1, maximum = 169 unmodified linesdef update_execution_providers(execution_providers : List[str]) -> Update: clear_face_analyser() clear_frame_processors_modules() facefusion.globals.execution_providers = decode_execution_providers(execution_providers) DeepFakeAI.globals.execution_providers = decode_execution_providers(execution_providers) return gradio.update(value = execution_providers)
def update_execution_thread_count(execution_thread_count : int = 1) -> Update: facefusion.globals.execution_thread_count = execution_thread_count DeepFakeAI.globals.execution_thread_count = execution_thread_count return gradio.update(value = execution_thread_count)
def update_execution_queue_count(execution_queue_count : int = 1) -> Update: facefusion.globals.execution_queue_count = execution_queue_count DeepFakeAI.globals.execution_queue_count = execution_queue_count return gradio.update(value = execution_queue_count)1 unmodified line23456789567891011129 unmodified lines2223242526252627282930313031323334353635363738398 unmodified lines4849505151525353541 unmodified line
import gradio
import facefusion.choicesimport facefusion.globalsfrom facefusion import wordingfrom facefusion.uis import core as uifrom facefusion.uis.typing import Updateimport DeepFakeAI.choicesimport DeepFakeAI.globalsfrom DeepFakeAI import wordingfrom DeepFakeAI.uis import core as uifrom DeepFakeAI.uis.typing import Update
FACE_ANALYSER_DIRECTION_DROPDOWN : Optional[gradio.Dropdown] = NoneFACE_ANALYSER_AGE_DROPDOWN : Optional[gradio.Dropdown] = None9 unmodified lines with gradio.Row(): FACE_ANALYSER_DIRECTION_DROPDOWN = gradio.Dropdown( label = wording.get('face_analyser_direction_dropdown_label'), choices = facefusion.choices.face_analyser_direction, value = facefusion.globals.face_analyser_direction choices = DeepFakeAI.choices.face_analyser_direction, value = DeepFakeAI.globals.face_analyser_direction ) FACE_ANALYSER_AGE_DROPDOWN = gradio.Dropdown( label = wording.get('face_analyser_age_dropdown_label'), choices = ['none'] + facefusion.choices.face_analyser_age, value = facefusion.globals.face_analyser_age or 'none' choices = ['none'] + DeepFakeAI.choices.face_analyser_age, value = DeepFakeAI.globals.face_analyser_age or 'none' ) FACE_ANALYSER_GENDER_DROPDOWN = gradio.Dropdown( label = wording.get('face_analyser_gender_dropdown_label'), choices = ['none'] + facefusion.choices.face_analyser_gender, value = facefusion.globals.face_analyser_gender or 'none' choices = ['none'] + DeepFakeAI.choices.face_analyser_gender, value = DeepFakeAI.globals.face_analyser_gender or 'none' ) ui.register_component('face_analyser_direction_dropdown', FACE_ANALYSER_DIRECTION_DROPDOWN) ui.register_component('face_analyser_age_dropdown', FACE_ANALYSER_AGE_DROPDOWN)8 unmodified lines
def update_dropdown(name : str, value : str) -> Update: if value == 'none': setattr(facefusion.globals, name, None) setattr(DeepFakeAI.globals, name, None) else: setattr(facefusion.globals, name, value) setattr(DeepFakeAI.globals, name, value) return gradio.update(value = value)DeepFakeAI/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/__pycache__/capturer.cpython-310.pyc
DeepFakeAI/__pycache__/choices.cpython-310.pyc
DeepFakeAI/__pycache__/core.cpython-310.pyc
DeepFakeAI/__pycache__/face_analyser.cpython-310.pyc
DeepFakeAI/__pycache__/face_reference.cpython-310.pyc
DeepFakeAI/__pycache__/globals.cpython-310.pyc
DeepFakeAI/__pycache__/metadata.cpython-310.pyc
DeepFakeAI/__pycache__/predictor.cpython-310.pyc
DeepFakeAI/__pycache__/typing.cpython-310.pyc
DeepFakeAI/__pycache__/utilities.cpython-310.pyc
DeepFakeAI/__pycache__/wording.cpython-310.pyc
DeepFakeAI/capturer.py+1-1
DeepFakeAI/choices.py+1-1
DeepFakeAI/core.py+69-69
DeepFakeAI/face_analyser.py+9-9
DeepFakeAI/face_reference.py+1-1
DeepFakeAI/globals.py+1-1
DeepFakeAI/metadata.py+1-1
DeepFakeAI/predictor.py+1-1
DeepFakeAI/processors/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/processors/frame/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/processors/frame/__pycache__/core.cpython-310.pyc
DeepFakeAI/processors/frame/core.py+11-11
DeepFakeAI/processors/frame/modules/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/processors/frame/modules/__pycache__/face_swapper.cpython-310.pyc
DeepFakeAI/processors/frame/modules/face_enhancer.py+10-10
DeepFakeAI/processors/frame/modules/face_swapper.py+21-21
DeepFakeAI/processors/frame/modules/frame_enhancer.py+4-4
DeepFakeAI/uis/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/uis/__pycache__/core.cpython-310.pyc
DeepFakeAI/uis/__pycache__/typing.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/__init__.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/about.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/execution.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/face_analyser.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/face_selector.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/output.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/output_settings.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/preview.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/processors.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/settings.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/source.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/target.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/temp_frame.cpython-310.pyc
DeepFakeAI/uis/components/__pycache__/trim_frame.cpython-310.pyc
DeepFakeAI/uis/components/about.py+1-1
DeepFakeAI/uis/components/benchmark.py+13-13
DeepFakeAI/uis/components/execution.py+12-12
DeepFakeAI/uis/components/face_analyser.py+13-13