Spaces:
Sleeping
Sleeping
Commit
·
9f160d1
1
Parent(s):
d83cd0a
handling labellist
Browse files- app.py +23 -14
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -66,23 +66,34 @@ def separate_stem(audio_file_path: str, model_name: str, stem_choice: str):
|
|
| 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
|
| 74 |
) -> Tuple[str, Dict]:
|
| 75 |
"""
|
| 76 |
-
PyHARP process function
|
| 77 |
-
- Separates a stem
|
| 78 |
-
- Returns
|
| 79 |
"""
|
| 80 |
|
| 81 |
-
# Get
|
| 82 |
user_token = request.headers.get("Authorization", None)
|
| 83 |
if user_token:
|
| 84 |
user_token = user_token.replace("Bearer ", "")
|
| 85 |
-
print(f"
|
| 86 |
|
| 87 |
# Run stem separation
|
| 88 |
stem_signal = separate_stem(
|
|
@@ -91,16 +102,14 @@ def process_fn_stem(
|
|
| 91 |
stem_choice=stem_choice
|
| 92 |
)
|
| 93 |
|
| 94 |
-
# Save output
|
| 95 |
stem_filename = f"{stem_choice.lower().replace(' ', '_')}.wav"
|
| 96 |
stem_path = save_audio(stem_signal, stem_filename)
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
"auth_status": "authenticated" if user_token else "unauthenticated"
|
| 103 |
-
}
|
| 104 |
|
| 105 |
|
| 106 |
# Define the model card
|
|
@@ -134,4 +143,4 @@ with gr.Blocks() as demo:
|
|
| 134 |
)
|
| 135 |
|
| 136 |
demo.queue()
|
| 137 |
-
|
|
|
|
| 66 |
stem_signal = AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
|
| 67 |
return stem_signal
|
| 68 |
|
| 69 |
+
|
| 70 |
+
def label_list_to_dict(label_list: LabelList) -> dict:
|
| 71 |
+
"""
|
| 72 |
+
Converts a LabelList (with nested dataclasses) into a plain dictionary
|
| 73 |
+
that Gradio + OAuth schema can serialize.
|
| 74 |
+
"""
|
| 75 |
+
return {
|
| 76 |
+
"meta": label_list.meta,
|
| 77 |
+
"labels": [vars(label) for label in label_list.labels]
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
def process_fn_stem(
|
| 81 |
audio_file_path: str,
|
| 82 |
demucs_model: str,
|
| 83 |
stem_choice: str,
|
| 84 |
+
request: gr.Request
|
| 85 |
) -> Tuple[str, Dict]:
|
| 86 |
"""
|
| 87 |
+
OAuth-safe PyHARP process function.
|
| 88 |
+
- Separates audio into a selected stem using Demucs.
|
| 89 |
+
- Returns output WAV path + label metadata as a plain dict.
|
| 90 |
"""
|
| 91 |
|
| 92 |
+
# Get HF user token if available (optional)
|
| 93 |
user_token = request.headers.get("Authorization", None)
|
| 94 |
if user_token:
|
| 95 |
user_token = user_token.replace("Bearer ", "")
|
| 96 |
+
print(f"Authenticated user token: {user_token[:10]}...")
|
| 97 |
|
| 98 |
# Run stem separation
|
| 99 |
stem_signal = separate_stem(
|
|
|
|
| 102 |
stem_choice=stem_choice
|
| 103 |
)
|
| 104 |
|
| 105 |
+
# Save stem output
|
| 106 |
stem_filename = f"{stem_choice.lower().replace(' ', '_')}.wav"
|
| 107 |
stem_path = save_audio(stem_signal, stem_filename)
|
| 108 |
|
| 109 |
+
# Build a basic label list (you can customize this later)
|
| 110 |
+
label_list = LabelList(labels=[])
|
| 111 |
+
|
| 112 |
+
return stem_path, label_list_to_dict(label_list)
|
|
|
|
|
|
|
| 113 |
|
| 114 |
|
| 115 |
# Define the model card
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
demo.queue()
|
| 146 |
+
demo.launch(show_error=True,share=True)
|
requirements.txt
CHANGED
|
@@ -15,3 +15,4 @@ numpy<2
|
|
| 15 |
scipy
|
| 16 |
soundfile
|
| 17 |
hydra-core>=1.1
|
|
|
|
|
|
| 15 |
scipy
|
| 16 |
soundfile
|
| 17 |
hydra-core>=1.1
|
| 18 |
+
typing
|