LogicGoInfotechSpaces commited on
Commit
d1d62d4
Β·
1 Parent(s): ef4098e

feat: auto-download inswapper_128.onnx via hf_hub with TOKEN fallback

Browse files
Files changed (2) hide show
  1. app.py +11 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -10,6 +10,7 @@ import os as _os
10
  import DeepFakeAI.globals as DF_G
11
  from DeepFakeAI import utilities as DF_U
12
  from DeepFakeAI.processors.frame.modules import face_swapper as DF_FS
 
13
 
14
  # ── config ───────────────────────────────────────────────────────────
15
  hf_token = os.environ.get("TOKEN")
@@ -67,7 +68,16 @@ def _run_local_faceswap(source_image_path: str, target_video_path: str) -> Optio
67
  except Exception:
68
  pass
69
 
70
- # Ensure model exists
 
 
 
 
 
 
 
 
 
71
  DF_FS.pre_check()
72
 
73
  # Extract frames
 
10
  import DeepFakeAI.globals as DF_G
11
  from DeepFakeAI import utilities as DF_U
12
  from DeepFakeAI.processors.frame.modules import face_swapper as DF_FS
13
+ from huggingface_hub import hf_hub_download
14
 
15
  # ── config ───────────────────────────────────────────────────────────
16
  hf_token = os.environ.get("TOKEN")
 
68
  except Exception:
69
  pass
70
 
71
+ # Ensure model exists (try bundled path; if missing, download via hf_hub)
72
+ model_dir = DF_U.resolve_relative_path('../.assets/models')
73
+ os.makedirs(model_dir, exist_ok=True)
74
+ model_path = os.path.join(model_dir, 'inswapper_128.onnx')
75
+ if not os.path.exists(model_path):
76
+ try:
77
+ token = os.environ.get('TOKEN') or os.environ.get('HF_TOKEN')
78
+ model_path = hf_hub_download(repo_id='banodoco/inswapper_128.onnx', filename='inswapper_128.onnx', token=token)
79
+ except Exception:
80
+ pass
81
  DF_FS.pre_check()
82
 
83
  # Extract frames
requirements.txt CHANGED
@@ -8,4 +8,5 @@ numpy==1.24.3
8
  insightface==0.7.3
9
  onnxruntime==1.17.3
10
  psutil==5.9.5
11
- tqdm==4.65.0
 
 
8
  insightface==0.7.3
9
  onnxruntime==1.17.3
10
  psutil==5.9.5
11
+ tqdm==4.65.0
12
+ huggingface_hub>=0.23.0