owiedotch commited on
Commit
4a925ac
1 Parent(s): 5c906d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -20,13 +20,15 @@ def inference(audio_file: str, model_name: str, vocals: bool, drums: bool, bass:
20
  yield None, stream_log("Error: No audio file provided")
21
  raise gr.Error("Please upload an audio file")
22
 
23
- output_dir = os.path.join("separated", model_name, os.path.splitext(os.path.basename(audio_file))[0])
 
 
24
  os.makedirs(output_dir, exist_ok=True)
25
 
26
- # Construct the Demucs command
27
  cmd = [
28
  "python", "-m", "demucs",
29
- "--out", os.path.dirname(output_dir), # Use the parent directory of output_dir
30
  "-n", model_name,
31
  audio_file
32
  ]
@@ -56,8 +58,8 @@ def inference(audio_file: str, model_name: str, vocals: bool, drums: bool, bass:
56
 
57
  yield None, stream_log("Separation completed. Processing stems...")
58
 
59
- # Change the stem search directory
60
- stem_search_dir = os.path.join(output_dir, model_name)
61
  yield None, stream_log(f"Searching for stems in: {stem_search_dir}")
62
 
63
  stems: Dict[str, str] = {}
@@ -71,8 +73,8 @@ def inference(audio_file: str, model_name: str, vocals: bool, drums: bool, bass:
71
  yield None, stream_log(f"Warning: {stem} stem not found")
72
 
73
  if not stems:
74
- yield None, stream_log("Error: No stems found. Checking parent directory...")
75
- stem_search_dir = output_dir
76
  for stem in ["vocals", "drums", "bass", "other"]:
77
  stem_path = os.path.join(stem_search_dir, f"{stem}.wav")
78
  yield None, stream_log(f"Checking for {stem} stem at: {stem_path}")
 
20
  yield None, stream_log("Error: No audio file provided")
21
  raise gr.Error("Please upload an audio file")
22
 
23
+ # Use absolute paths
24
+ base_output_dir = os.path.abspath("separated")
25
+ output_dir = os.path.join(base_output_dir, model_name, os.path.splitext(os.path.basename(audio_file))[0])
26
  os.makedirs(output_dir, exist_ok=True)
27
 
28
+ # Construct the Demucs command with full paths
29
  cmd = [
30
  "python", "-m", "demucs",
31
+ "--out", base_output_dir,
32
  "-n", model_name,
33
  audio_file
34
  ]
 
58
 
59
  yield None, stream_log("Separation completed. Processing stems...")
60
 
61
+ # Change the stem search directory using full path
62
+ stem_search_dir = os.path.join(base_output_dir, model_name, os.path.splitext(os.path.basename(audio_file))[0])
63
  yield None, stream_log(f"Searching for stems in: {stem_search_dir}")
64
 
65
  stems: Dict[str, str] = {}
 
73
  yield None, stream_log(f"Warning: {stem} stem not found")
74
 
75
  if not stems:
76
+ yield None, stream_log("Error: No stems found. Checking alternative directory...")
77
+ stem_search_dir = os.path.join(base_output_dir, model_name)
78
  for stem in ["vocals", "drums", "bass", "other"]:
79
  stem_path = os.path.join(stem_search_dir, f"{stem}.wav")
80
  yield None, stream_log(f"Checking for {stem} stem at: {stem_path}")