Rezuwan commited on
Commit
2910796
·
verified ·
1 Parent(s): c7cb083

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -39,11 +39,19 @@ def separate_audio(audio_file):
39
  if audio_file is None:
40
  return None, None
41
 
42
- output_paths = separator.separate(audio_file)
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- # audio-separator returns a list of output file paths (order/count
45
- # depends on the model). We sort them so the "instrumental"-labeled
46
- # file and "vocals"-labeled file land in predictable slots.
47
  vocals_path = next((p for p in output_paths if "vocal" in p.lower()), None)
48
  instrumental_path = next(
49
  (p for p in output_paths if p != vocals_path), None
@@ -70,4 +78,6 @@ ui = gr.Interface(
70
  )
71
 
72
  if __name__ == "__main__":
73
- ui.launch()
 
 
 
39
  if audio_file is None:
40
  return None, None
41
 
42
+ raw_outputs = separator.separate(audio_file)
43
+
44
+ # separator.separate() returns bare filenames, not full paths — they
45
+ # actually get written under separator.output_dir. Without joining them
46
+ # back to that directory, Gradio resolves the relative filename against
47
+ # the app's cwd instead of where the files really are, which is what
48
+ # caused the empty players / 403 on download.
49
+ output_paths = [
50
+ p if os.path.isabs(p) else os.path.join(separator.output_dir, p)
51
+ for p in raw_outputs
52
+ ]
53
+ output_paths = [os.path.abspath(p) for p in output_paths]
54
 
 
 
 
55
  vocals_path = next((p for p in output_paths if "vocal" in p.lower()), None)
56
  instrumental_path = next(
57
  (p for p in output_paths if p != vocals_path), None
 
78
  )
79
 
80
  if __name__ == "__main__":
81
+ # Explicitly whitelist the output directory for Gradio's file server —
82
+ # avoids 403s when serving files from a directory outside the app's cwd.
83
+ ui.launch(allowed_paths=[separator.output_dir])