Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -204,21 +204,37 @@ def install_flash_attn(): 
     | 
|
| 204 | 
         | 
| 205 | 
         
             
            def check_model_files():
         
     | 
| 206 | 
         
             
                base_dir = os.getcwd()
         
     | 
| 207 | 
         
            -
                 
     | 
| 208 | 
         
            -
             
     | 
| 209 | 
         
            -
             
     | 
| 210 | 
         
            -
             
     | 
| 211 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 212 | 
         | 
| 213 | 
         
            -
                 
     | 
| 214 | 
         
            -
                 
     | 
| 215 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 216 | 
         
             
                    download_missing_files()
         
     | 
| 217 | 
         | 
| 218 | 
         
            -
             
     | 
| 219 | 
         
            -
             
     | 
| 220 | 
         
            -
             
     | 
| 221 | 
         
            -
                         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 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 | 
         
            -
                    #  
     | 
| 284 | 
         
            -
                     
     | 
| 285 | 
         
            -
             
     | 
| 286 | 
         
            -
                         
     | 
| 287 | 
         
            -
                         
     | 
| 288 | 
         
            -
             
     | 
| 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)
         
     |