MySafeCode commited on
Commit
17a08f4
·
verified ·
1 Parent(s): 67dc5d2

Create mars.py

Browse files
Files changed (1) hide show
  1. mars.py +590 -0
mars.py ADDED
@@ -0,0 +1,590 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+ import time
5
+ import json
6
+ from urllib.parse import urlparse, parse_qs
7
+
8
+ # Suno API key
9
+ SUNO_KEY = os.environ.get("SunoKey", "")
10
+ if not SUNO_KEY:
11
+ print("⚠️ SunoKey not set!")
12
+
13
+ def get_task_info(task_id):
14
+ """Manually check any Suno task status"""
15
+ if not task_id:
16
+ return "❌ Please enter a Task ID ❌"
17
+
18
+ try:
19
+ resp = requests.get(
20
+ "https://api.sunoapi.org/api/v1/generate/record-info",
21
+ headers={"Authorization": f"Bearer {SUNO_KEY}"},
22
+ params={"taskId": task_id},
23
+ timeout=30
24
+ )
25
+
26
+ if resp.status_code != 200:
27
+ return f"❌ HTTP Error {resp.status_code}\n\n{resp.text}"
28
+
29
+ data = resp.json()
30
+
31
+ # Format the response for display
32
+ output = f"## 🔍 Task Status: `{task_id}`\n\n"
33
+
34
+ if data.get("code") == 200:
35
+ task_data = data.get("data", {})
36
+ status = task_data.get("status", "UNKNOWN")
37
+
38
+ output += f"**Status:** {status}\n"
39
+ output += f"**Task ID:** `{task_data.get('taskId', 'N/A')}`\n"
40
+ output += f"**Music ID:** `{task_data.get('musicId', 'N/A')}`\n"
41
+ output += f"**Created:** {task_data.get('createTime', 'N/A')}\n"
42
+
43
+ if status == "SUCCESS":
44
+ response_data = task_data.get("response", {})
45
+
46
+ # Try to parse response (could be string or dict)
47
+ if isinstance(response_data, str):
48
+ try:
49
+ response_data = json.loads(response_data)
50
+ except:
51
+ output += f"\n**Raw Response:**\n```\n{response_data}\n```\n"
52
+ response_data = {}
53
+
54
+ # Check for song data
55
+ songs = []
56
+ if isinstance(response_data, dict):
57
+ songs = response_data.get("sunoData", [])
58
+ if not songs:
59
+ songs = response_data.get("data", [])
60
+ elif isinstance(response_data, list):
61
+ songs = response_data
62
+
63
+ if songs:
64
+ output += f"\n## 🎵 Generated Songs ({len(songs)})\n\n"
65
+
66
+ for i, song in enumerate(songs, 1):
67
+ if isinstance(song, dict):
68
+ output += f"### Song {i}\n"
69
+ output += f"**Title:** {song.get('title', 'Untitled')}\n"
70
+ output += f"**ID:** `{song.get('id', 'N/A')}`\n"
71
+
72
+ # Audio URLs
73
+ audio_url = song.get('audioUrl') or song.get('audio_url')
74
+ stream_url = song.get('streamUrl') or song.get('stream_url')
75
+ download_url = song.get('downloadUrl') or song.get('download_url')
76
+
77
+ if audio_url:
78
+ output += f"**Audio:** [Play]({audio_url}) | [Download]({audio_url})\n"
79
+ elif stream_url:
80
+ output += f"**Stream:** [Play]({stream_url})\n"
81
+
82
+ if download_url:
83
+ output += f"**Download:** [MP3]({download_url})\n"
84
+
85
+ # Audio player
86
+ play_url = audio_url or stream_url
87
+ if play_url:
88
+ output += f"""\n<audio controls style="width: 100%; margin: 10px 0;">
89
+ <source src="{play_url}" type="audio/mpeg">
90
+ Your browser does not support audio.
91
+ </audio>\n"""
92
+
93
+ output += f"**Prompt:** {song.get('prompt', 'N/A')[:100]}...\n"
94
+ output += f"**Duration:** {song.get('duration', 'N/A')}s\n"
95
+ output += f"**Created:** {song.get('createTime', 'N/A')}\n\n"
96
+ output += "---\n\n"
97
+ else:
98
+ output += "\n**No song data found in response.**\n"
99
+
100
+ elif status == "FAILED":
101
+ error_msg = task_data.get("errorMessage", "Unknown error")
102
+ output += f"\n**Error:** {error_msg}\n"
103
+
104
+ elif status in ["PENDING", "PROCESSING", "RUNNING"]:
105
+ output += f"\n**Task is still processing...**\n"
106
+ output += f"Check again in 30 seconds.\n"
107
+
108
+ else:
109
+ output += f"\n**Unknown status:** {status}\n"
110
+
111
+ else:
112
+ output += f"**API Error:** {data.get('msg', 'Unknown')}\n"
113
+
114
+ # Show raw JSON for debugging
115
+ output += "\n## 📋 Raw Response\n"
116
+ output += f"```json\n{json.dumps(data, indent=2)}\n```"
117
+
118
+ return output
119
+
120
+ except Exception as e:
121
+ return f"❌ Error checking task: {str(e)}"
122
+
123
+ def generate_song_from_text(lyrics_text, style, title, instrumental, model):
124
+ """Generate a song from lyrics text"""
125
+ if not SUNO_KEY:
126
+ yield "❌ Error: SunoKey not configured in environment variables"
127
+ return
128
+
129
+ if not lyrics_text.strip() and not instrumental:
130
+ yield "❌ Error: Please provide lyrics or select instrumental"
131
+ return
132
+
133
+ if not style.strip():
134
+ yield "❌ Error: Please provide a music style"
135
+ return
136
+
137
+ if not title.strip():
138
+ yield "❌ Error: Please provide a song title"
139
+ return
140
+
141
+ try:
142
+ # Prepare request data
143
+ request_data = {
144
+ "customMode": True,
145
+ "instrumental": instrumental,
146
+ "model": model,
147
+ "callBackUrl": "https://1hit.no/gen/cb.php",
148
+ "style": style,
149
+ "title": title,
150
+ }
151
+
152
+ if not instrumental:
153
+ # Apply character limits
154
+ if model == "V4" and len(lyrics_text) > 3000:
155
+ lyrics_text = lyrics_text[:3000]
156
+ yield f"⚠️ Lyrics truncated to 3000 characters for V4 model\n\n"
157
+ elif model in ["V4_5", "V4_5PLUS", "V4_5ALL", "V5"] and len(lyrics_text) > 5000:
158
+ lyrics_text = lyrics_text[:5000]
159
+ yield f"⚠️ Lyrics truncated to 5000 characters for {model} model\n\n"
160
+
161
+ request_data["prompt"] = lyrics_text
162
+ else:
163
+ request_data["prompt"] = ""
164
+
165
+ # Apply style length limits
166
+ if model == "V4" and len(style) > 200:
167
+ style = style[:200]
168
+ yield f"⚠️ Style truncated to 200 characters for V4 model\n\n"
169
+ elif model in ["V4_5", "V4_5PLUS", "V4_5ALL", "V5"] and len(style) > 1000:
170
+ style = style[:1000]
171
+ yield f"⚠️ Style truncated to 1000 characters for {model} model\n\n"
172
+
173
+ # Apply title length limits
174
+ if model in ["V4", "V4_5ALL"] and len(title) > 80:
175
+ title = title[:80]
176
+ yield f"⚠️ Title truncated to 80 characters for {model} model\n\n"
177
+ elif model in ["V4_5", "V4_5PLUS", "V5"] and len(title) > 100:
178
+ title = title[:100]
179
+ yield f"⚠️ Title truncated to 100 characters for {model} model\n\n"
180
+
181
+ request_data["style"] = style
182
+ request_data["title"] = title
183
+
184
+ yield f"## 🚀 Submitting Song Request\n\n"
185
+ yield f"**Title:** {title}\n"
186
+ yield f"**Style:** {style}\n"
187
+ yield f"**Model:** {model}\n"
188
+ yield f"**Instrumental:** {'Yes' if instrumental else 'No'}\n"
189
+ if not instrumental:
190
+ yield f"**Lyrics length:** {len(lyrics_text)} characters\n\n"
191
+ yield f"**Callback URL:** https://1hit.no/callback.php\n\n"
192
+
193
+ # Submit generation request
194
+ try:
195
+ resp = requests.post(
196
+ "https://api.sunoapi.org/api/v1/generate",
197
+ json=request_data,
198
+ headers={
199
+ "Authorization": f"Bearer {SUNO_KEY}",
200
+ "Content-Type": "application/json"
201
+ },
202
+ timeout=30
203
+ )
204
+
205
+ if resp.status_code != 200:
206
+ yield f"❌ Submission failed: HTTP {resp.status_code}"
207
+ yield f"\n**Response:**\n```\n{resp.text}\n```"
208
+ return
209
+
210
+ data = resp.json()
211
+ print(f"Submission response: {json.dumps(data, indent=2)}")
212
+
213
+ if data.get("code") != 200:
214
+ yield f"❌ API error: {data.get('msg', 'Unknown')}"
215
+ return
216
+
217
+ # Extract task ID from response
218
+ task_id = None
219
+ if "taskId" in data:
220
+ task_id = data["taskId"]
221
+ elif "data" in data and "taskId" in data["data"]:
222
+ task_id = data["data"]["taskId"]
223
+ elif data.get("data") and "taskId" in data.get("data", {}):
224
+ task_id = data["data"]["taskId"]
225
+
226
+ if not task_id:
227
+ yield f"❌ Could not extract Task ID from response"
228
+ yield f"\n**Raw Response:**\n```json\n{json.dumps(data, indent=2)}\n```"
229
+ return
230
+
231
+ yield f"## ✅ Request Submitted Successfully!\n\n"
232
+ yield f"**🎯 Task ID:** `{task_id}`\n\n"
233
+ yield f"**⏳ Status:** Generation started\n"
234
+ yield f"**📞 Callback:** https://1hit.no/callback.php\n\n"
235
+ yield "**What happens now:**\n"
236
+ yield "1. Suno AI generates your song (1-3 minutes)\n"
237
+ yield "2. You'll get a callback notification\n"
238
+ yield "3. Use the Task ID above to check status manually\n\n"
239
+ yield "---\n\n"
240
+ yield f"## 🔍 Check Status Manually\n\n"
241
+ yield f"Use this Task ID: `{task_id}`\n\n"
242
+ yield "**To check status:**\n"
243
+ yield "1. Copy the Task ID above\n"
244
+ yield "2. Go to 'Check Any Task' tab\n"
245
+ yield "3. Paste and click 'Check Status'\n"
246
+ yield "4. Or wait for callback notification\n\n"
247
+ yield "**Generation time:**\n"
248
+ yield "- 30-60 seconds for stream URL\n"
249
+ yield "- 2-3 minutes for download URL\n"
250
+
251
+ # Simple one-time check after 30 seconds
252
+ yield "\n**⏰ Will check once in 30 seconds...**\n"
253
+ time.sleep(30)
254
+
255
+ # Single status check
256
+ status_result = get_task_info(task_id)
257
+ yield "\n## 📊 Status Check (30s)\n\n"
258
+ yield status_result
259
+
260
+ except Exception as e:
261
+ yield f"❌ Error submitting request: {str(e)}"
262
+ return
263
+
264
+ except Exception as e:
265
+ yield f"❌ **Unexpected Error:** {str(e)}"
266
+
267
+ # Function to handle URL parameters
268
+ def parse_url_params(request: gr.Request):
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
+
283
+ # Create the app
284
+ with gr.Blocks() as app:
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.TabItem("Audio Link"):
292
+ gr.HTML("""
293
+ <p>27 feb 2026 - This project may take a break in Mars. You may copy it and use your own Suno keys privatly or publicly. :)</p>
294
+ <p>There are two secret keys. SunoKey is essential. The Salt key is not yet implemented. It was intended for proof or receipe,</p>
295
+ <p>like a certificate of ownership if the song was ever monetized in some sense. Anyway, thanks for participating. It was fun.</p>
296
+
297
+ <p>(: -------------- :)</p>
298
+ <p>20 feb 2026 - WOW! We are featured on two mockup radio stations. :)</p>
299
+ <p>(: -------------- :)</p>
300
+ <a href="https://1hit.no/1radio.m3u" target="_blank">1hit radio - Chat GPT is host</a>
301
+ <a href="https://1hit.no/onlineradio.m3u" target="_blank">1hit radio - Deepseek is host</a>
302
+ <p>(: -------------- :)</p>
303
+
304
+ <p>Hey gangster kids, plis clean up the site for me, you are making a mess!</p>
305
+ <a href=" https://1hit.no/gen/audio/images/patchfix.php" target="_blank">Open 1hit Image Cleanup</a>
306
+
307
+
308
+ <p>Click below to open the audio page:</p>
309
+ <a href="https://1hit.no/gen/audio/mp3/" target="_blank">Open 1hit Audio</a>
310
+
311
+ <p>11 feb 2026 - New feature - Minimal m3u file download.</p>
312
+ <a href="https://1hit.no/gen/xm3u.php" target="_blank">Get complete m3u.file of music lib - with titles and duration</a>
313
+
314
+ <p>11 feb 2026 - New feature - Minimal m3u file download, better version comes up later?</p>
315
+ <a href="https://1hit.no/gen/sm3u.php" target="_blank">Get complete m3u.file of music lib - with taskid</a>
316
+
317
+ <p>Tested with VLC</p>
318
+ <a href=" https://www.videolan.org/vlc/" target="_blank">Download VLC media player</a>
319
+
320
+ <p>13 feb 2026 - Making a backup of dataset available, but made to many commits. :)</p>
321
+ <a href="https://huggingface.co/datasets/MySafeCode/1hit.no-Music-Images/" target="_blank">https://huggingface.co/datasets/MySafeCode/1hit.no-Music-Images/</a>
322
+
323
+ """)
324
+
325
+
326
+ with gr.Tab("🎶 Generate Song", id="generate_tab") as tab_generate:
327
+ with gr.Row():
328
+ with gr.Column(scale=1):
329
+ # Lyrics Input
330
+ gr.Markdown("### Step 1: Enter Lyrics")
331
+
332
+ lyrics_text = gr.Textbox(
333
+ label="Lyrics",
334
+ placeholder="Paste your lyrics here...\n\nExample:\n(Verse 1)\nSun is shining, sky is blue\nBirds are singing, just for you...",
335
+ lines=10,
336
+ interactive=True
337
+ )
338
+
339
+ # Song Settings
340
+ gr.Markdown("### Step 2: Song Settings")
341
+
342
+ style = gr.Textbox(
343
+ label="Music Style",
344
+ placeholder="Example: Pop, Rock, Jazz, Classical, Electronic, Hip Hop, Country",
345
+ value="Folk soul flamenco glam rock goa trance fusion",
346
+ interactive=True
347
+ )
348
+
349
+ title = gr.Textbox(
350
+ label="Song Title",
351
+ placeholder="My Awesome Song",
352
+ value="Generated Song",
353
+ interactive=True
354
+ )
355
+
356
+ with gr.Row():
357
+ instrumental = gr.Checkbox(
358
+ label="Instrumental (No Vocals)",
359
+ value=False,
360
+ interactive=True
361
+ )
362
+ model = gr.Dropdown(
363
+ label="Model",
364
+ choices=["V5", "V4_5PLUS", "V4_5ALL", "V4_5", "V4"],
365
+ value="V4_5ALL",
366
+ interactive=True
367
+ )
368
+
369
+ # Action Buttons
370
+ generate_btn = gr.Button("🚀 Generate Song", variant="primary")
371
+ clear_btn = gr.Button("🗑️ Clear All", variant="secondary")
372
+
373
+ # Instructions
374
+ gr.Markdown("""
375
+ **How to use:**
376
+ 1. Paste lyrics (or leave empty for instrumental)
377
+ 2. Set music style
378
+ 3. Enter song title
379
+ 4. Choose model
380
+ 5. Click Generate!
381
+
382
+ **Tips:**
383
+ - V4_5ALL: Best overall quality
384
+ - V5: Latest model
385
+ - Instrumental: No vocals, just music
386
+ """)
387
+
388
+ with gr.Column(scale=2):
389
+ # Output Area
390
+ output = gr.Markdown(
391
+ value="### Ready to generate!\n\nEnter lyrics and settings, then click 'Generate Song'"
392
+ )
393
+
394
+ with gr.Tab("🔍 Check Any Task", id="check_tab") as tab_check:
395
+ with gr.Row():
396
+ with gr.Column(scale=1):
397
+ gr.Markdown("### Check Task Status")
398
+ gr.Markdown("Enter any Suno Task ID to check its status")
399
+
400
+ check_task_id = gr.Textbox(
401
+ label="Task ID",
402
+ placeholder="Enter Task ID from generation or separation",
403
+ info="From Song Generator or Vocal Separator"
404
+ )
405
+
406
+ check_btn = gr.Button("🔍 Check Status", variant="primary")
407
+ check_clear_btn = gr.Button("🗑️ Clear", variant="secondary")
408
+
409
+ # URL parameter info
410
+ gr.Markdown("""
411
+ **Quick access via URL:**
412
+ Add `?taskid=YOUR_TASK_ID` to the URL
413
+
414
+ Example:
415
+ `https://1hit.no/gen/view.php?task_id=fa3529d5cbaa93427ee4451976ed5c4b`
416
+ """)
417
+
418
+ with gr.Column(scale=2):
419
+ check_output = gr.Markdown(
420
+ value="### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results."
421
+ )
422
+
423
+ with gr.Tab("📚 Instructions", id="instructions_tab"):
424
+ gr.Markdown("""
425
+ ## 📖 How to Use This App
426
+
427
+ ### 🎶 Generate Song Tab
428
+ 1. **Enter Lyrics** (or leave empty for instrumental)
429
+ 2. **Set Music Style** (e.g., "Pop", "Rock", "Jazz")
430
+ 3. **Enter Song Title**
431
+ 4. **Choose Model** (V4_5ALL recommended)
432
+ 5. **Click "Generate Song"**
433
+
434
+ ### 🔍 Check Any Task Tab
435
+ 1. **Paste any Suno Task ID**
436
+ 2. **Click "Check Status"**
437
+ 3. **View results and download links**
438
+
439
+ **Quick URL Access:**
440
+ - Visit with `?taskid=YOUR_TASK_ID` in the URL
441
+ - Automatically switches to Check tab
442
+ - Shows task status immediately
443
+
444
+ Example:
445
+ ```
446
+ https://1hit.no/gen/view.php?task_id=fa3529d5cbaa93427ee4451976ed5c4b
447
+ ```
448
+
449
+ ### ⏱️ What to Expect
450
+
451
+ **After generating:**
452
+ - You'll get a **Task ID** immediately
453
+ - Generation takes **1-3 minutes**
454
+ - **Callback** sent to https://1hit.no/gen/cb.php
455
+ - Use Task ID to **check status manually**
456
+
457
+ **Task IDs come from:**
458
+ - Song Generator (this app)
459
+ - Vocal Separator (other app)
460
+ - Any Suno API request
461
+
462
+ ### 🎵 Getting Your Songs
463
+
464
+ 1. **Stream URL:** Ready in 30-60 seconds
465
+ 2. **Download URL:** Ready in 2-3 minutes
466
+ 3. **Both appear in status check**
467
+ 4. **Audio player** included for streaming
468
+
469
+ ### 🔧 Troubleshooting
470
+
471
+ **Task not found?**
472
+ - Wait a few minutes
473
+ - Check callback logs at https://1hit.no/gen/view.php
474
+ - Ensure Task ID is correct
475
+
476
+ **No audio links?**
477
+ - Wait 2-3 minutes
478
+ - Check status again
479
+ - Generation may have failed
480
+ """)
481
+
482
+ with gr.Tab("📚 Less Instructions", id="less_instructions_tab"):
483
+ gr.Markdown("""
484
+ ## 📖 How to Use This App
485
+
486
+ ### 🎶 Generate Song Tab
487
+ 1. **Enter Lyrics** (or leave empty for instrumental)
488
+ 2. **Set Music Style** (e.g., "Pop", "Rock", "Jazz")
489
+ 3. **Enter Song Title**
490
+ 4. **Choose Model** (V4_5ALL recommended)
491
+ 5. **Click "Generate Song"**
492
+
493
+ ### 🔍 Check Any Task via URL
494
+ Add `?taskid=YOUR_TASK_ID` to the URL
495
+
496
+ Example:
497
+ ```
498
+ https://1hit.no/gen/view.php?task_id=fa3529d5cbaa93427ee4451976ed5c4b
499
+ ```
500
+
501
+ ### 📞 Callback Status
502
+ https://1hit.no/gen/view.php
503
+
504
+ **No audio links?**
505
+ - Wait 2-3 minutes
506
+ - Check status again
507
+ - Generation may have failed
508
+ """)
509
+
510
+ gr.Markdown("---")
511
+ gr.Markdown(
512
+ """
513
+ <div style="text-align: center; padding: 20px;">
514
+ <p>Powered by <a href="https://suno.ai" target="_blank">Suno AI</a> •
515
+ <a href="https://sunoapi.org" target="_blank">Suno API Docs</a></p>
516
+ <p><small>Create custom songs by providing lyrics and music style</small></p>
517
+ </div>
518
+ """,
519
+ elem_id="footer"
520
+ )
521
+
522
+ # Event handlers for Generate Song tab
523
+ def clear_all():
524
+ return "", "Pop", "Generated Song", False, "V4_5ALL", "### Ready to generate!\n\nEnter lyrics and settings, then click 'Generate Song'"
525
+
526
+ clear_btn.click(
527
+ clear_all,
528
+ outputs=[lyrics_text, style, title, instrumental, model, output]
529
+ )
530
+
531
+ generate_btn.click(
532
+ generate_song_from_text,
533
+ inputs=[lyrics_text, style, title, instrumental, model],
534
+ outputs=output
535
+ )
536
+
537
+ # Event handlers for Check Any Task tab
538
+ def clear_check():
539
+ return "", "### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results."
540
+
541
+ check_clear_btn.click(
542
+ clear_check,
543
+ outputs=[check_task_id, check_output]
544
+ )
545
+
546
+ check_btn.click(
547
+ get_task_info,
548
+ inputs=[check_task_id],
549
+ outputs=check_output
550
+ )
551
+
552
+ # Function to handle URL parameter on load
553
+ def on_page_load(request: gr.Request):
554
+ """Handle URL parameters when page loads"""
555
+ task_id = parse_url_params(request)
556
+
557
+ if task_id:
558
+ # We have a task ID from URL, return it and fetch results
559
+ task_result = get_task_info(task_id)
560
+ return (
561
+ task_id, # For check_task_id
562
+ task_result, # For check_output
563
+ gr.Tabs(selected="check_tab"), # Switch to check tab
564
+ True # Mark as loaded
565
+ )
566
+ else:
567
+ # No task ID in URL, stay on first tab
568
+ return (
569
+ "", # Empty check_task_id
570
+ "### Enter a Task ID above\n\nPaste any Suno Task ID to check its current status and results.", # Default message
571
+ gr.Tabs(selected="generate_tab"), # Stay on generate tab
572
+ True # Mark as loaded
573
+ )
574
+
575
+ # Load URL parameters when the app starts
576
+ app.load(
577
+ fn=on_page_load,
578
+ inputs=[],
579
+ outputs=[check_task_id, check_output, gr.Tabs(), initial_load_done],
580
+ queue=False
581
+ )
582
+
583
+ # Launch the app
584
+ if __name__ == "__main__":
585
+ print("🚀 Starting Suno Song Generator")
586
+ print(f"🔑 SunoKey: {'✅ Set' if SUNO_KEY else '❌ Not set'}")
587
+ print("🌐 Open your browser to: http://localhost:7860")
588
+ print("🔗 Use URL parameter: http://localhost:7860?taskid=YOUR_TASK_ID")
589
+
590
+ app.launch(server_name="0.0.0.0", server_port=7860, share=False)