Spaces:
Building
on
L40S
Building
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -202,64 +202,42 @@ def install_flash_attn():
|
|
202 |
return False
|
203 |
|
204 |
|
205 |
-
|
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 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
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 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|