Spaces:
Running
Running
File size: 6,367 Bytes
5621d80 7155a3e 2eaa647 c3f6215 d3cdef9 c3f6215 c063c00 e1c2b50 1f1b856 77c8e1c 1f1b856 77c8e1c 1f1b856 6c0850c 1f1b856 77c8e1c 1f1b856 6c0850c 1f1b856 77c8e1c 1f1b856 6c0850c 1f1b856 77c8e1c 1f1b856 2eaa647 1f1b856 5621d80 1f1b856 6c0850c 1f1b856 c063c00 5621d80 1f1b856 5621d80 2eaa647 5621d80 1f1b856 6c0850c 1f1b856 77c8e1c 1f1b856 c3f6215 1f1b856 6c0850c 1f1b856 c3f6215 1f1b856 c063c00 1f1b856 6c0850c 1f1b856 6c0850c 1f1b856 2eaa647 1f1b856 c063c00 1f1b856 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import gradio as gr
import requests
import os
import json
from datetime import datetime
# Load Suno API key
SUNO_KEY = os.environ.get("SunoKey", "")
if not SUNO_KEY:
print("⚠️ Warning: SunoKey environment variable not set!")
def test_all_endpoints():
"""Test all possible Suno API endpoints to find the right one"""
results = ["# 🔍 Testing All Suno API Endpoints", ""]
headers = {"Authorization": f"Bearer {SUNO_KEY}"}
endpoints = [
("GET", "https://api.sunoapi.org/api/v1/lyrics", "Base lyrics endpoint"),
("GET", "https://api.sunoapi.org/api/v1/lyrics/record-info", "Record info endpoint"),
("GET", "https://api.sunoapi.org/api/v1/lyrics/details", "Details endpoint"),
("POST", "https://api.sunoapi.org/api/v1/lyrics", "Submit lyrics"),
]
for method, url, description in endpoints:
results.append(f"\n## 🔗 {method} {url.split('/')[-1]}")
results.append(f"**Description:** {description}")
try:
if method == "GET":
response = requests.get(url, headers=headers, timeout=10)
else: # POST
# Try POST with minimal payload
post_headers = headers.copy()
post_headers["Content-Type"] = "application/json"
payload = {
"prompt": "Test endpoint",
"callBackUrl": "http://test.com/callback"
}
response = requests.post(url, json=payload, headers=post_headers, timeout=10)
results.append(f"**HTTP Status:** {response.status_code}")
if response.status_code == 200:
try:
data = response.json()
results.append(f"**Response:** ```json\n{json.dumps(data, indent=2)[:500]}...\n```")
except:
results.append(f"**Response:** {response.text[:200]}...")
else:
results.append(f"**Error:** {response.text[:200]}...")
except Exception as e:
results.append(f"**Exception:** {str(e)}")
return "\n".join(results)
def test_correct_workflow():
"""Test what SHOULD be the correct workflow based on your code"""
results = ["# 🎯 Testing Correct Workflow", ""]
if not SUNO_KEY:
return "❌ No SunoKey configured"
headers = {"Authorization": f"Bearer {SUNO_KEY}"}
# Step 1: Submit lyrics (as per your original working code)
results.append("## 1️⃣ Submit Lyrics")
submit_url = "https://api.sunoapi.org/api/v1/lyrics"
submit_headers = headers.copy()
submit_headers["Content-Type"] = "application/json"
payload = {
"prompt": "Correct workflow test song",
"callBackUrl": "http://correct-test.com/callback"
}
try:
response = requests.post(submit_url, json=payload, headers=submit_headers, timeout=30)
results.append(f"**Status:** {response.status_code}")
if response.status_code == 200:
data = response.json()
results.append(f"**Code:** {data.get('code')}")
results.append(f"**Message:** {data.get('msg', 'No message')}")
if data.get("code") == 200 and "data" in data:
task_id = data["data"]["taskId"]
results.append(f"**Task ID:** `{task_id}`")
# Step 2: Check using record-info endpoint (from your example)
results.append("\n## 2️⃣ Check with /record-info")
record_url = "https://api.sunoapi.org/api/v1/lyrics/record-info"
# Try different query parameters
test_params = [
{"taskId": task_id},
{"id": task_id},
{"record_id": task_id},
{}, # No params
]
for params in test_params:
results.append(f"\n**Trying params:** {params}")
try:
record_response = requests.get(
record_url,
headers=headers,
params=params,
timeout=30
)
results.append(f"Status: {record_response.status_code}")
if record_response.status_code == 200:
record_data = record_response.json()
results.append(f"Response: ```json\n{json.dumps(record_data, indent=2)[:300]}...\n```")
else:
results.append(f"Error: {record_response.text[:100]}")
except Exception as e:
results.append(f"Exception: {str(e)}")
# Step 3: Also try details endpoint for comparison
results.append("\n## 3️⃣ Check with /details (for comparison)")
details_url = f"https://api.sunoapi.org/api/v1/lyrics/details?taskId={task_id}"
try:
details_response = requests.get(details_url, headers=headers, timeout=30)
results.append(f"Status: {details_response.status_code}")
if details_response.status_code == 200:
details_data = details_response.json()
results.append(f"Response: ```json\n{json.dumps(details_data, indent=2)[:300]}...\n```")
except Exception as e:
results.append(f"Exception: {str(e)}")
else:
results.append("❌ No task ID in response")
else:
results.append(f"❌ Submission failed: {response.text[:200]}")
except Exception as e:
results.append(f"❌ Exception: {str(e)}")
return "\n".join(results)
def check_api_documentation():
"""Show what we know about Suno API"""
return """# 📚 Suno API Documentation
## 🔍 What We Know:
### **Endpoints Found:**
1. `POST /api/v1/lyrics` - Submit lyrics generation
```json
{
"prompt": "song about...",
"callBackUrl": "https://your-webhook.com/callback"
} |