Spaces:
Paused
Paused
Update app.py
Browse files12 unmodified lines13141516161718192080 unmodified lines10110210310310410510610710810911010911111211111311411511611711811912012112212312411712512612712812112913013113213313413513613713813914014114223 unmodified lines16616716815116917017117217315617417517617737 unmodified lines215216217200218219220221124 unmodified lines34634734833134935035135212 unmodified linesdef generate_song_from_text(lyrics_text, style, title, instrumental, model, custom_mode=True): """Generate a song from lyrics text""" if not SUNO_KEY: return "❌ Error: SunoKey not configured in environment variables" yield "❌ Error: SunoKey not configured in environment variables" return if not lyrics_text.strip(): return "❌ Error: Please provide lyrics"80 unmodified lines task_id = data["data"]["taskId"] yield f"✅ **Request submitted!**\nTask ID: `{task_id}`\n\n⏳ Waiting for song generation...\n" # Poll for results # Poll for results - FIXED ENDPOINT for attempt in range(60): # 60 attempts * 5 seconds = 300 seconds max (5 minutes) time.sleep(5) try: # FIX: Use the correct endpoint from the API docs check = requests.get( "https://api.sunoapi.org/api/v1/music-info", f"https://api.sunoapi.org/api/v1/generate/record-info?taskId={task_id}", headers={"Authorization": f"Bearer {SUNO_KEY}"}, params={"taskId": task_id}, timeout=30 ) if check.status_code == 200: check_data = check.json() # Check if the response structure is valid if check_data.get("code") != 200: yield f"⚠️ API returned error: {check_data.get('msg', 'Unknown')}" continue data_info = check_data.get("data", {}) status = check_data["data"].get("status", "PENDING") status = data_info.get("status", "PENDING") if status == "COMPLETE": # Success! Extract song URLs songs = check_data["data"].get("songs", []) response_data = data_info.get("response", {}) # Try to parse response if it's a string if isinstance(response_data, str): try: response_data = json.loads(response_data) except: response_data = {} songs = response_data.get("data", []) if songs: output = "🎶 **Song Generation Complete!**\n\n" for i, song in enumerate(songs, 1):23 unmodified lines return elif status == "FAILED": error = check_data["data"].get("errorMessage", "Unknown error") error = data_info.get("errorMessage", "Unknown error") yield f"❌ Task failed: {error}" return else: # Still processing # Still processing (PENDING or PROCESSING) if attempt % 6 == 0: # Update every 30 seconds yield f"⏳ Status: {status}\nAttempt: {attempt + 1}/60\nTask ID: `{task_id}`\n\nStill processing... (Usually takes 30-180 seconds)\n\nTypical timing:\n- 30-40s: Stream URL ready\n- 2-3 min: Download URL ready" else:37 unmodified lines
def clear_all(): """Clear all input fields""" return "", "", "Generated Song", False, "V4_5ALL", "" return "", "", "Generated Song", False, "V4_5ALL", "### Ready to generate!\n\n1. Enter lyrics\n2. Set style and title\n3. Click 'Generate Song'"
# Create the appwith gr.Blocks(title="Suno Song Generator", theme="soft") as app:124 unmodified lines inputs=lyrics_text, outputs=file_output ).then( lambda: "💾 **Lyrics ready for download!**", lambda: "💾 **Lyrics ready for download!**\n\nCheck the download button below.", outputs=output ) app.py+28-10