Spaces:
Runtime error
Runtime error
Commit ·
22826d0
1
Parent(s): 7ea548f
Improve error handling and fix TorchAudio compatibility issues
Browse files- Dockerfile +2 -0
- requirements.txt +3 -1
- server.py +13 -2
Dockerfile
CHANGED
|
@@ -40,6 +40,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 40 |
|
| 41 |
# Set environment variables for audio backends
|
| 42 |
ENV TORCHAUDIO_BACKEND=soundfile
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Copy the Flask server
|
| 45 |
COPY server.py .
|
|
|
|
| 40 |
|
| 41 |
# Set environment variables for audio backends
|
| 42 |
ENV TORCHAUDIO_BACKEND=soundfile
|
| 43 |
+
ENV PYTORCH_ENABLE_MPS_FALLBACK=1
|
| 44 |
+
ENV OMP_NUM_THREADS=1
|
| 45 |
|
| 46 |
# Copy the Flask server
|
| 47 |
COPY server.py .
|
requirements.txt
CHANGED
|
@@ -3,4 +3,6 @@ Flask-CORS==4.0.0
|
|
| 3 |
demucs==4.0.1
|
| 4 |
Werkzeug==2.3.6
|
| 5 |
gunicorn==21.2.0
|
| 6 |
-
soundfile==0.12.1
|
|
|
|
|
|
|
|
|
| 3 |
demucs==4.0.1
|
| 4 |
Werkzeug==2.3.6
|
| 5 |
gunicorn==21.2.0
|
| 6 |
+
soundfile==0.12.1
|
| 7 |
+
torch==2.0.1
|
| 8 |
+
torchaudio==2.0.2
|
server.py
CHANGED
|
@@ -79,12 +79,23 @@ def separate_audio():
|
|
| 79 |
|
| 80 |
# Run demucs command with output to temp directory
|
| 81 |
output_dir = os.path.join(temp_dir, 'separated')
|
| 82 |
-
cmd = ['demucs', '--out', output_dir, file_path]
|
| 83 |
|
| 84 |
result = subprocess.run(cmd, capture_output=True, text=True, env=env)
|
| 85 |
|
| 86 |
if result.returncode != 0:
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# Find the output directory (Demucs creates subdirectories)
|
| 90 |
base_name = os.path.splitext(filename)[0]
|
|
|
|
| 79 |
|
| 80 |
# Run demucs command with output to temp directory
|
| 81 |
output_dir = os.path.join(temp_dir, 'separated')
|
| 82 |
+
cmd = ['demucs', '--device', 'cpu', '--out', output_dir, file_path]
|
| 83 |
|
| 84 |
result = subprocess.run(cmd, capture_output=True, text=True, env=env)
|
| 85 |
|
| 86 |
if result.returncode != 0:
|
| 87 |
+
# Combine both stdout and stderr for complete error info
|
| 88 |
+
error_output = ""
|
| 89 |
+
if result.stdout:
|
| 90 |
+
error_output += f"STDOUT: {result.stdout}\n"
|
| 91 |
+
if result.stderr:
|
| 92 |
+
error_output += f"STDERR: {result.stderr}"
|
| 93 |
+
|
| 94 |
+
# Also log the full error for debugging
|
| 95 |
+
print(f"Demucs failed with return code {result.returncode}")
|
| 96 |
+
print(f"Full error output: {error_output}")
|
| 97 |
+
|
| 98 |
+
return jsonify({'error': f'Demucs processing failed with return code {result.returncode}: {error_output}'}), 500
|
| 99 |
|
| 100 |
# Find the output directory (Demucs creates subdirectories)
|
| 101 |
base_name = os.path.splitext(filename)[0]
|