ajayarora1235 commited on
Commit
4162802
1 Parent(s): 2638861

fix suno bugs, link bugs

Browse files
Files changed (2) hide show
  1. chat.py +17 -3
  2. suno.py +105 -16
chat.py CHANGED
@@ -358,7 +358,12 @@ def model_chat(genre_input, query: Optional[str], history: Optional[History], me
358
  yield '', new_history, new_messages, "", "", "", clips_to_continue, None, generated_audios, ["merge snippets", "continue to next section"]
359
 
360
  else:
361
- updated_clip_id = updated_clip_url.split("https://audiopipe.suno.ai/?item_id=")[1]
 
 
 
 
 
362
 
363
  #pass this info in new tool and assistant message
364
  tool_message = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'updated clip id: {updated_clip_id}\nupdated lyrics: {updated_lyrics}\nupdated clips path: {clips_list}'}
@@ -423,11 +428,20 @@ def model_chat(genre_input, query: Optional[str], history: Optional[History], me
423
  if snippet_clip_to_continue_from not in [None, ""]:
424
  updated_clip_url = "still streaming"
425
  while "still streaming" in updated_clip_url:
426
- updated_clip_url, updated_lyrics, updated_tags, clips_list = concat_snippets(song_link.split("https://audiopipe.suno.ai/?item_id=")[1])
 
 
 
 
427
  else:
428
  updated_clip_url, updated_lyrics, clips_list = song_link, remaining_lyrics, []
429
  ## YIELD UPDATED CLIP URL, LYRICS, AND CLIPS LIST
430
- updated_clip_id = updated_clip_url.split("https://audiopipe.suno.ai/?item_id=")[1]
 
 
 
 
 
431
 
432
  #tool and assistant message
433
  tool_message = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'updated clip id: {updated_clip_id}\nupdated lyrics: {updated_lyrics}\nupdated clips path: {clips_list}'}
 
358
  yield '', new_history, new_messages, "", "", "", clips_to_continue, None, generated_audios, ["merge snippets", "continue to next section"]
359
 
360
  else:
361
+ if "https://audiopipe.suno.ai/?item_id=" in updated_clip_url:
362
+ updated_clip_id = updated_clip_url.split("https://audiopipe.suno.ai/?item_id=")[1]
363
+ elif "https://cdn1.suno.ai/" in updated_clip_url:
364
+ updated_clip_id = updated_clip_url.split("https://cdn1.suno.ai/")[1].split(".mp3")[0]
365
+ else:
366
+ updated_clip_id = "unknown"
367
 
368
  #pass this info in new tool and assistant message
369
  tool_message = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'updated clip id: {updated_clip_id}\nupdated lyrics: {updated_lyrics}\nupdated clips path: {clips_list}'}
 
428
  if snippet_clip_to_continue_from not in [None, ""]:
429
  updated_clip_url = "still streaming"
430
  while "still streaming" in updated_clip_url:
431
+ if "https://audiopipe.suno.ai/?item_id=" in song_link:
432
+ clip_id = song_link.split("https://audiopipe.suno.ai/?item_id=")[1]
433
+ else:
434
+ clip_id = updated_clip_url.split("https://cdn1.suno.ai/")[1].split(".mp3")[0]
435
+ updated_clip_url, updated_lyrics, updated_tags, clips_list = concat_snippets(clip_id)
436
  else:
437
  updated_clip_url, updated_lyrics, clips_list = song_link, remaining_lyrics, []
438
  ## YIELD UPDATED CLIP URL, LYRICS, AND CLIPS LIST
439
+ if "https://audiopipe.suno.ai/?item_id=" in updated_clip_url:
440
+ updated_clip_id = updated_clip_url.split("https://audiopipe.suno.ai/?item_id=")[1]
441
+ elif "https://cdn1.suno.ai/" in updated_clip_url:
442
+ updated_clip_id = updated_clip_url.split("https://cdn1.suno.ai/")[1].split(".mp3")[0]
443
+ else:
444
+ updated_clip_id = "unknown"
445
 
446
  #tool and assistant message
447
  tool_message = {'role': 'tool', 'tool_call_id': tool_call_id, 'name': tool_function_name, 'content': f'updated clip id: {updated_clip_id}\nupdated lyrics: {updated_lyrics}\nupdated clips path: {clips_list}'}
suno.py CHANGED
@@ -63,17 +63,33 @@ def generate_song(tags, prompt, save_path, clip_id=None, continue_at=30):
63
  print("No data in response, retrying", response_data)
64
  time.sleep(2)
65
  continue
66
- elif response_data[0]["status"] == 'streaming':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  return "Snippet to extend is still streaming, please wait to request later."
68
- if response_data[0]["status"] == 'complete':
69
  break
70
  else:
71
  time.sleep(8)
72
  continue
73
 
74
-
75
-
76
-
77
  response = requests.post(api_endpoint_submit, json=data) #,headers=headers)
78
  response_data = response.json()
79
 
@@ -110,12 +126,33 @@ def generate_song(tags, prompt, save_path, clip_id=None, continue_at=30):
110
  while True:
111
  response = requests.get(api_endpoint_info + song_id, headers=headers)
112
  response_data = response.json()
 
113
  if response.status_code != 200:
114
  print("No data in response, retrying", response_data)
115
  time.sleep(2)
116
  continue
117
  # print("Got response", response_data)
118
- if response_data[0]["status"] == 'streaming':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  break
120
  else:
121
  time.sleep(2)
@@ -123,8 +160,8 @@ def generate_song(tags, prompt, save_path, clip_id=None, continue_at=30):
123
  # if time.time() - startTime > 300:
124
  # raise Exception("Timeout while waiting for song completion")
125
 
126
- print("Got song", response_data[0]["audio_url"])
127
- url = response_data[0]["audio_url"]
128
 
129
  return url
130
 
@@ -133,6 +170,7 @@ def concat_snippets(clip_id):
133
  feed_url = api_endpoint_info + clip_id
134
 
135
  while True:
 
136
  response = requests.get(feed_url, headers=headers)
137
  response_data = response.json()
138
  if response.status_code != 200:
@@ -140,15 +178,25 @@ def concat_snippets(clip_id):
140
  time.sleep(2)
141
  continue
142
  if isinstance(response_data, list):
 
 
 
143
  status = response_data[0]["status"]
144
- else:
 
 
 
145
  status = response_data["status"]
 
 
 
146
 
147
  if status == 'streaming':
148
  return "Song is still streaming, please wait to request later.", None, None, []
149
  if status == 'complete':
150
  break
151
  else:
 
152
  time.sleep(8)
153
  continue
154
 
@@ -177,8 +225,29 @@ def concat_snippets(clip_id):
177
  print("No data in response, retrying", response_data)
178
  time.sleep(2)
179
  continue
180
- # print("Got response", response_data)
181
- if response_data[0]["status"] == 'streaming' or response_data[0]["audio_url"] != "" or response_data[0]["status"] == 'complete':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  break
183
  else:
184
  time.sleep(2)
@@ -186,8 +255,8 @@ def concat_snippets(clip_id):
186
  # if time.time() - startTime > 300:
187
  # raise Exception("Timeout while waiting for song completion")
188
 
189
- print("Got song", response_data[0]["audio_url"])
190
- url = response_data[0]["audio_url"]
191
 
192
  return url, lyrics, tags, concatenated_clips
193
 
@@ -204,11 +273,31 @@ def update_song_links(generated_audios):
204
  if response.status_code != 200:
205
  print("No data in response, retrying", response_data)
206
  continue
207
- elif response_data[0]["status"] == 'streaming':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  print("still streaming, update later")
209
  continue
210
- if response_data[0]["status"] == 'complete':
211
- updated_clip_path = response_data[0]["audio_url"]
212
  print(updated_clip_path)
213
  updated_generated_audios[i] = (updated_clip_path, lyrics, instrumental, title, "complete")
214
 
 
63
  print("No data in response, retrying", response_data)
64
  time.sleep(2)
65
  continue
66
+
67
+ # Check if response_data is a list or a dictionary
68
+ elif isinstance(response_data, list):
69
+ if len(response_data) == 0 or "status" not in response_data[0]:
70
+ print("Invalid response data, update later")
71
+ time.sleep(2)
72
+ continue
73
+ status = response_data[0]["status"]
74
+ elif isinstance(response_data, dict):
75
+ if "status" not in response_data:
76
+ print("Invalid response data, update later")
77
+ time.sleep(2)
78
+ continue
79
+ status = response_data["status"]
80
+ else:
81
+ print("Unexpected response format, update later")
82
+ time.sleep(2)
83
+ continue
84
+
85
+ if status == 'streaming':
86
  return "Snippet to extend is still streaming, please wait to request later."
87
+ if status == 'complete':
88
  break
89
  else:
90
  time.sleep(8)
91
  continue
92
 
 
 
 
93
  response = requests.post(api_endpoint_submit, json=data) #,headers=headers)
94
  response_data = response.json()
95
 
 
126
  while True:
127
  response = requests.get(api_endpoint_info + song_id, headers=headers)
128
  response_data = response.json()
129
+ status = ""
130
  if response.status_code != 200:
131
  print("No data in response, retrying", response_data)
132
  time.sleep(2)
133
  continue
134
  # print("Got response", response_data)
135
+ # Check if response_data is a list or a dictionary
136
+ if isinstance(response_data, list):
137
+ if len(response_data) == 0 or "status" not in response_data[0]:
138
+ print("Invalid response data, update later")
139
+ time.sleep(2)
140
+ continue
141
+ status = response_data[0]["status"]
142
+ audio_url = response_data[0].get("audio_url", "")
143
+ elif isinstance(response_data, dict):
144
+ if "status" not in response_data:
145
+ print("Invalid response data, update later")
146
+ time.sleep(2)
147
+ continue
148
+ status = response_data["status"]
149
+ audio_url = response_data.get("audio_url", "")
150
+ else:
151
+ print("Unexpected response format, update later")
152
+ time.sleep(2)
153
+ continue
154
+
155
+ if status == 'streaming':
156
  break
157
  else:
158
  time.sleep(2)
 
160
  # if time.time() - startTime > 300:
161
  # raise Exception("Timeout while waiting for song completion")
162
 
163
+ print("Got song", audio_url)
164
+ url = audio_url
165
 
166
  return url
167
 
 
170
  feed_url = api_endpoint_info + clip_id
171
 
172
  while True:
173
+ status = ""
174
  response = requests.get(feed_url, headers=headers)
175
  response_data = response.json()
176
  if response.status_code != 200:
 
178
  time.sleep(2)
179
  continue
180
  if isinstance(response_data, list):
181
+ if len(response_data) == 0 or "status" not in response_data[0]:
182
+ print("Invalid list response data, update later")
183
+ continue
184
  status = response_data[0]["status"]
185
+ elif isinstance(response_data, dict):
186
+ if "status" not in response_data:
187
+ print("Invalid dictionary response data, update later")
188
+ continue
189
  status = response_data["status"]
190
+ else:
191
+ print("Unexpected response format, update later")
192
+ continue
193
 
194
  if status == 'streaming':
195
  return "Song is still streaming, please wait to request later.", None, None, []
196
  if status == 'complete':
197
  break
198
  else:
199
+ print("Streaming status couldn't be retrieved, response_data was ", response_data)
200
  time.sleep(8)
201
  continue
202
 
 
225
  print("No data in response, retrying", response_data)
226
  time.sleep(2)
227
  continue
228
+ print("Got concat snippet response", response_data)
229
+
230
+ # Check if response_data is a list or a dictionary
231
+ if isinstance(response_data, list):
232
+ if len(response_data) == 0 or "status" not in response_data[0]:
233
+ print("Invalid response data, update later")
234
+ time.sleep(2)
235
+ continue
236
+ status = response_data[0]["status"]
237
+ audio_url = response_data[0].get("audio_url", "")
238
+ elif isinstance(response_data, dict):
239
+ if "status" not in response_data:
240
+ print("Invalid response data, update later")
241
+ time.sleep(2)
242
+ continue
243
+ status = response_data["status"]
244
+ audio_url = response_data.get("audio_url", "")
245
+ else:
246
+ print("Unexpected response format, update later")
247
+ time.sleep(2)
248
+ continue
249
+
250
+ if status == 'streaming' or audio_url != "" or status == 'complete':
251
  break
252
  else:
253
  time.sleep(2)
 
255
  # if time.time() - startTime > 300:
256
  # raise Exception("Timeout while waiting for song completion")
257
 
258
+ print("Got song", audio_url)
259
+ url = audio_url
260
 
261
  return url, lyrics, tags, concatenated_clips
262
 
 
273
  if response.status_code != 200:
274
  print("No data in response, retrying", response_data)
275
  continue
276
+
277
+ # Check if response_data is a list or a dictionary
278
+ status = ""
279
+ audio_url = ""
280
+ if isinstance(response_data, list):
281
+ if len(response_data) == 0 or "status" not in response_data[0]:
282
+ print("Invalid list response data, update later")
283
+ continue
284
+ status = response_data[0]["status"]
285
+ audio_url = response_data[0].get("audio_url", "")
286
+ elif isinstance(response_data, dict):
287
+ if "status" not in response_data:
288
+ print("Invalid dictionary response data, update later")
289
+ continue
290
+ status = response_data["status"]
291
+ audio_url = response_data.get("audio_url", "")
292
+ else:
293
+ print("Unexpected response format, update later")
294
+ continue
295
+
296
+ if status == 'streaming':
297
  print("still streaming, update later")
298
  continue
299
+ if status == 'complete' and audio_url != "":
300
+ updated_clip_path = audio_url
301
  print(updated_clip_path)
302
  updated_generated_audios[i] = (updated_clip_path, lyrics, instrumental, title, "complete")
303