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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -52
app.py CHANGED
@@ -202,64 +202,42 @@ def install_flash_attn():
202
  return False
203
 
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:
241
- from huggingface_hub import snapshot_download
242
 
243
- # xcodec_mini_infer ๋ชจ๋ธ ๋‹ค์šด๋กœ๋“œ
244
- xcodec_path = snapshot_download(
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 = [
@@ -281,10 +259,54 @@ def download_missing_files():
281
  logging.info(f"Downloaded {model_name} to: {model_path}")
282
 
283
  logging.info("All required models downloaded successfully")
 
 
 
 
 
 
 
 
 
 
284
  except Exception as e:
285
  logging.error(f"Error downloading models: {e}")
286
  raise
287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  def initialize_system():
289
  optimize_gpu_settings()
290
 
 
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 = [
 
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
275
 
276
+ def check_model_files():
277
+ base_dir = os.getcwd()
278
+ xcodec_dir = os.path.join(base_dir, "xcodec_mini_infer")
279
+
280
+ # ํ•„์š”ํ•œ ํŒŒ์ผ ๋ชฉ๋ก
281
+ required_files = {
282
+ "config.json": "config.json",
283
+ "vocal_decoder.pth": "vocal_decoder.pth",
284
+ "inst_decoder.pth": "inst_decoder.pth"
285
+ }
286
+
287
+ # ํŒŒ์ผ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
288
+ missing = False
289
+ for file_name in required_files.keys():
290
+ file_path = os.path.join(xcodec_dir, file_name)
291
+ if not os.path.exists(file_path):
292
+ missing = True
293
+ logging.warning(f"Missing file: {file_path}")
294
+
295
+ if missing:
296
+ logging.info("Downloading missing files...")
297
+ download_missing_files()
298
+
299
+ # ๋‹ค์šด๋กœ๋“œ ํ›„ ํŒŒ์ผ ์žฌํ™•์ธ
300
+ for file_name in required_files.keys():
301
+ file_path = os.path.join(xcodec_dir, file_name)
302
+ if not os.path.exists(file_path):
303
+ raise FileNotFoundError(f"Failed to download or locate required file: {file_name}")
304
+ else:
305
+ file_size = os.path.getsize(file_path)
306
+ if file_size == 0:
307
+ raise FileNotFoundError(f"Downloaded file is empty: {file_name}")
308
+ logging.info(f"Verified {file_name}: {file_size} bytes")
309
+
310
  def initialize_system():
311
  optimize_gpu_settings()
312