Spaces:
Running on Zero
Running on Zero
fix: audio from audios folder now loads into gr.Audio player
Browse files- src/webui.py +26 -8
src/webui.py
CHANGED
|
@@ -230,12 +230,18 @@ def refresh_audio_list():
|
|
| 230 |
|
| 231 |
|
| 232 |
def load_selected_audio(audio_path):
|
| 233 |
-
"""Load the selected audio file from the audios folder."""
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
|
| 241 |
def validate_audio_input(local_file_value):
|
|
@@ -246,6 +252,10 @@ def validate_audio_input(local_file_value):
|
|
| 246 |
if local_file_value is None:
|
| 247 |
return None
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
# If it's a string (path), check if it exists
|
| 250 |
if isinstance(local_file_value, str):
|
| 251 |
local_file_value = local_file_value.strip()
|
|
@@ -313,14 +323,22 @@ if __name__ == '__main__':
|
|
| 313 |
# Connect folder audio dropdown - updates both audio player and state
|
| 314 |
refresh_audio_btn.click(refresh_audio_list, outputs=folder_audio_dropdown)
|
| 315 |
folder_audio_dropdown.change(
|
| 316 |
-
|
| 317 |
inputs=[folder_audio_dropdown],
|
| 318 |
outputs=[local_file, audio_path_state]
|
| 319 |
)
|
| 320 |
|
| 321 |
# When local_file changes (from upload/URL), also update state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
local_file.change(
|
| 323 |
-
|
| 324 |
inputs=[local_file],
|
| 325 |
outputs=[audio_path_state]
|
| 326 |
)
|
|
|
|
| 230 |
|
| 231 |
|
| 232 |
def load_selected_audio(audio_path):
|
| 233 |
+
"""Load the selected audio file from the audios folder into gr.Audio format."""
|
| 234 |
+
print(f"[DEBUG] load_selected_audio called with: {audio_path}")
|
| 235 |
+
|
| 236 |
+
if not audio_path or not os.path.exists(audio_path):
|
| 237 |
+
print(f"[DEBUG] Audio path invalid or not found: {audio_path}")
|
| 238 |
+
return None, ""
|
| 239 |
+
|
| 240 |
+
# Return as tuple for gr.Audio: (filepath, caption)
|
| 241 |
+
# This will make the audio appear in the player!
|
| 242 |
+
result = (audio_path, os.path.basename(audio_path))
|
| 243 |
+
print(f"[DEBUG] Returning audio: {result}")
|
| 244 |
+
return result, audio_path
|
| 245 |
|
| 246 |
|
| 247 |
def validate_audio_input(local_file_value):
|
|
|
|
| 252 |
if local_file_value is None:
|
| 253 |
return None
|
| 254 |
|
| 255 |
+
# Handle tuple format (filepath, caption) from gr.Audio
|
| 256 |
+
if isinstance(local_file_value, tuple):
|
| 257 |
+
local_file_value = local_file_value[0]
|
| 258 |
+
|
| 259 |
# If it's a string (path), check if it exists
|
| 260 |
if isinstance(local_file_value, str):
|
| 261 |
local_file_value = local_file_value.strip()
|
|
|
|
| 323 |
# Connect folder audio dropdown - updates both audio player and state
|
| 324 |
refresh_audio_btn.click(refresh_audio_list, outputs=folder_audio_dropdown)
|
| 325 |
folder_audio_dropdown.change(
|
| 326 |
+
load_selected_audio,
|
| 327 |
inputs=[folder_audio_dropdown],
|
| 328 |
outputs=[local_file, audio_path_state]
|
| 329 |
)
|
| 330 |
|
| 331 |
# When local_file changes (from upload/URL), also update state
|
| 332 |
+
def update_audio_state(x):
|
| 333 |
+
"""Extract path from gr.Audio output (could be tuple or string)."""
|
| 334 |
+
if x is None:
|
| 335 |
+
return ""
|
| 336 |
+
if isinstance(x, tuple):
|
| 337 |
+
return x[0] if x[0] else ""
|
| 338 |
+
return str(x) if x else ""
|
| 339 |
+
|
| 340 |
local_file.change(
|
| 341 |
+
update_audio_state,
|
| 342 |
inputs=[local_file],
|
| 343 |
outputs=[audio_path_state]
|
| 344 |
)
|