Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -330,18 +330,39 @@ def initialize_system():
|
|
| 330 |
os.makedirs(base_dir, exist_ok=True)
|
| 331 |
os.makedirs(os.path.join(base_dir, "models"), exist_ok=True)
|
| 332 |
|
| 333 |
-
#
|
| 334 |
-
|
|
|
|
| 335 |
|
| 336 |
-
|
| 337 |
-
os.makedirs(xcodec_path, exist_ok=True)
|
| 338 |
|
| 339 |
-
# xcodec_mini_infer
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
# YuE λͺ¨λΈλ€ λ€μ΄λ‘λ
|
| 347 |
models = [
|
|
@@ -351,30 +372,38 @@ def initialize_system():
|
|
| 351 |
"m-a-p/YuE-s2-1B-general"
|
| 352 |
]
|
| 353 |
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
-
#
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
-
|
| 368 |
-
required_files = [
|
| 369 |
-
os.path.join("xcodec_mini_infer", "config.json"),
|
| 370 |
-
os.path.join("xcodec_mini_infer", "vocal_decoder.pth"),
|
| 371 |
-
os.path.join("xcodec_mini_infer", "inst_decoder.pth")
|
| 372 |
-
]
|
| 373 |
|
| 374 |
-
for file_path in required_files:
|
| 375 |
-
if not os.path.exists(file_path):
|
| 376 |
-
raise FileNotFoundError(f"Required file not found: {file_path}")
|
| 377 |
-
|
| 378 |
except Exception as e:
|
| 379 |
logging.error(f"Directory error: {e}")
|
| 380 |
raise
|
|
|
|
| 330 |
os.makedirs(base_dir, exist_ok=True)
|
| 331 |
os.makedirs(os.path.join(base_dir, "models"), exist_ok=True)
|
| 332 |
|
| 333 |
+
# μμ
λλ ν 리 λ³κ²½
|
| 334 |
+
os.chdir(base_dir)
|
| 335 |
+
logging.info(f"Working directory changed to: {os.getcwd()}")
|
| 336 |
|
| 337 |
+
from huggingface_hub import snapshot_download, hf_hub_download
|
|
|
|
| 338 |
|
| 339 |
+
# xcodec_mini_infer νμΌλ€ μ§μ λ€μ΄λ‘λ
|
| 340 |
+
xcodec_dir = os.path.join(base_dir, "xcodec_mini_infer")
|
| 341 |
+
os.makedirs(xcodec_dir, exist_ok=True)
|
| 342 |
+
|
| 343 |
+
# νμ νμΌ μ§μ λ€μ΄λ‘λ
|
| 344 |
+
required_files = {
|
| 345 |
+
"config.json": "config.json",
|
| 346 |
+
"vocal_decoder.pth": "vocal_decoder.pth",
|
| 347 |
+
"inst_decoder.pth": "inst_decoder.pth"
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
for file_name in required_files.keys():
|
| 351 |
+
try:
|
| 352 |
+
file_path = os.path.join(xcodec_dir, file_name)
|
| 353 |
+
if not os.path.exists(file_path):
|
| 354 |
+
downloaded_path = hf_hub_download(
|
| 355 |
+
repo_id="m-a-p/xcodec_mini_infer",
|
| 356 |
+
filename=file_name,
|
| 357 |
+
local_dir=xcodec_dir,
|
| 358 |
+
force_download=True
|
| 359 |
+
)
|
| 360 |
+
if downloaded_path != file_path:
|
| 361 |
+
shutil.copy2(downloaded_path, file_path)
|
| 362 |
+
logging.info(f"Downloaded {file_name} to {file_path}")
|
| 363 |
+
except Exception as e:
|
| 364 |
+
logging.error(f"Error downloading {file_name}: {e}")
|
| 365 |
+
raise
|
| 366 |
|
| 367 |
# YuE λͺ¨λΈλ€ λ€μ΄λ‘λ
|
| 368 |
models = [
|
|
|
|
| 372 |
"m-a-p/YuE-s2-1B-general"
|
| 373 |
]
|
| 374 |
|
| 375 |
+
with ThreadPoolExecutor(max_workers=4) as executor:
|
| 376 |
+
futures = []
|
| 377 |
+
|
| 378 |
+
# Flash Attention μ€μΉ
|
| 379 |
+
futures.append(executor.submit(install_flash_attn))
|
| 380 |
+
|
| 381 |
+
# λͺ¨λΈ λ€μ΄λ‘λ
|
| 382 |
+
for model in models:
|
| 383 |
+
model_name = model.split('/')[-1]
|
| 384 |
+
model_path = os.path.join(base_dir, "models", model_name)
|
| 385 |
+
futures.append(executor.submit(
|
| 386 |
+
snapshot_download,
|
| 387 |
+
repo_id=model,
|
| 388 |
+
local_dir=model_path,
|
| 389 |
+
force_download=True
|
| 390 |
+
))
|
| 391 |
+
|
| 392 |
+
# λͺ¨λ μμ
μλ£ λκΈ°
|
| 393 |
+
for future in futures:
|
| 394 |
+
future.result()
|
| 395 |
|
| 396 |
+
# νμΌ μ‘΄μ¬ νμΈ
|
| 397 |
+
for file_name, _ in required_files.items():
|
| 398 |
+
file_path = os.path.join(xcodec_dir, file_name)
|
| 399 |
+
if not os.path.exists(file_path):
|
| 400 |
+
raise FileNotFoundError(f"Required file still missing after download: {file_path}")
|
| 401 |
+
else:
|
| 402 |
+
file_size = os.path.getsize(file_path)
|
| 403 |
+
logging.info(f"Verified {file_name}: {file_size} bytes")
|
| 404 |
|
| 405 |
+
logging.info("System initialization completed successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
except Exception as e:
|
| 408 |
logging.error(f"Directory error: {e}")
|
| 409 |
raise
|