Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,9 +22,18 @@ def inference(audio_file: str, model_name: str, vocals: bool, drums: bool, bass:
|
|
22 |
yield None, stream_log("Starting separation process...")
|
23 |
yield None, stream_log(f"Loading audio file: {audio_file}")
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
# Load the audio file with the correct samplerate and audio channels
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
# Check the number of channels and adjust if necessary
|
29 |
if wav.dim() == 1:
|
30 |
wav = wav.unsqueeze(0) # Add channel dimension if mono
|
@@ -40,8 +49,12 @@ def inference(audio_file: str, model_name: str, vocals: bool, drums: bool, bass:
|
|
40 |
yield None, stream_log("Audio loaded successfully. Applying model...")
|
41 |
|
42 |
# Use apply_model as a standalone function
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
# Process the sources
|
46 |
sources = [source * ref.view(1, -1) + ref.view(1, -1) for source in sources]
|
47 |
|
|
|
22 |
yield None, stream_log("Starting separation process...")
|
23 |
yield None, stream_log(f"Loading audio file: {audio_file}")
|
24 |
|
25 |
+
# Check if audio_file is None
|
26 |
+
if audio_file is None:
|
27 |
+
yield None, stream_log("Error: No audio file provided")
|
28 |
+
raise gr.Error("Please upload an audio file")
|
29 |
+
|
30 |
# Load the audio file with the correct samplerate and audio channels
|
31 |
+
try:
|
32 |
+
wav, sr = load_track(audio_file, samplerate=separator.samplerate, audio_channels=2)
|
33 |
+
except Exception as e:
|
34 |
+
yield None, stream_log(f"Error loading audio file: {str(e)}")
|
35 |
+
raise gr.Error(f"Failed to load audio file: {str(e)}")
|
36 |
+
|
37 |
# Check the number of channels and adjust if necessary
|
38 |
if wav.dim() == 1:
|
39 |
wav = wav.unsqueeze(0) # Add channel dimension if mono
|
|
|
49 |
yield None, stream_log("Audio loaded successfully. Applying model...")
|
50 |
|
51 |
# Use apply_model as a standalone function
|
52 |
+
try:
|
53 |
+
sources = apply_model(separator, wav.to(device), device=device)
|
54 |
+
except Exception as e:
|
55 |
+
yield None, stream_log(f"Error applying model: {str(e)}")
|
56 |
+
raise gr.Error(f"Failed to apply model: {str(e)}")
|
57 |
+
|
58 |
# Process the sources
|
59 |
sources = [source * ref.view(1, -1) + ref.view(1, -1) for source in sources]
|
60 |
|