Commit
·
2d64c58
1
Parent(s):
1651cda
FaceSwapper: use hf_hub_download before mirrors; avoid 404 on Spaces
Browse files
DeepFakeAI/processors/frame/modules/face_swapper.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
import cv2
|
| 4 |
import insightface
|
| 5 |
import threading
|
|
|
|
| 6 |
|
| 7 |
import DeepFakeAI.globals
|
| 8 |
import DeepFakeAI.processors.frame.core as frame_processors
|
|
@@ -32,12 +33,27 @@ def get_frame_processor() -> Any:
|
|
| 32 |
local_dir = resolve_relative_path('../.assets/models')
|
| 33 |
local_model_path = os.path.join(local_dir, 'inswapper_128.onnx')
|
| 34 |
if not os.path.exists(local_model_path):
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
'
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
FRAME_PROCESSOR = insightface.model_zoo.get_model(model_path, providers = DeepFakeAI.globals.execution_providers)
|
| 42 |
return FRAME_PROCESSOR
|
| 43 |
|
|
|
|
| 3 |
import cv2
|
| 4 |
import insightface
|
| 5 |
import threading
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
import DeepFakeAI.globals
|
| 9 |
import DeepFakeAI.processors.frame.core as frame_processors
|
|
|
|
| 33 |
local_dir = resolve_relative_path('../.assets/models')
|
| 34 |
local_model_path = os.path.join(local_dir, 'inswapper_128.onnx')
|
| 35 |
if not os.path.exists(local_model_path):
|
| 36 |
+
# Try Hugging Face Hub first to avoid 404s on GitHub mirrors
|
| 37 |
+
token = os.environ.get('TOKEN') or os.environ.get('HF_TOKEN')
|
| 38 |
+
for repo_id in [
|
| 39 |
+
'zihaomu/inswapper_128.onnx',
|
| 40 |
+
'linyi/inswapper_128.onnx',
|
| 41 |
+
'banodoco/inswapper_128.onnx',
|
| 42 |
+
]:
|
| 43 |
+
try:
|
| 44 |
+
model_path = hf_hub_download(repo_id=repo_id, filename='inswapper_128.onnx', token=token)
|
| 45 |
+
break
|
| 46 |
+
except Exception:
|
| 47 |
+
model_path = None # keep trying
|
| 48 |
+
# If HF Hub failed, try public mirrors as a last resort
|
| 49 |
+
if not model_path:
|
| 50 |
+
conditional_download(local_dir, [
|
| 51 |
+
'https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx',
|
| 52 |
+
'https://huggingface.co/banodoco/inswapper_128.onnx/resolve/main/inswapper_128.onnx'
|
| 53 |
+
])
|
| 54 |
+
model_path = local_model_path
|
| 55 |
+
else:
|
| 56 |
+
model_path = local_model_path
|
| 57 |
FRAME_PROCESSOR = insightface.model_zoo.get_model(model_path, providers = DeepFakeAI.globals.execution_providers)
|
| 58 |
return FRAME_PROCESSOR
|
| 59 |
|