ginipick commited on
Commit
98e03fd
ยท
verified ยท
1 Parent(s): f08699a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -23
app.py CHANGED
@@ -204,21 +204,37 @@ def install_flash_attn():
204
 
205
  def check_model_files():
206
  base_dir = os.getcwd()
207
- required_files = [
208
- os.path.join(base_dir, "xcodec_mini_infer", "config.json"),
209
- os.path.join(base_dir, "xcodec_mini_infer", "vocal_decoder.pth"),
210
- os.path.join(base_dir, "xcodec_mini_infer", "inst_decoder.pth")
211
- ]
 
 
 
212
 
213
- missing_files = [f for f in required_files if not os.path.exists(f)]
214
- if missing_files:
215
- logging.warning(f"Missing required files: {missing_files}")
 
 
 
 
 
 
 
216
  download_missing_files()
217
 
218
- # ํŒŒ์ผ ์กด์žฌ ํ™•์ธ
219
- for file_path in required_files:
220
- if not os.path.exists(file_path):
221
- raise FileNotFoundError(f"Required file still missing after download: {file_path}")
 
 
 
 
 
 
222
 
223
  def download_missing_files():
224
  try:
@@ -229,10 +245,22 @@ def download_missing_files():
229
  repo_id="m-a-p/xcodec_mini_infer",
230
  local_dir="./xcodec_mini_infer",
231
  resume_download=True,
232
- force_download=True
 
233
  )
234
  logging.info(f"Downloaded xcodec_mini_infer to: {xcodec_path}")
235
 
 
 
 
 
 
 
 
 
 
 
 
236
  # YuE ๋ชจ๋ธ๋“ค ๋‹ค์šด๋กœ๋“œ
237
  models = [
238
  "m-a-p/YuE-s1-7B-anneal-jp-kr-cot",
@@ -247,7 +275,8 @@ def download_missing_files():
247
  repo_id=model,
248
  local_dir=f"./models/{model_name}",
249
  resume_download=True,
250
- force_download=True
 
251
  )
252
  logging.info(f"Downloaded {model_name} to: {model_path}")
253
 
@@ -280,20 +309,18 @@ def initialize_system():
280
  # ๋ชจ๋ธ ํŒŒ์ผ ์ฒดํฌ ๋ฐ ๋‹ค์šด๋กœ๋“œ
281
  check_model_files()
282
 
283
- # GPU ์„ค์ • ํ™•์ธ
284
- if torch.cuda.is_available():
285
- torch.cuda.empty_cache()
286
- device = torch.device("cuda")
287
- logging.info(f"Using GPU device: {torch.cuda.get_device_name(0)}")
288
- else:
289
- device = torch.device("cpu")
290
- logging.warning("GPU not available, using CPU")
291
 
292
  logging.info("System initialization completed successfully")
293
 
294
  except Exception as e:
295
  logging.error(f"Initialization error: {e}")
296
- os.chdir(original_dir) # ์˜ค๋ฅ˜ ๋ฐœ์ƒ ์‹œ ์›๋ž˜ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ๋ณต๊ท€
297
  raise
298
 
299
  @lru_cache(maxsize=100)
 
204
 
205
  def check_model_files():
206
  base_dir = os.getcwd()
207
+ xcodec_dir = os.path.join(base_dir, "xcodec_mini_infer")
208
+
209
+ # ํ•„์š”ํ•œ ํŒŒ์ผ ๋ชฉ๋ก
210
+ required_files = {
211
+ "config.json": "config.json",
212
+ "vocal_decoder.pth": "vocal_decoder.pth",
213
+ "inst_decoder.pth": "inst_decoder.pth"
214
+ }
215
 
216
+ # ํŒŒ์ผ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
217
+ missing = False
218
+ for file_name in required_files.keys():
219
+ file_path = os.path.join(xcodec_dir, file_name)
220
+ if not os.path.exists(file_path):
221
+ missing = True
222
+ logging.warning(f"Missing file: {file_path}")
223
+
224
+ if missing:
225
+ logging.info("Downloading missing files...")
226
  download_missing_files()
227
 
228
+ # ๋‹ค์šด๋กœ๋“œ ํ›„ ํŒŒ์ผ ์žฌํ™•์ธ
229
+ for file_name, src_name in required_files.items():
230
+ src_path = os.path.join(xcodec_dir, src_name)
231
+ dst_path = os.path.join(xcodec_dir, file_name)
232
+
233
+ if not os.path.exists(dst_path) and os.path.exists(src_path):
234
+ shutil.copy2(src_path, dst_path)
235
+
236
+ if not os.path.exists(dst_path):
237
+ raise FileNotFoundError(f"Failed to download or locate required file: {file_name}")
238
 
239
  def download_missing_files():
240
  try:
 
245
  repo_id="m-a-p/xcodec_mini_infer",
246
  local_dir="./xcodec_mini_infer",
247
  resume_download=True,
248
+ force_download=True,
249
+ local_files_only=False
250
  )
251
  logging.info(f"Downloaded xcodec_mini_infer to: {xcodec_path}")
252
 
253
+ # ํŒŒ์ผ ์กด์žฌ ํ™•์ธ ๋ฐ ๋ณต์‚ฌ
254
+ xcodec_dir = "./xcodec_mini_infer"
255
+ for root, _, files in os.walk(xcodec_dir):
256
+ for file in files:
257
+ if file in ["config.json", "vocal_decoder.pth", "inst_decoder.pth"]:
258
+ src_path = os.path.join(root, file)
259
+ dst_path = os.path.join(xcodec_dir, file)
260
+ if src_path != dst_path:
261
+ shutil.copy2(src_path, dst_path)
262
+ logging.info(f"Copied {file} to {dst_path}")
263
+
264
  # YuE ๋ชจ๋ธ๋“ค ๋‹ค์šด๋กœ๋“œ
265
  models = [
266
  "m-a-p/YuE-s1-7B-anneal-jp-kr-cot",
 
275
  repo_id=model,
276
  local_dir=f"./models/{model_name}",
277
  resume_download=True,
278
+ force_download=True,
279
+ local_files_only=False
280
  )
281
  logging.info(f"Downloaded {model_name} to: {model_path}")
282
 
 
309
  # ๋ชจ๋ธ ํŒŒ์ผ ์ฒดํฌ ๋ฐ ๋‹ค์šด๋กœ๋“œ
310
  check_model_files()
311
 
312
+ # ํŒŒ์ผ ๊ถŒํ•œ ํ™•์ธ
313
+ xcodec_dir = "./xcodec_mini_infer"
314
+ for file_name in ["config.json", "vocal_decoder.pth", "inst_decoder.pth"]:
315
+ file_path = os.path.join(xcodec_dir, file_name)
316
+ if os.path.exists(file_path):
317
+ os.chmod(file_path, 0o644) # ์ฝ๊ธฐ ๊ถŒํ•œ ํ™•์ธ
 
 
318
 
319
  logging.info("System initialization completed successfully")
320
 
321
  except Exception as e:
322
  logging.error(f"Initialization error: {e}")
323
+ os.chdir(original_dir)
324
  raise
325
 
326
  @lru_cache(maxsize=100)