Extract download directory path from assets path

This commit is contained in:
henryruhs 2024-11-14 21:09:58 +01:00
parent 74c61108dd
commit 9034a2b490
18 changed files with 29 additions and 44 deletions

View File

@ -54,11 +54,10 @@ def get_model_options() -> ModelOptions:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def analyse_stream(vision_frame : VisionFrame, video_fps : Fps) -> bool:

View File

@ -158,7 +158,6 @@ def conditional_append_reference_faces() -> None:
def force_download() -> ErrorCode:
download_directory_path = resolve_relative_path('../.assets/models')
available_processors = list_directory('facefusion/processors/modules')
common_modules =\
[
@ -179,7 +178,7 @@ def force_download() -> ErrorCode:
model_sources = model.get('sources')
if model_hashes and model_sources:
if not conditional_download_hashes(download_directory_path, model_hashes) or not conditional_download_sources(download_directory_path, model_sources):
if not conditional_download_hashes(model_hashes) or not conditional_download_sources(model_sources):
return 1
return 0

View File

@ -48,7 +48,7 @@ def get_download_size(url : str) -> int:
return 0
def conditional_download_hashes(download_directory_path : str, hashes : DownloadSet) -> bool:
def conditional_download_hashes(hashes : DownloadSet) -> bool:
hash_paths = [ hashes.get(hash_key).get('path') for hash_key in hashes.keys() ]
process_manager.check()
@ -58,6 +58,7 @@ def conditional_download_hashes(download_directory_path : str, hashes : Download
for index in hashes:
if hashes.get(index).get('path') in invalid_hash_paths:
invalid_hash_url = hashes.get(index).get('url')
download_directory_path = os.path.dirname(hashes.get(index).get('path'))
conditional_download(download_directory_path, [ invalid_hash_url ])
valid_hash_paths, invalid_hash_paths = validate_hash_paths(hash_paths)
@ -73,7 +74,7 @@ def conditional_download_hashes(download_directory_path : str, hashes : Download
return not invalid_hash_paths
def conditional_download_sources(download_directory_path : str, sources : DownloadSet) -> bool:
def conditional_download_sources(sources : DownloadSet) -> bool:
source_paths = [ sources.get(source_key).get('path') for source_key in sources.keys() ]
process_manager.check()
@ -83,6 +84,7 @@ def conditional_download_sources(download_directory_path : str, sources : Downlo
for index in sources:
if sources.get(index).get('path') in invalid_source_paths:
invalid_source_url = sources.get(index).get('url')
download_directory_path = os.path.dirname(sources.get(index).get('path'))
conditional_download(download_directory_path, [ invalid_source_url ])
valid_source_paths, invalid_source_paths = validate_source_paths(source_paths)

View File

@ -51,11 +51,10 @@ def get_model_options() -> ModelOptions:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def classify_face(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Gender, Age, Race]:

View File

@ -101,10 +101,9 @@ def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes, model_sources = collect_model_downloads()
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def detect_faces(vision_frame : VisionFrame) -> Tuple[List[BoundingBox], List[Score], List[FaceLandmark5]]:

View File

@ -105,10 +105,9 @@ def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes, model_sources = collect_model_downloads()
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def detect_face_landmarks(vision_frame : VisionFrame, bounding_box : BoundingBox, face_angle : Angle) -> Tuple[FaceLandmark68, Score]:

View File

@ -93,10 +93,9 @@ def collect_model_downloads() -> Tuple[DownloadSet, DownloadSet]:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes, model_sources = collect_model_downloads()
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
@lru_cache(maxsize = None)

View File

@ -49,11 +49,10 @@ def get_model_options() -> ModelOptions:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def calc_embedding(temp_vision_frame : VisionFrame, face_landmark_5 : FaceLandmark5) -> Tuple[Embedding, Embedding]:

View File

@ -91,11 +91,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -55,7 +55,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'jackie_chan_224.hash'),
'path': resolve_relative_path('../.assets/models/jackie_chan_224.hash')
'path': resolve_relative_path('../.assets/models/iperov/jackie_chan_224.hash')
}
},
'sources':
@ -63,7 +63,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'jackie_chan_224.dfm'),
'path': resolve_relative_path('../.assets/models/jackie_chan_224.dfm')
'path': resolve_relative_path('../.assets/models/iperov/jackie_chan_224.dfm')
}
},
'size': (224, 224),
@ -77,7 +77,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'keanu_reeves_320.hash'),
'path': resolve_relative_path('../.assets/models/keanu_reeves_320.hash')
'path': resolve_relative_path('../.assets/models/iperov/keanu_reeves_320.hash')
}
},
'sources':
@ -85,7 +85,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'keanu_reeves_320.dfm'),
'path': resolve_relative_path('../.assets/models/keanu_reeves_320.dfm')
'path': resolve_relative_path('../.assets/models/iperov/keanu_reeves_320.dfm')
}
},
'size': (320, 320),
@ -99,7 +99,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'sylvester_stallone_224.hash'),
'path': resolve_relative_path('../.assets/models/sylvester_stallone_224.hash')
'path': resolve_relative_path('../.assets/models/iperov/sylvester_stallone_224.hash')
}
},
'sources':
@ -107,7 +107,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'sylvester_stallone_224.dfm'),
'path': resolve_relative_path('../.assets/models/sylvester_stallone_224.dfm')
'path': resolve_relative_path('../.assets/models/iperov/sylvester_stallone_224.dfm')
}
},
'size': (224, 224),
@ -121,7 +121,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'taylor_swift_224.hash'),
'path': resolve_relative_path('../.assets/models/taylor_swift_224.hash')
'path': resolve_relative_path('../.assets/models/iperov/taylor_swift_224.hash')
}
},
'sources':
@ -129,7 +129,7 @@ def create_model_set() -> ModelSet:
'deep_swapper':
{
'url': resolve_download_url_by_provider('huggingface', 'deepfacelive-models-iperov', 'taylor_swift_224.dfm'),
'path': resolve_relative_path('../.assets/models/taylor_swift_224.dfm')
'path': resolve_relative_path('../.assets/models/iperov/taylor_swift_224.dfm')
}
},
'size': (224, 224),
@ -167,11 +167,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -102,11 +102,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -158,11 +158,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -249,11 +249,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -365,11 +365,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -157,11 +157,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -412,11 +412,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -99,11 +99,10 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def pre_process(mode : ProcessMode) -> bool:

View File

@ -47,11 +47,10 @@ def get_model_options() -> ModelOptions:
def pre_check() -> bool:
download_directory_path = resolve_relative_path('../.assets/models')
model_hashes = get_model_options().get('hashes')
model_sources = get_model_options().get('sources')
return conditional_download_hashes(download_directory_path, model_hashes) and conditional_download_sources(download_directory_path, model_sources)
return conditional_download_hashes(model_hashes) and conditional_download_sources(model_sources)
def batch_extract_voice(audio : Audio, chunk_size : int, step_size : int) -> Audio: