oddsilk commited on
Commit
c952080
ยท
1 Parent(s): 55ca299

Update automatic mapping logic in `auto_mapper.py`.

Browse files
Files changed (1) hide show
  1. 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
- "--path", audio_path,
111
  "-o", stem_parent_dir
112
  ]
113
- # output_dir ์ธ์ž๊ฐ€ ์žˆ์œผ๋ฉด ๊ทธ๊ณณ์— ์ž„์‹œ ์ €์žฅ ํ›„ ์ •๋ฆฌ
114
- subprocess.run(cmd, check=True)
 
 
 
 
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
- if os.path.exists(demucs_out_path):
131
- shutil.rmtree(os.path.join(stem_parent_dir, "htdemucs"))
 
132
 
133
  except Exception as e:
134
  print(f" โŒ Demucs ๋ถ„๋ฆฌ ์‹คํŒจ: {str(e)}")
135
- # ์‹คํŒจ ์‹œ์—๋„ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋ผ๋„ ๋งž์ถ”๊ธฐ ์œ„ํ•ด ์‹œ๋„
136
- if not os.path.exists(stem_dir):
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