Spaces:
Sleeping
Sleeping
Delete a.py
Browse files
a.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
# Updated polling function with correct endpoint
|
| 2 |
-
def poll_status(task_id, single_poll=False):
|
| 3 |
-
"""Poll Suno API for task status"""
|
| 4 |
-
if not task_id:
|
| 5 |
-
st.error("❌ Task ID cannot be empty. The API returned: '任务id不能为空' (Task ID cannot be empty)")
|
| 6 |
-
return False
|
| 7 |
-
|
| 8 |
-
headers = {
|
| 9 |
-
"Authorization": f"Bearer {st.session_state.suno_api_key}",
|
| 10 |
-
"Content-Type": "application/json"
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
with st.spinner(f"Checking status for task: {task_id}..."):
|
| 15 |
-
# Try different endpoint formats
|
| 16 |
-
endpoints_to_try = []
|
| 17 |
-
|
| 18 |
-
# Format 1: /api/v1/wav/record-info with task_id as query parameter
|
| 19 |
-
endpoints_to_try.append(f"https://api.sunoapi.org/api/v1/wav/record-info?taskId={task_id}")
|
| 20 |
-
|
| 21 |
-
# Format 2: Different endpoint pattern (possible other versions)
|
| 22 |
-
endpoints_to_try.append(f"https://api.sunoapi.org/api/v1/wav/record-info/{task_id}")
|
| 23 |
-
endpoints_to_try.append(f"https://api.sunoapi.org/api/v1/wav/record-info?id={task_id}")
|
| 24 |
-
|
| 25 |
-
# Format 3: JSON body
|
| 26 |
-
endpoints_to_try.append({
|
| 27 |
-
"url": "https://api.sunoapi.org/api/v1/wav/record-info",
|
| 28 |
-
"params": {"taskId": task_id}
|
| 29 |
-
})
|
| 30 |
-
|
| 31 |
-
response = None
|
| 32 |
-
for endpoint in endpoints_to_try:
|
| 33 |
-
try:
|
| 34 |
-
response = requests.get(
|
| 35 |
-
endpoint,
|
| 36 |
-
headers=headers,
|
| 37 |
-
timeout=30
|
| 38 |
-
)
|
| 39 |
-
if response.status_code == 200:
|
| 40 |
-
break
|
| 41 |
-
except:
|
| 42 |
-
continue
|
| 43 |
-
|
| 44 |
-
if not response:
|
| 45 |
-
st.error("❌ Could not connect to any polling endpoint")
|
| 46 |
-
return False
|
| 47 |
-
|
| 48 |
-
if response.status_code == 200:
|
| 49 |
-
result = response.json()
|
| 50 |
-
|
| 51 |
-
# Display result
|
| 52 |
-
if result.get("code") == 200:
|
| 53 |
-
data = result.get("data", {})
|
| 54 |
-
|
| 55 |
-
if data.get("successFlag") == "SUCCESS":
|
| 56 |
-
# Audio is ready!
|
| 57 |
-
audio_url = data.get("response", {}).get("audioWavUrl")
|
| 58 |
-
if audio_url:
|
| 59 |
-
st.success("✅ Audio ready!")
|
| 60 |
-
st.balloons()
|
| 61 |
-
|
| 62 |
-
# Display audio info
|
| 63 |
-
st.markdown("### 🎵 Audio Information")
|
| 64 |
-
cols = st.columns(2)
|
| 65 |
-
with cols[0]:
|
| 66 |
-
st.metric("Task ID", data.get("taskId", "N/A")[:12] + "...")
|
| 67 |
-
st.metric("Music ID", data.get("musicId", "N/A")[:12] + "...")
|
| 68 |
-
with cols[1]:
|
| 69 |
-
st.metric("Status", data.get("successFlag", "N/A"))
|
| 70 |
-
st.metric("Created", data.get("createTime", "N/A"))
|
| 71 |
-
|
| 72 |
-
# Audio player
|
| 73 |
-
st.markdown("### 🔊 Listen")
|
| 74 |
-
st.audio(audio_url, format="audio/wav")
|
| 75 |
-
|
| 76 |
-
# Download section
|
| 77 |
-
st.markdown("### 📥 Download")
|
| 78 |
-
st.code(audio_url)
|
| 79 |
-
|
| 80 |
-
col_dl1, col_dl2 = st.columns(2)
|
| 81 |
-
with col_dl1:
|
| 82 |
-
st.download_button(
|
| 83 |
-
label="⬇ Download WAV",
|
| 84 |
-
data=requests.get(audio_url).content if audio_url.startswith("http") else b"",
|
| 85 |
-
file_name=f"audio_{data.get('taskId', 'unknown')[:8]}.wav",
|
| 86 |
-
mime="audio/wav",
|
| 87 |
-
key=f"download_{task_id}"
|
| 88 |
-
)
|
| 89 |
-
with col_dl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|