oddsilk commited on
Commit ยท
c952080
1
Parent(s): 55ca299
Update automatic mapping logic in `auto_mapper.py`.
Browse files- auto_mapper.py +24 -8
auto_mapper.py
CHANGED
|
@@ -104,19 +104,33 @@ def separate_stems(audio_path: str, output_dir: str) -> str:
|
|
| 104 |
try:
|
| 105 |
import subprocess
|
| 106 |
# htdemucs ๋ชจ๋ธ ์ฌ์ฉ (๊ธฐ๋ณธ 4์คํฌ)
|
|
|
|
| 107 |
cmd = [
|
| 108 |
sys.executable, "-m", "demucs.separate",
|
| 109 |
"-n", "htdemucs",
|
| 110 |
-
|
| 111 |
"-o", stem_parent_dir
|
| 112 |
]
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# Demucs์ ๊ธฐ๋ณธ ์ถ๋ ฅ ๊ฒฝ๋ก ๊ตฌ์กฐ: {output_dir}/htdemucs/{filename}/{stem}.wav
|
| 117 |
# ์ด๋ฅผ ์ฐ๋ฆฌ๊ฐ ์ํ๋ {output_dir}/{filename}/{stem}.wav ๋ก ์ด๋/์ ๋ฆฌ
|
| 118 |
demucs_out_path = os.path.join(stem_parent_dir, "htdemucs", basename)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
if not os.path.exists(stem_dir):
|
| 121 |
os.makedirs(stem_dir, exist_ok=True)
|
| 122 |
|
|
@@ -125,16 +139,18 @@ def separate_stems(audio_path: str, output_dir: str) -> str:
|
|
| 125 |
dst = os.path.join(stem_dir, f)
|
| 126 |
if os.path.exists(src):
|
| 127 |
shutil.move(src, dst)
|
|
|
|
|
|
|
| 128 |
|
| 129 |
# ์ฌ์ฉ ํ ๋จ์ htdemucs ๋น ํด๋ ์ญ์
|
| 130 |
-
|
| 131 |
-
|
|
|
|
| 132 |
|
| 133 |
except Exception as e:
|
| 134 |
print(f" โ Demucs ๋ถ๋ฆฌ ์คํจ: {str(e)}")
|
| 135 |
-
#
|
| 136 |
-
|
| 137 |
-
os.makedirs(stem_dir, exist_ok=True)
|
| 138 |
|
| 139 |
print(f" โ ์คํ
๋ถ๋ฆฌ ๋ฐ ์บ์ฑ ์๋ฃ โ {stem_dir}")
|
| 140 |
return stem_dir
|
|
|
|
| 104 |
try:
|
| 105 |
import subprocess
|
| 106 |
# htdemucs ๋ชจ๋ธ ์ฌ์ฉ (๊ธฐ๋ณธ 4์คํฌ)
|
| 107 |
+
# ์ค์: --path ์ธ์๋ ์กด์ฌํ์ง ์์ผ๋ฏ๋ก ์ ๊ฑฐํ๊ณ positional argument๋ก ์ ๋ฌ
|
| 108 |
cmd = [
|
| 109 |
sys.executable, "-m", "demucs.separate",
|
| 110 |
"-n", "htdemucs",
|
| 111 |
+
audio_path,
|
| 112 |
"-o", stem_parent_dir
|
| 113 |
]
|
| 114 |
+
|
| 115 |
+
print(f" โ ์คํ ๋ช
๋ น: {' '.join(cmd)}")
|
| 116 |
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
| 117 |
+
|
| 118 |
+
if result.returncode != 0:
|
| 119 |
+
raise RuntimeError(f"Demucs ์คํ ์คํจ (Exit Code {result.returncode}):\n{result.stderr}")
|
| 120 |
|
| 121 |
# Demucs์ ๊ธฐ๋ณธ ์ถ๋ ฅ ๊ฒฝ๋ก ๊ตฌ์กฐ: {output_dir}/htdemucs/{filename}/{stem}.wav
|
| 122 |
# ์ด๋ฅผ ์ฐ๋ฆฌ๊ฐ ์ํ๋ {output_dir}/{filename}/{stem}.wav ๋ก ์ด๋/์ ๋ฆฌ
|
| 123 |
demucs_out_path = os.path.join(stem_parent_dir, "htdemucs", basename)
|
| 124 |
|
| 125 |
+
if not os.path.exists(demucs_out_path):
|
| 126 |
+
# ํ์ผ๋ช
์ด ๋ค๋ฅผ ์ ์์ผ๋ฏ๋ก htdemucs ๋ด๋ถ ํด๋ ํ์ธ
|
| 127 |
+
htdemucs_dir = os.path.join(stem_parent_dir, "htdemucs")
|
| 128 |
+
if os.path.exists(htdemucs_dir):
|
| 129 |
+
subdirs = [d for d in os.listdir(htdemucs_dir) if os.path.isdir(os.path.join(htdemucs_dir, d))]
|
| 130 |
+
if subdirs:
|
| 131 |
+
demucs_out_path = os.path.join(htdemucs_dir, subdirs[0])
|
| 132 |
+
print(f" โ basename ๋ถ์ผ์น ๊ฐ์ง. ํด๋๋ช
์ {subdirs[0]}๋ก ๋์ฒดํฉ๋๋ค.")
|
| 133 |
+
|
| 134 |
if not os.path.exists(stem_dir):
|
| 135 |
os.makedirs(stem_dir, exist_ok=True)
|
| 136 |
|
|
|
|
| 139 |
dst = os.path.join(stem_dir, f)
|
| 140 |
if os.path.exists(src):
|
| 141 |
shutil.move(src, dst)
|
| 142 |
+
else:
|
| 143 |
+
print(f" โ ๊ฒฝ๊ณ : ์์๋ ์คํ
ํ์ผ์ ์ฐพ์ ์ ์์: {src}")
|
| 144 |
|
| 145 |
# ์ฌ์ฉ ํ ๋จ์ htdemucs ๋น ํด๋ ์ญ์
|
| 146 |
+
htdemucs_base = os.path.join(stem_parent_dir, "htdemucs")
|
| 147 |
+
if os.path.exists(htdemucs_base):
|
| 148 |
+
shutil.rmtree(htdemucs_base)
|
| 149 |
|
| 150 |
except Exception as e:
|
| 151 |
print(f" โ Demucs ๋ถ๋ฆฌ ์คํจ: {str(e)}")
|
| 152 |
+
# ์๋ฌ๋ฅผ ๋ค์ ๋์ ธ์ ์์(Gradio UI)์์ ์ธ์งํ ์ ์๊ฒ ํจ
|
| 153 |
+
raise RuntimeError(f"Demucs ๋ถ๋ฆฌ ๊ณผ์ ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}")
|
|
|
|
| 154 |
|
| 155 |
print(f" โ ์คํ
๋ถ๋ฆฌ ๋ฐ ์บ์ฑ ์๋ฃ โ {stem_dir}")
|
| 156 |
return stem_dir
|