Update app.py
Browse files
app.py
CHANGED
@@ -199,78 +199,36 @@ def install_flash_attn():
|
|
199 |
logging.warning(f"Failed to install flash-attn: {e}")
|
200 |
return False
|
201 |
|
|
|
202 |
def initialize_system():
|
203 |
optimize_gpu_settings()
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
base_dir = os.path.abspath("./inference")
|
208 |
-
os.makedirs(base_dir, exist_ok=True)
|
209 |
-
os.makedirs(os.path.join(base_dir, "models"), exist_ok=True)
|
210 |
-
|
211 |
-
# ์์
๋๋ ํ ๋ฆฌ ๋ณ๊ฒฝ
|
212 |
-
os.chdir(base_dir)
|
213 |
-
logging.info(f"Working directory changed to: {os.getcwd()}")
|
214 |
|
215 |
-
|
216 |
|
217 |
-
|
218 |
-
xcodec_dir = "xcodec_mini_infer"
|
219 |
-
os.makedirs(xcodec_dir, exist_ok=True)
|
220 |
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
# infer.py ํ์ผ ๋ค์ด๋ก๋
|
229 |
-
infer_script = hf_hub_download(
|
230 |
repo_id="m-a-p/xcodec_mini_infer",
|
231 |
-
|
232 |
-
|
233 |
-
)
|
234 |
-
|
235 |
-
# infer.py ํ์ผ์ ํ์ฌ ๋๋ ํ ๋ฆฌ๋ก ๋ณต์ฌ
|
236 |
-
shutil.copy2(infer_script, "infer.py")
|
237 |
-
|
238 |
-
# YuE ๋ชจ๋ธ๋ค ๋ค์ด๋ก๋
|
239 |
-
models = [
|
240 |
-
"m-a-p/YuE-s1-7B-anneal-jp-kr-cot",
|
241 |
-
"m-a-p/YuE-s1-7B-anneal-en-cot",
|
242 |
-
"m-a-p/YuE-s1-7B-anneal-zh-cot",
|
243 |
-
"m-a-p/YuE-s2-1B-general"
|
244 |
-
]
|
245 |
-
|
246 |
-
for model in models:
|
247 |
-
model_name = model.split('/')[-1]
|
248 |
-
model_path = os.path.join("models", model_name)
|
249 |
-
snapshot_download(
|
250 |
-
repo_id=model,
|
251 |
-
local_dir=model_path,
|
252 |
-
force_download=True
|
253 |
-
)
|
254 |
-
|
255 |
-
# ํ์ํ ํ์ผ๋ค ์กด์ฌ ํ์ธ
|
256 |
-
required_files = [
|
257 |
-
"infer.py",
|
258 |
-
os.path.join(xcodec_dir, "config.json"),
|
259 |
-
os.path.join(xcodec_dir, "vocal_decoder.pth"),
|
260 |
-
os.path.join(xcodec_dir, "inst_decoder.pth")
|
261 |
-
]
|
262 |
-
|
263 |
-
for file_path in required_files:
|
264 |
-
if not os.path.exists(file_path):
|
265 |
-
raise FileNotFoundError(f"Required file not found: {file_path}")
|
266 |
-
else:
|
267 |
-
file_size = os.path.getsize(file_path)
|
268 |
-
logging.info(f"Verified {file_path}: {file_size} bytes")
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
|
|
|
|
|
|
|
|
274 |
raise
|
275 |
|
276 |
@lru_cache(maxsize=100)
|
|
|
199 |
logging.warning(f"Failed to install flash-attn: {e}")
|
200 |
return False
|
201 |
|
202 |
+
|
203 |
def initialize_system():
|
204 |
optimize_gpu_settings()
|
205 |
|
206 |
+
with ThreadPoolExecutor(max_workers=4) as executor:
|
207 |
+
futures = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
futures.append(executor.submit(install_flash_attn))
|
210 |
|
211 |
+
from huggingface_hub import snapshot_download
|
|
|
|
|
212 |
|
213 |
+
folder_path = './inference/xcodec_mini_infer'
|
214 |
+
os.makedirs(folder_path, exist_ok=True)
|
215 |
+
logging.info(f"Created folder at: {folder_path}")
|
216 |
+
|
217 |
+
futures.append(executor.submit(
|
218 |
+
snapshot_download,
|
|
|
|
|
|
|
219 |
repo_id="m-a-p/xcodec_mini_infer",
|
220 |
+
local_dir="./inference/xcodec_mini_infer",
|
221 |
+
resume_download=True
|
222 |
+
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
+
for future in futures:
|
225 |
+
future.result()
|
226 |
+
|
227 |
+
try:
|
228 |
+
os.chdir("./inference")
|
229 |
+
logging.info(f"Working directory changed to: {os.getcwd()}")
|
230 |
+
except FileNotFoundError as e:
|
231 |
+
logging.error(f"Directory error: {e}")
|
232 |
raise
|
233 |
|
234 |
@lru_cache(maxsize=100)
|