ginipick commited on
Commit
a406e84
ยท
verified ยท
1 Parent(s): 7621f85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -37
app.py CHANGED
@@ -202,42 +202,55 @@ def install_flash_attn():
202
  return False
203
 
204
 
205
-
206
-
207
  def download_missing_files():
208
  try:
209
  from huggingface_hub import hf_hub_download, snapshot_download
210
 
211
  # xcodec_mini_infer ํŒŒ์ผ๋“ค ์ง์ ‘ ๋‹ค์šด๋กœ๋“œ
 
212
  files_to_download = {
213
- "config.json": "config.json",
214
- "vocal_decoder.pth": "vocal_decoder.pth",
215
- "inst_decoder.pth": "inst_decoder.pth"
216
  }
217
 
218
  xcodec_dir = "./xcodec_mini_infer"
219
  os.makedirs(xcodec_dir, exist_ok=True)
 
220
 
221
- for file_name in files_to_download.keys():
222
  try:
223
  downloaded_path = hf_hub_download(
224
- repo_id="m-a-p/xcodec_mini_infer",
225
- filename=file_name,
226
- local_dir=xcodec_dir,
227
  force_download=True,
228
  local_files_only=False
229
  )
230
- logging.info(f"Downloaded {file_name} to: {downloaded_path}")
231
 
232
- # ํŒŒ์ผ ์œ„์น˜ ํ™•์ธ ๋ฐ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ณต์‚ฌ
233
- target_path = os.path.join(xcodec_dir, file_name)
234
- if downloaded_path != target_path:
235
- shutil.copy2(downloaded_path, target_path)
236
- logging.info(f"Copied {file_name} to correct location: {target_path}")
237
 
238
  except Exception as e:
239
- logging.error(f"Error downloading {file_name}: {e}")
240
- raise
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
  # YuE ๋ชจ๋ธ๋“ค ๋‹ค์šด๋กœ๋“œ
243
  models = [
@@ -252,23 +265,24 @@ def download_missing_files():
252
  model_path = snapshot_download(
253
  repo_id=model,
254
  local_dir=f"./models/{model_name}",
 
255
  resume_download=True,
256
- force_download=True,
257
- local_files_only=False
258
  )
259
  logging.info(f"Downloaded {model_name} to: {model_path}")
 
 
 
 
 
 
 
 
 
 
260
 
261
  logging.info("All required models downloaded successfully")
262
 
263
- # ํŒŒ์ผ ์กด์žฌ ํ™•์ธ
264
- for file_name in files_to_download.keys():
265
- file_path = os.path.join(xcodec_dir, file_name)
266
- if not os.path.exists(file_path):
267
- raise FileNotFoundError(f"Failed to download {file_name}")
268
- else:
269
- file_size = os.path.getsize(file_path)
270
- logging.info(f"Verified {file_name}: {file_size} bytes")
271
-
272
  except Exception as e:
273
  logging.error(f"Error downloading models: {e}")
274
  raise
@@ -319,25 +333,21 @@ def initialize_system():
319
  os.makedirs("./inference/models", exist_ok=True)
320
  os.makedirs("./inference/models/cache", exist_ok=True)
321
  os.makedirs("./inference/xcodec_mini_infer", exist_ok=True)
 
322
 
323
  # inference ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™
324
  os.chdir("./inference")
325
  logging.info(f"Working directory changed to: {os.getcwd()}")
326
 
327
  # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
328
- os.environ["HF_HOME"] = os.path.abspath("./models/cache")
329
- os.environ["TRANSFORMERS_CACHE"] = os.path.abspath("./models/cache")
 
 
330
 
331
  # ๋ชจ๋ธ ํŒŒ์ผ ์ฒดํฌ ๋ฐ ๋‹ค์šด๋กœ๋“œ
332
  check_model_files()
333
 
334
- # ํŒŒ์ผ ๊ถŒํ•œ ํ™•์ธ
335
- xcodec_dir = "./xcodec_mini_infer"
336
- for file_name in ["config.json", "vocal_decoder.pth", "inst_decoder.pth"]:
337
- file_path = os.path.join(xcodec_dir, file_name)
338
- if os.path.exists(file_path):
339
- os.chmod(file_path, 0o644) # ์ฝ๊ธฐ ๊ถŒํ•œ ํ™•์ธ
340
-
341
  logging.info("System initialization completed successfully")
342
 
343
  except Exception as e:
 
202
  return False
203
 
204
 
 
 
205
  def download_missing_files():
206
  try:
207
  from huggingface_hub import hf_hub_download, snapshot_download
208
 
209
  # xcodec_mini_infer ํŒŒ์ผ๋“ค ์ง์ ‘ ๋‹ค์šด๋กœ๋“œ
210
+ repo_id = "hf-internal-testing/xcodec_mini_infer" # ์ €์žฅ์†Œ ๊ฒฝ๋กœ ์ˆ˜์ •
211
  files_to_download = {
212
+ "config.json": "config/config.json",
213
+ "vocal_decoder.pth": "checkpoints/vocal_decoder.pth",
214
+ "inst_decoder.pth": "checkpoints/inst_decoder.pth"
215
  }
216
 
217
  xcodec_dir = "./xcodec_mini_infer"
218
  os.makedirs(xcodec_dir, exist_ok=True)
219
+ os.makedirs(os.path.join(xcodec_dir, "checkpoints"), exist_ok=True)
220
 
221
+ for target_name, source_path in files_to_download.items():
222
  try:
223
  downloaded_path = hf_hub_download(
224
+ repo_id=repo_id,
225
+ filename=source_path,
226
+ cache_dir="./models/cache",
227
  force_download=True,
228
  local_files_only=False
229
  )
230
+ logging.info(f"Downloaded {source_path} to: {downloaded_path}")
231
 
232
+ # ํŒŒ์ผ์„ ์˜ฌ๋ฐ”๋ฅธ ์œ„์น˜๋กœ ๋ณต์‚ฌ
233
+ target_path = os.path.join(xcodec_dir, target_name)
234
+ shutil.copy2(downloaded_path, target_path)
235
+ logging.info(f"Copied to: {target_path}")
 
236
 
237
  except Exception as e:
238
+ logging.error(f"Error downloading {source_path}: {e}")
239
+ # ๋Œ€์ฒด ์ €์žฅ์†Œ ์‹œ๋„
240
+ try:
241
+ alt_repo_id = "facebook/musicgen-small"
242
+ downloaded_path = hf_hub_download(
243
+ repo_id=alt_repo_id,
244
+ filename=source_path,
245
+ cache_dir="./models/cache",
246
+ force_download=True
247
+ )
248
+ target_path = os.path.join(xcodec_dir, target_name)
249
+ shutil.copy2(downloaded_path, target_path)
250
+ logging.info(f"Downloaded from alternate source to: {target_path}")
251
+ except Exception as alt_e:
252
+ logging.error(f"Error with alternate download: {alt_e}")
253
+ raise
254
 
255
  # YuE ๋ชจ๋ธ๋“ค ๋‹ค์šด๋กœ๋“œ
256
  models = [
 
265
  model_path = snapshot_download(
266
  repo_id=model,
267
  local_dir=f"./models/{model_name}",
268
+ cache_dir="./models/cache",
269
  resume_download=True,
270
+ force_download=True
 
271
  )
272
  logging.info(f"Downloaded {model_name} to: {model_path}")
273
+
274
+ # ํŒŒ์ผ ์กด์žฌ ๋ฐ ํฌ๊ธฐ ํ™•์ธ
275
+ for target_name in files_to_download.keys():
276
+ file_path = os.path.join(xcodec_dir, target_name)
277
+ if not os.path.exists(file_path):
278
+ raise FileNotFoundError(f"Failed to download {target_name}")
279
+ file_size = os.path.getsize(file_path)
280
+ if file_size == 0:
281
+ raise FileNotFoundError(f"Downloaded file is empty: {target_name}")
282
+ logging.info(f"Verified {target_name}: {file_size} bytes")
283
 
284
  logging.info("All required models downloaded successfully")
285
 
 
 
 
 
 
 
 
 
 
286
  except Exception as e:
287
  logging.error(f"Error downloading models: {e}")
288
  raise
 
333
  os.makedirs("./inference/models", exist_ok=True)
334
  os.makedirs("./inference/models/cache", exist_ok=True)
335
  os.makedirs("./inference/xcodec_mini_infer", exist_ok=True)
336
+ os.makedirs("./inference/xcodec_mini_infer/checkpoints", exist_ok=True)
337
 
338
  # inference ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™
339
  os.chdir("./inference")
340
  logging.info(f"Working directory changed to: {os.getcwd()}")
341
 
342
  # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
343
+ cache_dir = os.path.abspath("./models/cache")
344
+ os.environ["HF_HOME"] = cache_dir
345
+ os.environ["TRANSFORMERS_CACHE"] = cache_dir
346
+ os.environ["HF_HUB_CACHE"] = cache_dir
347
 
348
  # ๋ชจ๋ธ ํŒŒ์ผ ์ฒดํฌ ๋ฐ ๋‹ค์šด๋กœ๋“œ
349
  check_model_files()
350
 
 
 
 
 
 
 
 
351
  logging.info("System initialization completed successfully")
352
 
353
  except Exception as e: