MySafeCode commited on
Commit
41ec818
·
verified ·
1 Parent(s): 3bdc340

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -38
app.py CHANGED
@@ -222,7 +222,7 @@ def check_song_status(task_id, show_raw=False):
222
 
223
  # Create the app
224
  with gr.Blocks() as app:
225
- gr.Markdown("# 🎵 Suno Song Generator")
226
 
227
  # Store current task ID
228
  current_task_id = gr.State(value="")
@@ -286,7 +286,6 @@ with gr.Blocks() as app:
286
  )
287
 
288
  check_btn = gr.Button("🔍 Check Status Now", variant="primary")
289
- auto_check = gr.Checkbox(label="Auto-check every 30s", value=False)
290
 
291
  gr.Markdown("""
292
  **What to expect:**
@@ -307,6 +306,68 @@ with gr.Blocks() as app:
307
  value="*Raw JSON will appear here when you check status*"
308
  )
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  with gr.Tab("📋 Instructions"):
311
  gr.Markdown("""
312
  ## 🎵 Complete Workflow
@@ -317,36 +378,87 @@ with gr.Blocks() as app:
317
  - **IMMEDIATELY get a Task ID**
318
  - Copy the Task ID
319
 
320
- ### 2. Check Status
321
  - Switch to **Check Status** tab
322
  - Task ID auto-fills
323
  - Click **Check Status Now**
324
  - Wait for **TEXT_SUCCESS** status
325
 
326
- ### 3. Download Songs
327
- - When **TEXT_SUCCESS** appears:
328
- - **Listen Now** links with audio players
329
- - **Download** links for MP3 files
330
- - Cover art images
331
- - Track IDs for reference
332
 
333
- ### 4. Tips
334
- - Processing: **1-3 minutes**
335
- - Check every **30 seconds**
336
- - Use **Auto-check** for convenience
337
- - Raw data available for debugging
338
 
339
  ### 5. Status Meanings
340
  - **TEXT_SUCCESS**: ✅ Songs ready!
341
  - **PENDING/PROCESSING**: ⏳ Still working
342
  - **SUCCESS**: Check raw data
343
  - **FAILED**: Try again
344
-
345
- ### 6. Callback System
346
- - Results also sent to: https://1hit.no/callback.php
347
- - View all results: https://1hit.no/viewer.php
348
  """)
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  # Auto-fill status tab with task ID
351
  def update_status_field(task_id):
352
  return task_id
@@ -366,23 +478,4 @@ with gr.Blocks() as app:
366
 
367
  submit_btn.click(
368
  fn=on_generate,
369
- inputs=[lyrics_text, style, title, instrumental, model],
370
- outputs=[submission_output, current_task_id, status_task_id]
371
- )
372
-
373
- # Check status
374
- def on_check(task_id, show_raw):
375
- output, raw = check_song_status(task_id, show_raw)
376
- return output, raw
377
-
378
- check_btn.click(
379
- fn=on_check,
380
- inputs=[status_task_id, gr.State(True)], # Always show raw
381
- outputs=[status_output, raw_output]
382
- )
383
-
384
- if __name__ == "__main__":
385
- print("🚀 Starting Suno Song Generator")
386
- print(f"🔑 SunoKey: {'✅ Set' if SUNO_KEY else '❌ Not set'}")
387
- print("🌐 Open your browser to: http://localhost:7860")
388
- app.launch(server_name="0.0.0.0", server_port=7860, share=False)
 
222
 
223
  # Create the app
224
  with gr.Blocks() as app:
225
+ gr.Markdown("# 🎵 Suno Song Generator + Player")
226
 
227
  # Store current task ID
228
  current_task_id = gr.State(value="")
 
286
  )
287
 
288
  check_btn = gr.Button("🔍 Check Status Now", variant="primary")
 
289
 
290
  gr.Markdown("""
291
  **What to expect:**
 
306
  value="*Raw JSON will appear here when you check status*"
307
  )
308
 
309
+ with gr.Tab("🎧 Music Player"):
310
+ with gr.Row():
311
+ with gr.Column(scale=1):
312
+ gr.Markdown("### Music Player")
313
+ gr.Markdown("Play any MP3 URL or use the default track")
314
+
315
+ music_url = gr.Textbox(
316
+ label="MP3 URL",
317
+ value="https://huggingface.co/spaces/MySafeCode/SUNO-API-V5/resolve/main/Gnomes%20remember.mp3",
318
+ info="Enter any direct MP3 URL"
319
+ )
320
+
321
+ play_btn = gr.Button("▶️ Play This URL", variant="primary")
322
+ reset_btn = gr.Button("🔄 Reset to Default", variant="secondary")
323
+
324
+ gr.Markdown("""
325
+ **Features:**
326
+ - Play any public MP3 URL
327
+ - Default: "Gnomes remember" track
328
+ - Volume control
329
+ - Play/pause/seek
330
+ - Works with your generated songs!
331
+ """)
332
+
333
+ with gr.Column(scale=2):
334
+ # Audio player display
335
+ gr.Markdown("### 🔊 Player")
336
+ audio_player = gr.HTML(
337
+ value="""<audio id="musicPlayer" controls style="width: 100%; height: 100px; margin: 20px 0;">
338
+ <source src="https://huggingface.co/spaces/MySafeCode/SUNO-API-V5/resolve/main/Gnomes%20remember.mp3" type="audio/mpeg">
339
+ Your browser does not support audio playback.
340
+ </audio>
341
+ <div style="margin-top: 10px; padding: 10px; background: #f5f5f5; border-radius: 5px;">
342
+ <strong>Now Playing:</strong> Gnomes remember.mp3 (Default track)
343
+ </div>"""
344
+ )
345
+
346
+ # Quick player controls
347
+ with gr.Row():
348
+ volume_slider = gr.Slider(
349
+ minimum=0,
350
+ maximum=100,
351
+ value=80,
352
+ label="Volume",
353
+ interactive=True
354
+ )
355
+
356
+ # Quick links to generated songs
357
+ gr.Markdown("### 🎵 Quick Play")
358
+ gr.Markdown("Paste URLs from generated songs:")
359
+
360
+ quick_url_1 = gr.Textbox(
361
+ label="Song URL 1",
362
+ placeholder="Paste audio URL here",
363
+ lines=1
364
+ )
365
+ quick_url_2 = gr.Textbox(
366
+ label="Song URL 2",
367
+ placeholder="Paste another URL here",
368
+ lines=1
369
+ )
370
+
371
  with gr.Tab("📋 Instructions"):
372
  gr.Markdown("""
373
  ## 🎵 Complete Workflow
 
378
  - **IMMEDIATELY get a Task ID**
379
  - Copy the Task ID
380
 
381
+ ### 2. Check Status
382
  - Switch to **Check Status** tab
383
  - Task ID auto-fills
384
  - Click **Check Status Now**
385
  - Wait for **TEXT_SUCCESS** status
386
 
387
+ ### 3. Play & Download
388
+ - When ready, use **Music Player** tab:
389
+ - Play generated songs
390
+ - Download MP3 files
391
+ - Volume control
392
+ - Quick URLs
393
 
394
+ ### 4. Player Features
395
+ - **Default track**: Gnomes remember.mp3
396
+ - **Any MP3 URL**: Paste and play
397
+ - **From Suno**: Use streamAudioUrl
398
+ - **Volume control**: Adjust as needed
399
 
400
  ### 5. Status Meanings
401
  - **TEXT_SUCCESS**: ✅ Songs ready!
402
  - **PENDING/PROCESSING**: ⏳ Still working
403
  - **SUCCESS**: Check raw data
404
  - **FAILED**: Try again
 
 
 
 
405
  """)
406
 
407
+ # JavaScript for music player
408
+ app.load(
409
+ None,
410
+ None,
411
+ None,
412
+ js="""
413
+ function updateAudioPlayer(url, title) {
414
+ const player = document.getElementById('musicPlayer');
415
+ if (player) {
416
+ // Update audio source
417
+ const source = player.querySelector('source');
418
+ if (source) {
419
+ source.src = url;
420
+ }
421
+
422
+ // Update player src
423
+ player.src = url;
424
+
425
+ // Update label
426
+ const label = document.querySelector('#musicPlayer + div');
427
+ if (label) {
428
+ label.innerHTML = '<strong>Now Playing:</strong> ' + (title || url);
429
+ }
430
+
431
+ // Load new audio
432
+ player.load();
433
+
434
+ // Try to play
435
+ player.play().catch(e => console.log("Auto-play prevented:", e));
436
+ }
437
+ }
438
+
439
+ // Volume control
440
+ function updateVolume(volume) {
441
+ const player = document.getElementById('musicPlayer');
442
+ if (player) {
443
+ player.volume = volume / 100;
444
+ }
445
+ }
446
+
447
+ // Quick play functions
448
+ function playQuickUrl1(url) {
449
+ if (url && url.includes('://')) {
450
+ updateAudioPlayer(url, 'Quick Song 1');
451
+ }
452
+ }
453
+
454
+ function playQuickUrl2(url) {
455
+ if (url && url.includes('://')) {
456
+ updateAudioPlayer(url, 'Quick Song 2');
457
+ }
458
+ }
459
+ """
460
+ )
461
+
462
  # Auto-fill status tab with task ID
463
  def update_status_field(task_id):
464
  return task_id
 
478
 
479
  submit_btn.click(
480
  fn=on_generate,
481
+ inputs=[lyrics](streamdown:incomplete-link)