Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,21 +82,29 @@ def submit_vocal_separation(task_id, audio_id):
|
|
| 82 |
data = resp.json()
|
| 83 |
print(f"Parsed data: {data}")
|
| 84 |
|
| 85 |
-
#
|
| 86 |
separation_task_id = None
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
separation_task_id = data["data"]["taskId"]
|
| 91 |
-
elif data.get("
|
| 92 |
separation_task_id = data["data"]["taskId"]
|
| 93 |
|
| 94 |
if separation_task_id:
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
else:
|
| 97 |
-
# Try to extract error or show raw response
|
| 98 |
error_msg = data.get("msg", data.get("error", "Unknown error"))
|
| 99 |
-
return f"❌ No task ID in response: {error_msg}\n\nRaw
|
| 100 |
else:
|
| 101 |
return f"❌ HTTP Error {resp.status_code}:\n{resp.text}", None
|
| 102 |
|
|
@@ -120,39 +128,89 @@ def check_separation_status(task_id):
|
|
| 120 |
|
| 121 |
if resp.status_code == 200:
|
| 122 |
data = resp.json()
|
| 123 |
-
print(f"Status data: {data}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
# Check
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
if
|
| 131 |
# Format results
|
| 132 |
-
output = "✅ **Separation Complete!**\n\n"
|
| 133 |
-
output += f"**Task ID:** `{task_id}`\n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
if
|
| 140 |
-
output += f"**📁 Original:** [Download MP3]({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
output += f"\n**🔗 Viewer:** [Open in Viewer](https://1hit.no/viewer.php?task_id={task_id})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
return output
|
| 144 |
else:
|
| 145 |
-
return f"✅ Processing complete
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
# Check for other statuses
|
| 148 |
-
status = data.get("data", {}).get("status", "UNKNOWN")
|
| 149 |
-
if status in ["PENDING", "PROCESSING", "RUNNING"]:
|
| 150 |
-
return f"⏳ **Status:** {status}\n\n**Task ID:** `{task_id}`\n\nStill processing. Check again in 30 seconds."
|
| 151 |
-
elif status == "FAILED":
|
| 152 |
-
error = data.get("data", {}).get("errorMessage", "Unknown error")
|
| 153 |
-
return f"❌ **Failed:** {error}\n\n**Task ID:** `{task_id}`"
|
| 154 |
else:
|
| 155 |
-
return f"🔄 **Status:** {
|
|
|
|
|
|
|
|
|
|
| 156 |
else:
|
| 157 |
return f"❌ HTTP Error {resp.status_code}:\n{resp.text}"
|
| 158 |
|
|
@@ -278,9 +336,4 @@ if __name__ == "__main__":
|
|
| 278 |
print(f"🔑 SunoKey: {'✅ Set' if SUNO_KEY else '❌ Not set'}")
|
| 279 |
print("🌐 Open your browser to: http://localhost:7860")
|
| 280 |
|
| 281 |
-
|
| 282 |
-
app.launch(
|
| 283 |
-
server_name="0.0.0.0",
|
| 284 |
-
server_port=7860,
|
| 285 |
-
share=False
|
| 286 |
-
)
|
|
|
|
| 82 |
data = resp.json()
|
| 83 |
print(f"Parsed data: {data}")
|
| 84 |
|
| 85 |
+
# Get separation task ID from response
|
| 86 |
separation_task_id = None
|
| 87 |
+
|
| 88 |
+
# Try different response formats
|
| 89 |
+
if data.get("taskId"):
|
| 90 |
+
separation_task_id = data.get("taskId")
|
| 91 |
+
elif data.get("data", {}).get("taskId"):
|
| 92 |
separation_task_id = data["data"]["taskId"]
|
| 93 |
+
elif data.get("code") == 200 and data.get("data", {}).get("taskId"):
|
| 94 |
separation_task_id = data["data"]["taskId"]
|
| 95 |
|
| 96 |
if separation_task_id:
|
| 97 |
+
# Also get musicId if available
|
| 98 |
+
music_id = data.get("musicId") or data.get("data", {}).get("musicId", "N/A")
|
| 99 |
+
|
| 100 |
+
output = f"✅ **Task submitted!**\n\n"
|
| 101 |
+
output += f"**Separation Task ID:** `{separation_task_id}`\n"
|
| 102 |
+
output += f"**Music ID:** `{music_id}`\n\n"
|
| 103 |
+
output += "Check status below using the Separation Task ID."
|
| 104 |
+
return output, separation_task_id
|
| 105 |
else:
|
|
|
|
| 106 |
error_msg = data.get("msg", data.get("error", "Unknown error"))
|
| 107 |
+
return f"❌ No task ID in response: {error_msg}\n\nRaw response:\n```json\n{json.dumps(data, indent=2)}\n```", None
|
| 108 |
else:
|
| 109 |
return f"❌ HTTP Error {resp.status_code}:\n{resp.text}", None
|
| 110 |
|
|
|
|
| 128 |
|
| 129 |
if resp.status_code == 200:
|
| 130 |
data = resp.json()
|
| 131 |
+
print(f"Status data: {json.dumps(data, indent=2)}")
|
| 132 |
+
|
| 133 |
+
# Check API response code
|
| 134 |
+
if data.get("code") != 200:
|
| 135 |
+
error_msg = data.get("msg", "Unknown error")
|
| 136 |
+
return f"❌ API Error: {error_msg}\n\n**Task ID:** `{task_id}`"
|
| 137 |
+
|
| 138 |
+
# Get the main data object
|
| 139 |
+
response_data = data.get("data", {})
|
| 140 |
|
| 141 |
+
# Check success flag
|
| 142 |
+
success_flag = response_data.get("successFlag", "UNKNOWN")
|
| 143 |
+
|
| 144 |
+
if success_flag == "SUCCESS":
|
| 145 |
+
# Get response with download URLs
|
| 146 |
+
result_response = response_data.get("response", {})
|
| 147 |
|
| 148 |
+
if result_response:
|
| 149 |
# Format results
|
| 150 |
+
output = "✅ **Vocal Separation Complete!**\n\n"
|
| 151 |
+
output += f"**Task ID:** `{task_id}`\n"
|
| 152 |
+
output += f"**Music ID:** `{response_data.get('musicId', 'N/A')}`\n\n"
|
| 153 |
+
output += "## 🎵 Download Links\n\n"
|
| 154 |
+
|
| 155 |
+
# Check for URLs (case-insensitive)
|
| 156 |
+
urls_found = False
|
| 157 |
+
|
| 158 |
+
# Vocal URL
|
| 159 |
+
vocal_url = (result_response.get("vocalUrl") or
|
| 160 |
+
result_response.get("vocal_url") or
|
| 161 |
+
result_response.get("vocalURL"))
|
| 162 |
+
if vocal_url:
|
| 163 |
+
output += f"**🎤 Vocals:** [Download MP3]({vocal_url})\n"
|
| 164 |
+
urls_found = True
|
| 165 |
+
|
| 166 |
+
# Instrumental URL
|
| 167 |
+
instrumental_url = (result_response.get("instrumentalUrl") or
|
| 168 |
+
result_response.get("instrumental_url") or
|
| 169 |
+
result_response.get("instrumentalURL"))
|
| 170 |
+
if instrumental_url:
|
| 171 |
+
output += f"**🎵 Instrumental:** [Download MP3]({instrumental_url})\n"
|
| 172 |
+
urls_found = True
|
| 173 |
|
| 174 |
+
# Original URL
|
| 175 |
+
origin_url = (result_response.get("originUrl") or
|
| 176 |
+
result_response.get("origin_url") or
|
| 177 |
+
result_response.get("originURL"))
|
| 178 |
+
if origin_url:
|
| 179 |
+
output += f"**📁 Original:** [Download MP3]({origin_url})\n"
|
| 180 |
+
urls_found = True
|
| 181 |
+
|
| 182 |
+
if not urls_found:
|
| 183 |
+
output += "No download URLs found in response.\n"
|
| 184 |
+
output += f"**Raw response:**\n```json\n{json.dumps(result_response, indent=2)}\n```\n"
|
| 185 |
|
| 186 |
output += f"\n**🔗 Viewer:** [Open in Viewer](https://1hit.no/viewer.php?task_id={task_id})"
|
| 187 |
+
|
| 188 |
+
# Add other fields if they exist
|
| 189 |
+
other_fields = []
|
| 190 |
+
for key, value in result_response.items():
|
| 191 |
+
if value and key.endswith("Url") and key not in ["vocalUrl", "instrumentalUrl", "originUrl"]:
|
| 192 |
+
field_name = key.replace("Url", "").replace("_", " ").title()
|
| 193 |
+
other_fields.append(f"**{field_name}:** {value}")
|
| 194 |
+
|
| 195 |
+
if other_fields:
|
| 196 |
+
output += "\n\n**Other URLs:**\n" + "\n".join(other_fields)
|
| 197 |
+
|
| 198 |
return output
|
| 199 |
else:
|
| 200 |
+
return f"✅ **Processing complete!**\n\n**Task ID:** `{task_id}`\n\nNo download URLs in response yet. Check your callback endpoint or try again in a moment."
|
| 201 |
+
|
| 202 |
+
elif success_flag in ["PENDING", "PROCESSING", "RUNNING"]:
|
| 203 |
+
return f"⏳ **Status:** {success_flag}\n\n**Task ID:** `{task_id}`\n\nStill processing. Check again in 30 seconds."
|
| 204 |
+
|
| 205 |
+
elif success_flag == "FAILED":
|
| 206 |
+
error_msg = response_data.get("errorMessage", "Unknown error")
|
| 207 |
+
return f"❌ **Failed:** {error_msg}\n\n**Task ID:** `{task_id}`"
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
else:
|
| 210 |
+
return f"🔄 **Status:** {success_flag}\n\n**Task ID:** `{task_id}`\n\n**Full response:**\n```json\n{json.dumps(data, indent=2)}\n```"
|
| 211 |
+
|
| 212 |
+
elif resp.status_code == 404:
|
| 213 |
+
return f"❌ Task not found: `{task_id}`\n\nMake sure the Task ID is correct and the separation has started."
|
| 214 |
else:
|
| 215 |
return f"❌ HTTP Error {resp.status_code}:\n{resp.text}"
|
| 216 |
|
|
|
|
| 336 |
print(f"🔑 SunoKey: {'✅ Set' if SUNO_KEY else '❌ Not set'}")
|
| 337 |
print("🌐 Open your browser to: http://localhost:7860")
|
| 338 |
|
| 339 |
+
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|