Pepguy commited on
Commit
05a9187
·
verified ·
1 Parent(s): 936d8f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -15,7 +15,7 @@ os.makedirs(BASE_DIR, exist_ok=True)
15
 
16
  def add_status(log_list, message):
17
  log_list.append(message)
18
- print(message)
19
 
20
  @app.post("/process")
21
  def process_audio(payload: dict):
@@ -70,7 +70,7 @@ def process_audio(payload: dict):
70
  add_status(status_log, f"Error downloading file: {e}")
71
  return JSONResponse(status_code=400, content={"status": status_log})
72
 
73
- # Remove query parameters for a clean filename
74
  parsed = urlparse(audio_url)
75
  path = parsed.path
76
  ext = os.path.splitext(path)[1] or ".mp3"
@@ -89,7 +89,7 @@ def process_audio(payload: dict):
89
  add_status(status_log, "Error: Input file does not exist after download.")
90
  return JSONResponse(status_code=500, content={"status": status_log})
91
 
92
- # Run Spleeter using updated syntax:
93
  # spleeter separate -p spleeter:2stems -o <task_dir> <input_filepath>
94
  spleeter_cmd = [
95
  "spleeter", "separate",
@@ -106,22 +106,9 @@ def process_audio(payload: dict):
106
  add_status(status_log, "Spleeter processing failed: " + e.stderr)
107
  return JSONResponse(status_code=500, content={"status": status_log})
108
 
109
- # Determine expected output folder.
110
- # By default, Spleeter creates a folder with the base name of the input file.
111
  base_name = os.path.splitext(input_filename)[0]
112
  output_folder = os.path.join(task_dir, base_name)
113
-
114
- # If the expected folder doesn't exist, attempt to auto-detect the correct folder.
115
- if not os.path.exists(output_folder):
116
- add_status(status_log, f"Expected output folder '{output_folder}' not found. Searching for subdirectories.")
117
- subdirs = [d for d in os.listdir(task_dir) if os.path.isdir(os.path.join(task_dir, d))]
118
- if len(subdirs) == 1:
119
- output_folder = os.path.join(task_dir, subdirs[0])
120
- add_status(status_log, f"Detected output folder as: {output_folder}")
121
- else:
122
- add_status(status_log, "Error: Unable to detect unique output folder.")
123
- return JSONResponse(status_code=500, content={"status": status_log})
124
-
125
  vocals_file = os.path.join(output_folder, "vocals.wav")
126
  accompaniment_file = os.path.join(output_folder, "accompaniment.wav")
127
 
@@ -131,7 +118,7 @@ def process_audio(payload: dict):
131
 
132
  add_status(status_log, "Spleeter processing completed successfully.")
133
 
134
- # Read output files and encode in base64
135
  try:
136
  with open(vocals_file, "rb") as f:
137
  vocals_data = f.read()
 
15
 
16
  def add_status(log_list, message):
17
  log_list.append(message)
18
+ print(message) # Also log to console
19
 
20
  @app.post("/process")
21
  def process_audio(payload: dict):
 
70
  add_status(status_log, f"Error downloading file: {e}")
71
  return JSONResponse(status_code=400, content={"status": status_log})
72
 
73
+ # Clean filename: remove query parameters using urlparse
74
  parsed = urlparse(audio_url)
75
  path = parsed.path
76
  ext = os.path.splitext(path)[1] or ".mp3"
 
89
  add_status(status_log, "Error: Input file does not exist after download.")
90
  return JSONResponse(status_code=500, content={"status": status_log})
91
 
92
+ # Run Spleeter using the updated syntax:
93
  # spleeter separate -p spleeter:2stems -o <task_dir> <input_filepath>
94
  spleeter_cmd = [
95
  "spleeter", "separate",
 
106
  add_status(status_log, "Spleeter processing failed: " + e.stderr)
107
  return JSONResponse(status_code=500, content={"status": status_log})
108
 
109
+ # Spleeter creates an output folder with the base name of the input file.
 
110
  base_name = os.path.splitext(input_filename)[0]
111
  output_folder = os.path.join(task_dir, base_name)
 
 
 
 
 
 
 
 
 
 
 
 
112
  vocals_file = os.path.join(output_folder, "vocals.wav")
113
  accompaniment_file = os.path.join(output_folder, "accompaniment.wav")
114
 
 
118
 
119
  add_status(status_log, "Spleeter processing completed successfully.")
120
 
121
+ # Read output files and encode them in base64
122
  try:
123
  with open(vocals_file, "rb") as f:
124
  vocals_data = f.read()