Spaces:
Sleeping
Sleeping
Commit
·
3113ec2
1
Parent(s):
0d10337
handling return type
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from demucs import pretrained
|
|
| 5 |
from demucs.apply import apply_model
|
| 6 |
from pyharp import *
|
| 7 |
from audiotools import AudioSignal
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# Available Demucs models
|
|
@@ -65,15 +66,41 @@ def separate_stem(audio_file_path: str, model_name: str, stem_choice: str):
|
|
| 65 |
stem_signal = AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
|
| 66 |
return stem_signal
|
| 67 |
|
| 68 |
-
def process_fn_stem(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
"""
|
| 70 |
-
PyHARP process function:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
"""
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
# Define the model card
|
|
@@ -107,4 +134,4 @@ with gr.Blocks() as demo:
|
|
| 107 |
)
|
| 108 |
|
| 109 |
demo.queue()
|
| 110 |
-
demo.launch(show_error=True
|
|
|
|
| 5 |
from demucs.apply import apply_model
|
| 6 |
from pyharp import *
|
| 7 |
from audiotools import AudioSignal
|
| 8 |
+
from typing import Tuple, Dict
|
| 9 |
|
| 10 |
|
| 11 |
# Available Demucs models
|
|
|
|
| 66 |
stem_signal = AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
|
| 67 |
return stem_signal
|
| 68 |
|
| 69 |
+
def process_fn_stem(
|
| 70 |
+
audio_file_path: str,
|
| 71 |
+
demucs_model: str,
|
| 72 |
+
stem_choice: str,
|
| 73 |
+
request: gr.Request # Needed for OAuth
|
| 74 |
+
) -> Tuple[str, Dict]:
|
| 75 |
"""
|
| 76 |
+
PyHARP process function (OAuth-safe):
|
| 77 |
+
- Separates a stem from audio using Demucs.
|
| 78 |
+
- Returns a path to the output WAV + dummy metadata.
|
| 79 |
"""
|
| 80 |
+
|
| 81 |
+
# Get user's HF OAuth token if available (optional usage)
|
| 82 |
+
user_token = request.headers.get("Authorization", None)
|
| 83 |
+
if user_token:
|
| 84 |
+
user_token = user_token.replace("Bearer ", "")
|
| 85 |
+
print(f"User is authenticated with token (truncated): {user_token[:10]}...")
|
| 86 |
+
|
| 87 |
+
# Run stem separation
|
| 88 |
+
stem_signal = separate_stem(
|
| 89 |
+
audio_file_path,
|
| 90 |
+
model_name=demucs_model,
|
| 91 |
+
stem_choice=stem_choice
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Save output audio file
|
| 95 |
+
stem_filename = f"{stem_choice.lower().replace(' ', '_')}.wav"
|
| 96 |
+
stem_path = save_audio(stem_signal, stem_filename)
|
| 97 |
+
|
| 98 |
+
# Return stem path + basic metadata (dict that Gradio can serialize)
|
| 99 |
+
return stem_path, {
|
| 100 |
+
"stem": stem_choice,
|
| 101 |
+
"model": demucs_model,
|
| 102 |
+
"is_authenticated": bool(user_token)
|
| 103 |
+
}
|
| 104 |
|
| 105 |
|
| 106 |
# Define the model card
|
|
|
|
| 134 |
)
|
| 135 |
|
| 136 |
demo.queue()
|
| 137 |
+
demo.launch(show_error=True)
|