Spaces:
Running
Running
Update a.py
Browse files
a.py
CHANGED
|
@@ -269,9 +269,14 @@ def parse_url_params(request: gr.Request):
|
|
| 269 |
"""Parse taskid from URL parameters"""
|
| 270 |
task_id = None
|
| 271 |
if request:
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
return task_id
|
| 277 |
|
|
@@ -280,10 +285,10 @@ with gr.Blocks() as app:
|
|
| 280 |
gr.Markdown("# 🎵 Suno Song Generator")
|
| 281 |
gr.Markdown("Create songs from lyrics and style using Suno AI")
|
| 282 |
|
| 283 |
-
#
|
| 284 |
-
|
| 285 |
|
| 286 |
-
with gr.Tab("🎶 Generate Song", id=
|
| 287 |
with gr.Row():
|
| 288 |
with gr.Column(scale=1):
|
| 289 |
# Lyrics Input
|
|
@@ -351,7 +356,7 @@ with gr.Blocks() as app:
|
|
| 351 |
value="### Ready to generate!\n\nEnter lyrics and settings, then click 'Generate Song'"
|
| 352 |
)
|
| 353 |
|
| 354 |
-
with gr.Tab("🔍 Check Any Task", id=
|
| 355 |
with gr.Row():
|
| 356 |
with gr.Column(scale=1):
|
| 357 |
gr.Markdown("### Check Task Status")
|
|
@@ -380,7 +385,7 @@ with gr.Blocks() as app:
|
|
| 380 |
value="### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results."
|
| 381 |
)
|
| 382 |
|
| 383 |
-
with gr.Tab("📚 Instructions", id=
|
| 384 |
gr.Markdown("""
|
| 385 |
## 📖 How to Use This App
|
| 386 |
|
|
@@ -439,7 +444,7 @@ with gr.Blocks() as app:
|
|
| 439 |
- Generation may have failed
|
| 440 |
""")
|
| 441 |
|
| 442 |
-
with gr.Tab("📚 Less Instructions", id=
|
| 443 |
gr.Markdown("""
|
| 444 |
## 📖 How to Use This App
|
| 445 |
|
|
@@ -513,16 +518,30 @@ with gr.Blocks() as app:
|
|
| 513 |
def on_page_load(request: gr.Request):
|
| 514 |
"""Handle URL parameters when page loads"""
|
| 515 |
task_id = parse_url_params(request)
|
|
|
|
| 516 |
if task_id:
|
| 517 |
-
#
|
| 518 |
-
|
| 519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
|
| 521 |
# Load URL parameters when the app starts
|
| 522 |
app.load(
|
| 523 |
fn=on_page_load,
|
| 524 |
inputs=[],
|
| 525 |
-
outputs=[check_task_id, check_output, gr.Tabs(
|
| 526 |
queue=False
|
| 527 |
)
|
| 528 |
|
|
|
|
| 269 |
"""Parse taskid from URL parameters"""
|
| 270 |
task_id = None
|
| 271 |
if request:
|
| 272 |
+
try:
|
| 273 |
+
query_params = parse_qs(urlparse(request.request.url).query)
|
| 274 |
+
if 'taskid' in query_params:
|
| 275 |
+
task_id = query_params['taskid'][0]
|
| 276 |
+
# Remove any whitespace
|
| 277 |
+
task_id = task_id.strip()
|
| 278 |
+
except Exception as e:
|
| 279 |
+
print(f"Error parsing URL params: {e}")
|
| 280 |
|
| 281 |
return task_id
|
| 282 |
|
|
|
|
| 285 |
gr.Markdown("# 🎵 Suno Song Generator")
|
| 286 |
gr.Markdown("Create songs from lyrics and style using Suno AI")
|
| 287 |
|
| 288 |
+
# We'll use a hidden component to track initial load
|
| 289 |
+
initial_load_done = gr.State(value=False)
|
| 290 |
|
| 291 |
+
with gr.Tab("🎶 Generate Song", id="generate_tab") as tab_generate:
|
| 292 |
with gr.Row():
|
| 293 |
with gr.Column(scale=1):
|
| 294 |
# Lyrics Input
|
|
|
|
| 356 |
value="### Ready to generate!\n\nEnter lyrics and settings, then click 'Generate Song'"
|
| 357 |
)
|
| 358 |
|
| 359 |
+
with gr.Tab("🔍 Check Any Task", id="check_tab") as tab_check:
|
| 360 |
with gr.Row():
|
| 361 |
with gr.Column(scale=1):
|
| 362 |
gr.Markdown("### Check Task Status")
|
|
|
|
| 385 |
value="### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results."
|
| 386 |
)
|
| 387 |
|
| 388 |
+
with gr.Tab("📚 Instructions", id="instructions_tab"):
|
| 389 |
gr.Markdown("""
|
| 390 |
## 📖 How to Use This App
|
| 391 |
|
|
|
|
| 444 |
- Generation may have failed
|
| 445 |
""")
|
| 446 |
|
| 447 |
+
with gr.Tab("📚 Less Instructions", id="less_instructions_tab"):
|
| 448 |
gr.Markdown("""
|
| 449 |
## 📖 How to Use This App
|
| 450 |
|
|
|
|
| 518 |
def on_page_load(request: gr.Request):
|
| 519 |
"""Handle URL parameters when page loads"""
|
| 520 |
task_id = parse_url_params(request)
|
| 521 |
+
|
| 522 |
if task_id:
|
| 523 |
+
# We have a task ID from URL, return it and fetch results
|
| 524 |
+
task_result = get_task_info(task_id)
|
| 525 |
+
return (
|
| 526 |
+
task_id, # For check_task_id
|
| 527 |
+
task_result, # For check_output
|
| 528 |
+
gr.Tabs(selected="check_tab"), # Switch to check tab
|
| 529 |
+
True # Mark as loaded
|
| 530 |
+
)
|
| 531 |
+
else:
|
| 532 |
+
# No task ID in URL, stay on first tab
|
| 533 |
+
return (
|
| 534 |
+
"", # Empty check_task_id
|
| 535 |
+
"### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results.", # Default message
|
| 536 |
+
gr.Tabs(selected="generate_tab"), # Stay on generate tab
|
| 537 |
+
True # Mark as loaded
|
| 538 |
+
)
|
| 539 |
|
| 540 |
# Load URL parameters when the app starts
|
| 541 |
app.load(
|
| 542 |
fn=on_page_load,
|
| 543 |
inputs=[],
|
| 544 |
+
outputs=[check_task_id, check_output, gr.Tabs(), initial_load_done],
|
| 545 |
queue=False
|
| 546 |
)
|
| 547 |
|