Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -214,55 +214,43 @@ def initialize_system():
|
|
| 214 |
# ์ ๋ ๊ฒฝ๋ก ์ค์
|
| 215 |
app_dir = os.path.abspath(os.path.dirname(__file__))
|
| 216 |
inference_dir = os.path.join(app_dir, "inference")
|
| 217 |
-
models_dir = os.path.join(inference_dir, "models")
|
| 218 |
|
| 219 |
# ๊ธฐ๋ณธ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ ์์ฑ
|
| 220 |
os.makedirs(inference_dir, exist_ok=True)
|
| 221 |
-
os.makedirs(
|
| 222 |
os.makedirs(os.path.join(inference_dir, "xcodec_mini_infer"), exist_ok=True)
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 225 |
|
| 226 |
-
# models ๋ชจ๋ ๋ค์ด๋ก๋
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
for file_name in models_files:
|
| 234 |
-
file_path = hf_hub_download(
|
| 235 |
-
repo_id="m-a-p/xcodec_mini_infer",
|
| 236 |
-
filename=f"models/{file_name}",
|
| 237 |
-
local_dir=inference_dir,
|
| 238 |
-
force_download=True
|
| 239 |
-
)
|
| 240 |
-
target_path = os.path.join(models_dir, file_name)
|
| 241 |
-
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
| 242 |
-
shutil.copy2(file_path, target_path)
|
| 243 |
-
logging.info(f"Copied {file_name} to: {target_path}")
|
| 244 |
-
except Exception as e:
|
| 245 |
-
logging.error(f"Error downloading models files: {e}")
|
| 246 |
-
raise
|
| 247 |
|
| 248 |
-
#
|
| 249 |
try:
|
| 250 |
-
|
| 251 |
repo_id="m-a-p/xcodec_mini_infer",
|
| 252 |
-
filename="
|
| 253 |
-
|
| 254 |
force_download=True
|
| 255 |
)
|
| 256 |
-
|
| 257 |
except Exception as e:
|
| 258 |
-
logging.error(f"
|
| 259 |
raise
|
| 260 |
|
| 261 |
# xcodec_mini_infer ๋ชจ๋ธ ๋ค์ด๋ก๋
|
| 262 |
-
xcodec_path = os.path.join(inference_dir, "xcodec_mini_infer")
|
| 263 |
snapshot_download(
|
| 264 |
repo_id="m-a-p/xcodec_mini_infer",
|
| 265 |
-
local_dir=
|
| 266 |
force_download=True
|
| 267 |
)
|
| 268 |
|
|
@@ -276,30 +264,23 @@ def initialize_system():
|
|
| 276 |
|
| 277 |
for model in models:
|
| 278 |
model_name = model.split('/')[-1]
|
| 279 |
-
model_path = os.path.join(inference_dir, "models", model_name)
|
| 280 |
snapshot_download(
|
| 281 |
repo_id=model,
|
| 282 |
-
local_dir=
|
| 283 |
force_download=True
|
| 284 |
)
|
| 285 |
|
| 286 |
-
# ์์
๋๋ ํ ๋ฆฌ ๋ณ๊ฒฝ
|
| 287 |
-
os.chdir(inference_dir)
|
| 288 |
-
logging.info(f"Working directory changed to: {os.getcwd()}")
|
| 289 |
-
|
| 290 |
# PYTHONPATH ์ค์
|
| 291 |
if inference_dir not in sys.path:
|
| 292 |
sys.path.insert(0, inference_dir)
|
| 293 |
-
logging.info(f"Added to PYTHONPATH: {inference_dir}")
|
| 294 |
|
| 295 |
# ํ์ผ ์กด์ฌ ํ์ธ
|
| 296 |
required_files = [
|
| 297 |
-
os.path.join(inference_dir, "infer.py"),
|
| 298 |
-
os.path.join(models_dir, "soundstream_hubert_new.py"),
|
| 299 |
os.path.join(models_dir, "__init__.py"),
|
| 300 |
-
os.path.join(
|
| 301 |
-
os.path.join(
|
| 302 |
-
os.path.join(
|
|
|
|
| 303 |
]
|
| 304 |
|
| 305 |
for file_path in required_files:
|
|
@@ -415,8 +396,9 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
| 415 |
"--max_new_tokens", str(actual_max_tokens),
|
| 416 |
"--disable_offload_model"
|
| 417 |
]
|
| 418 |
-
|
| 419 |
env = os.environ.copy()
|
|
|
|
|
|
|
| 420 |
if torch.cuda.is_available():
|
| 421 |
env.update({
|
| 422 |
"CUDA_VISIBLE_DEVICES": "0",
|
|
@@ -425,7 +407,7 @@ def infer(genre_txt_content, lyrics_txt_content, num_segments, max_new_tokens):
|
|
| 425 |
"LD_LIBRARY_PATH": f"/usr/local/cuda/lib64:{env.get('LD_LIBRARY_PATH', '')}",
|
| 426 |
"PYTORCH_CUDA_ALLOC_CONF": "max_split_size_mb:512",
|
| 427 |
"CUDA_LAUNCH_BLOCKING": "0",
|
| 428 |
-
"PYTHONPATH":
|
| 429 |
})
|
| 430 |
|
| 431 |
# transformers ์บ์ ๋ง์ด๊ทธ๋ ์ด์
์ฒ๋ฆฌ
|
|
|
|
| 214 |
# ์ ๋ ๊ฒฝ๋ก ์ค์
|
| 215 |
app_dir = os.path.abspath(os.path.dirname(__file__))
|
| 216 |
inference_dir = os.path.join(app_dir, "inference")
|
|
|
|
| 217 |
|
| 218 |
# ๊ธฐ๋ณธ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ ์์ฑ
|
| 219 |
os.makedirs(inference_dir, exist_ok=True)
|
| 220 |
+
os.makedirs(os.path.join(inference_dir, "models"), exist_ok=True)
|
| 221 |
os.makedirs(os.path.join(inference_dir, "xcodec_mini_infer"), exist_ok=True)
|
| 222 |
|
| 223 |
+
# ์์
๋๋ ํ ๋ฆฌ ๋ณ๊ฒฝ
|
| 224 |
+
os.chdir(inference_dir)
|
| 225 |
+
logging.info(f"Working directory changed to: {os.getcwd()}")
|
| 226 |
+
|
| 227 |
from huggingface_hub import snapshot_download, hf_hub_download
|
| 228 |
|
| 229 |
+
# models ๋ชจ๋ ํ์ผ ๋ค์ด๋ก๋ ๋ฐ ์ค์
|
| 230 |
+
models_dir = os.path.join(inference_dir, "models")
|
| 231 |
+
os.makedirs(models_dir, exist_ok=True)
|
| 232 |
+
|
| 233 |
+
# __init__.py ์์ฑ
|
| 234 |
+
with open(os.path.join(models_dir, "__init__.py"), "w") as f:
|
| 235 |
+
f.write("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
+
# soundstream_hubert_new.py ๋ค์ด๋ก๋
|
| 238 |
try:
|
| 239 |
+
soundstream_file = hf_hub_download(
|
| 240 |
repo_id="m-a-p/xcodec_mini_infer",
|
| 241 |
+
filename="models/soundstream_hubert_new.py",
|
| 242 |
+
cache_dir=os.path.join(inference_dir, "cache"),
|
| 243 |
force_download=True
|
| 244 |
)
|
| 245 |
+
shutil.copy2(soundstream_file, os.path.join(models_dir, "soundstream_hubert_new.py"))
|
| 246 |
except Exception as e:
|
| 247 |
+
logging.error(f"Failed to download soundstream_hubert_new.py: {e}")
|
| 248 |
raise
|
| 249 |
|
| 250 |
# xcodec_mini_infer ๋ชจ๋ธ ๋ค์ด๋ก๋
|
|
|
|
| 251 |
snapshot_download(
|
| 252 |
repo_id="m-a-p/xcodec_mini_infer",
|
| 253 |
+
local_dir=os.path.join(inference_dir, "xcodec_mini_infer"),
|
| 254 |
force_download=True
|
| 255 |
)
|
| 256 |
|
|
|
|
| 264 |
|
| 265 |
for model in models:
|
| 266 |
model_name = model.split('/')[-1]
|
|
|
|
| 267 |
snapshot_download(
|
| 268 |
repo_id=model,
|
| 269 |
+
local_dir=os.path.join(inference_dir, "models", model_name),
|
| 270 |
force_download=True
|
| 271 |
)
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
# PYTHONPATH ์ค์
|
| 274 |
if inference_dir not in sys.path:
|
| 275 |
sys.path.insert(0, inference_dir)
|
|
|
|
| 276 |
|
| 277 |
# ํ์ผ ์กด์ฌ ํ์ธ
|
| 278 |
required_files = [
|
|
|
|
|
|
|
| 279 |
os.path.join(models_dir, "__init__.py"),
|
| 280 |
+
os.path.join(models_dir, "soundstream_hubert_new.py"),
|
| 281 |
+
os.path.join(inference_dir, "xcodec_mini_infer", "config.json"),
|
| 282 |
+
os.path.join(inference_dir, "xcodec_mini_infer", "vocal_decoder.pth"),
|
| 283 |
+
os.path.join(inference_dir, "xcodec_mini_infer", "inst_decoder.pth")
|
| 284 |
]
|
| 285 |
|
| 286 |
for file_path in required_files:
|
|
|
|
| 396 |
"--max_new_tokens", str(actual_max_tokens),
|
| 397 |
"--disable_offload_model"
|
| 398 |
]
|
|
|
|
| 399 |
env = os.environ.copy()
|
| 400 |
+
current_dir = os.getcwd()
|
| 401 |
+
|
| 402 |
if torch.cuda.is_available():
|
| 403 |
env.update({
|
| 404 |
"CUDA_VISIBLE_DEVICES": "0",
|
|
|
|
| 407 |
"LD_LIBRARY_PATH": f"/usr/local/cuda/lib64:{env.get('LD_LIBRARY_PATH', '')}",
|
| 408 |
"PYTORCH_CUDA_ALLOC_CONF": "max_split_size_mb:512",
|
| 409 |
"CUDA_LAUNCH_BLOCKING": "0",
|
| 410 |
+
"PYTHONPATH": current_dir
|
| 411 |
})
|
| 412 |
|
| 413 |
# transformers ์บ์ ๋ง์ด๊ทธ๋ ์ด์
์ฒ๋ฆฌ
|