crash10155 commited on
Commit
136788e
Β·
verified Β·
1 Parent(s): ddf9937

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -114,9 +114,21 @@ def download_required_models():
114
  import urllib.error
115
 
116
  models_to_download = [
 
 
 
 
 
 
 
 
 
 
 
 
117
  {
118
  'name': 'GFPGANv1.4.pth',
119
- 'url': 'https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth',
120
  'path': ASSETS_DIR / 'GFPGANv1.4.pth',
121
  'description': 'GFPGAN face enhancement model'
122
  }
@@ -137,6 +149,7 @@ def download_required_models():
137
 
138
  try:
139
  print(f"πŸ“₯ Downloading {model_name}...")
 
140
  print(f" URL: {model_url}")
141
  print(f" Path: {model_path}")
142
 
@@ -147,11 +160,28 @@ def download_required_models():
147
  def progress_callback(block_num, block_size, total_size):
148
  if total_size > 0:
149
  percent = min(100, (block_num * block_size * 100) / total_size)
150
- if block_num % 100 == 0: # Update every 100 blocks to avoid spam
151
  print(f" Progress: {percent:.1f}%")
152
 
153
- # Download with progress
154
- urllib.request.urlretrieve(model_url, str(model_path), progress_callback)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  # Verify download
157
  if model_path.exists() and model_path.stat().st_size > 1024:
@@ -168,7 +198,7 @@ def download_required_models():
168
  except Exception as e:
169
  print(f"❌ Error downloading {model_name}: {e}")
170
 
171
- # Download models at startup
172
  print("\nπŸ”„ Checking required model files...")
173
  try:
174
  download_required_models()
 
114
  import urllib.error
115
 
116
  models_to_download = [
117
+ {
118
+ 'name': 'inswapper_128_fp16.onnx',
119
+ 'url': 'https://huggingface.co/ninjawick/webui-faceswap-unlocked/resolve/main/inswapper_128_fp16.onnx',
120
+ 'path': ASSETS_DIR / 'inswapper_128_fp16.onnx',
121
+ 'description': 'InSwapper FP16 face swap model'
122
+ },
123
+ {
124
+ 'name': 'inswapper_128.onnx',
125
+ 'url': 'https://huggingface.co/xingren23/comfyflow-models/resolve/main/insightface/inswapper_128.onnx',
126
+ 'path': ASSETS_DIR / 'inswapper_128.onnx',
127
+ 'description': 'InSwapper face swap model'
128
+ },
129
  {
130
  'name': 'GFPGANv1.4.pth',
131
+ 'url': 'https://huggingface.co/gmk123/GFPGAN/resolve/main/GFPGANv1.4.pth',
132
  'path': ASSETS_DIR / 'GFPGANv1.4.pth',
133
  'description': 'GFPGAN face enhancement model'
134
  }
 
149
 
150
  try:
151
  print(f"πŸ“₯ Downloading {model_name}...")
152
+ print(f" Description: {model['description']}")
153
  print(f" URL: {model_url}")
154
  print(f" Path: {model_path}")
155
 
 
160
  def progress_callback(block_num, block_size, total_size):
161
  if total_size > 0:
162
  percent = min(100, (block_num * block_size * 100) / total_size)
163
+ if block_num % 200 == 0: # Update every 200 blocks to avoid spam
164
  print(f" Progress: {percent:.1f}%")
165
 
166
+ # Download with progress and proper headers for HuggingFace
167
+ req = urllib.request.Request(model_url)
168
+ req.add_header('User-Agent', 'Mozilla/5.0 (compatible; FaceSwapStudio/1.0)')
169
+
170
+ with urllib.request.urlopen(req) as response:
171
+ total_size = int(response.headers.get('Content-Length', 0))
172
+ downloaded = 0
173
+
174
+ with open(model_path, 'wb') as f:
175
+ while True:
176
+ chunk = response.read(8192)
177
+ if not chunk:
178
+ break
179
+ f.write(chunk)
180
+ downloaded += len(chunk)
181
+
182
+ if total_size > 0 and downloaded % (8192 * 100) == 0: # Progress every ~800KB
183
+ percent = (downloaded * 100) / total_size
184
+ print(f" Progress: {percent:.1f}%")
185
 
186
  # Verify download
187
  if model_path.exists() and model_path.stat().st_size > 1024:
 
198
  except Exception as e:
199
  print(f"❌ Error downloading {model_name}: {e}")
200
 
201
+ # Download models at startup - BEFORE web interface
202
  print("\nπŸ”„ Checking required model files...")
203
  try:
204
  download_required_models()