Update suno_app.py
Browse files- suno_app.py +26 -15
suno_app.py
CHANGED
|
@@ -154,13 +154,18 @@ def process_music_generation(prompt, style, title, api_key, progress=gr.Progress
|
|
| 154 |
first_music_shown = False
|
| 155 |
music_data_1 = None
|
| 156 |
music_data_2 = None
|
|
|
|
|
|
|
| 157 |
|
| 158 |
while time.time() - start_time < 600: # 最多等待10分钟
|
| 159 |
elapsed = int(time.time() - start_time)
|
| 160 |
progress_value = min(0.2 + (elapsed / 600) * 0.7, 0.9)
|
| 161 |
|
| 162 |
-
#
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
| 164 |
if status == 'FIRST_SUCCESS' and not first_music_shown:
|
| 165 |
# 第一首音乐生成完成
|
| 166 |
progress(progress_value, desc="🎵 First music generated!")
|
|
@@ -196,25 +201,31 @@ def process_music_generation(prompt, style, title, api_key, progress=gr.Progress
|
|
| 196 |
)
|
| 197 |
break
|
| 198 |
|
| 199 |
-
|
| 200 |
-
progress(progress_value, desc=f"⏳ Generating music... ({elapsed}s)")
|
| 201 |
-
|
| 202 |
-
# 实时更新状态 - 只有在第一首音乐还没生成时才显示等待状态
|
| 203 |
if not first_music_shown:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
elif first_music_shown and music_data_1:
|
| 210 |
-
#
|
| 211 |
yield (
|
| 212 |
-
|
| 213 |
-
|
| 214 |
f"✅ First music generated, generating second... (waited {elapsed}s)"
|
| 215 |
)
|
| 216 |
|
| 217 |
-
time.sleep(
|
| 218 |
|
| 219 |
# 超时
|
| 220 |
if time.time() - start_time >= 600:
|
|
|
|
| 154 |
first_music_shown = False
|
| 155 |
music_data_1 = None
|
| 156 |
music_data_2 = None
|
| 157 |
+
last_api_check = 0
|
| 158 |
+
api_check_interval = 8 # API每8秒检查一次
|
| 159 |
|
| 160 |
while time.time() - start_time < 600: # 最多等待10分钟
|
| 161 |
elapsed = int(time.time() - start_time)
|
| 162 |
progress_value = min(0.2 + (elapsed / 600) * 0.7, 0.9)
|
| 163 |
|
| 164 |
+
# 每8秒检查一次API状态,避免频繁请求
|
| 165 |
+
if time.time() - last_api_check >= api_check_interval:
|
| 166 |
+
status, data = check_task_status(task_id, api_key.strip())
|
| 167 |
+
last_api_check = time.time()
|
| 168 |
+
|
| 169 |
if status == 'FIRST_SUCCESS' and not first_music_shown:
|
| 170 |
# 第一首音乐生成完成
|
| 171 |
progress(progress_value, desc="🎵 First music generated!")
|
|
|
|
| 201 |
)
|
| 202 |
break
|
| 203 |
|
| 204 |
+
# 只在状态变化时更新音乐卡片,避免频繁刷新
|
|
|
|
|
|
|
|
|
|
| 205 |
if not first_music_shown:
|
| 206 |
+
# 只在第一次时显示空卡片,之后不再更新
|
| 207 |
+
if elapsed == 1: # 只在第1秒时显示一次
|
| 208 |
+
yield (
|
| 209 |
+
create_music_card(None, 1),
|
| 210 |
+
create_music_card(None, 2),
|
| 211 |
+
f"⏳ Generating music... (waited {elapsed}s)"
|
| 212 |
+
)
|
| 213 |
+
else:
|
| 214 |
+
# 只更新状态文本,不更新音乐卡片
|
| 215 |
+
yield (
|
| 216 |
+
gr.update(), # 保持音乐卡片不变
|
| 217 |
+
gr.update(), # 保持音乐卡片不变
|
| 218 |
+
f"⏳ Generating music... (waited {elapsed}s)"
|
| 219 |
+
)
|
| 220 |
elif first_music_shown and music_data_1:
|
| 221 |
+
# 第一首音乐已生成,只更新状态文本
|
| 222 |
yield (
|
| 223 |
+
gr.update(), # 保持音乐卡片不变
|
| 224 |
+
gr.update(), # 保持音乐卡片不变
|
| 225 |
f"✅ First music generated, generating second... (waited {elapsed}s)"
|
| 226 |
)
|
| 227 |
|
| 228 |
+
time.sleep(1) # 每1秒更新一次状态文本
|
| 229 |
|
| 230 |
# 超时
|
| 231 |
if time.time() - start_time >= 600:
|