Spaces:
Running
Running
Phoenixak99
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -328,6 +328,7 @@ def generate_audio(genre, energy_level, tempo, description, duration):
|
|
328 |
progress_placeholder = st.empty()
|
329 |
subscription_info_placeholder = st.empty()
|
330 |
server_message_placeholder = st.empty()
|
|
|
331 |
|
332 |
# Define the subscription tiers information
|
333 |
subscription_info = """
|
@@ -351,17 +352,68 @@ def generate_audio(genre, energy_level, tempo, description, duration):
|
|
351 |
|
352 |
### π **Why Subscribe?**
|
353 |
Premium subscribers enjoy priority access to dedicated servers,
|
354 |
-
significantly reducing wait times
|
355 |
"""
|
356 |
|
357 |
-
# Start
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
subscription_info_placeholder.markdown(subscription_info)
|
364 |
-
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
|
366 |
# Check if the user is logged in
|
367 |
if st.session_state.get("jwt_token") is None:
|
@@ -401,19 +453,10 @@ def generate_audio(genre, energy_level, tempo, description, duration):
|
|
401 |
)
|
402 |
return
|
403 |
|
404 |
-
# Clear initial countdown placeholders
|
405 |
-
status_placeholder.empty()
|
406 |
-
progress_placeholder.empty()
|
407 |
-
subscription_info_placeholder.empty()
|
408 |
-
server_message_placeholder.empty()
|
409 |
-
|
410 |
# Prepare the prompt and payload for the music generation API
|
411 |
prompt = f"Genre: {genre}, Energy Level: {energy_level}, Tempo: {tempo}, Description: {description}"
|
412 |
payload = {"inputs": {"prompt": prompt, "duration": duration}}
|
413 |
|
414 |
-
# Headers for the music generation API
|
415 |
-
api_headers = get_api_headers()
|
416 |
-
|
417 |
# Enhanced retry logic with better feedback
|
418 |
max_retries = 3
|
419 |
retry_delay = 30 # increased initial delay
|
@@ -426,7 +469,7 @@ def generate_audio(genre, energy_level, tempo, description, duration):
|
|
426 |
|
427 |
if response is None:
|
428 |
server_message_placeholder.warning(
|
429 |
-
"π
|
430 |
f"Retrying in {current_delay} seconds... \n\n"
|
431 |
"π‘ Premium subscribers enjoy faster access with dedicated servers!"
|
432 |
)
|
|
|
328 |
progress_placeholder = st.empty()
|
329 |
subscription_info_placeholder = st.empty()
|
330 |
server_message_placeholder = st.empty()
|
331 |
+
stage_message_placeholder = st.empty()
|
332 |
|
333 |
# Define the subscription tiers information
|
334 |
subscription_info = """
|
|
|
352 |
|
353 |
### π **Why Subscribe?**
|
354 |
Premium subscribers enjoy priority access to dedicated servers,
|
355 |
+
significantly reducing wait times from 7 minutes to just 30 seconds!
|
356 |
"""
|
357 |
|
358 |
+
# Start server warmup with an initial request
|
359 |
+
warmup_payload = {"inputs": {"prompt": "warmup", "duration": 1}}
|
360 |
+
api_headers = get_api_headers()
|
361 |
+
|
362 |
+
# Create a thread for the initial warmup request
|
363 |
+
def make_warmup_request():
|
364 |
+
try:
|
365 |
+
return time_post_request(API_URL, headers=api_headers, payload=warmup_payload, timeout=600)
|
366 |
+
except:
|
367 |
+
return None
|
368 |
+
|
369 |
+
warmup_thread = threading.Thread(target=make_warmup_request)
|
370 |
+
warmup_thread.start()
|
371 |
+
|
372 |
+
# Start the countdown while server is warming up
|
373 |
+
start_time = time.time()
|
374 |
+
total_warmup_time = 420 # 7 minutes in seconds
|
375 |
+
|
376 |
+
# Define server initialization stages
|
377 |
+
stages = [
|
378 |
+
{"time": 0, "message": "π Initializing server resources..."},
|
379 |
+
{"time": 60, "message": "βοΈ Loading AI models into memory..."},
|
380 |
+
{"time": 180, "message": "π§ Optimizing model parameters..."},
|
381 |
+
{"time": 300, "message": "π Configuring generation settings..."},
|
382 |
+
{"time": 360, "message": "β¨ Finalizing server preparation..."}
|
383 |
+
]
|
384 |
+
current_stage = 0
|
385 |
+
|
386 |
+
while time.time() - start_time < total_warmup_time and warmup_thread.is_alive():
|
387 |
+
elapsed = time.time() - start_time
|
388 |
+
remaining = total_warmup_time - elapsed
|
389 |
+
progress = elapsed / total_warmup_time
|
390 |
+
|
391 |
+
# Update current stage based on elapsed time
|
392 |
+
while current_stage < len(stages) - 1 and elapsed > stages[current_stage + 1]["time"]:
|
393 |
+
current_stage += 1
|
394 |
+
|
395 |
+
minutes_remaining = int(remaining // 60)
|
396 |
+
seconds_remaining = int(remaining % 60)
|
397 |
+
|
398 |
+
status_placeholder.markdown("### π AI Server Initialization in Progress")
|
399 |
+
progress_placeholder.progress(progress)
|
400 |
+
|
401 |
+
stage_message_placeholder.info(stages[current_stage]["message"])
|
402 |
+
|
403 |
+
server_message_placeholder.warning(
|
404 |
+
f"β³ Estimated time remaining: {minutes_remaining}m {seconds_remaining}s\n\n"
|
405 |
+
f"π΅ Free tier server initialization takes about 7 minutes\n\n"
|
406 |
+
"π‘ Premium users enjoy dramatically faster startup times (30s or less)!"
|
407 |
+
)
|
408 |
+
|
409 |
subscription_info_placeholder.markdown(subscription_info)
|
410 |
+
time.sleep(0.1)
|
411 |
+
|
412 |
+
# Clear initialization messages
|
413 |
+
status_placeholder.empty()
|
414 |
+
progress_placeholder.empty()
|
415 |
+
stage_message_placeholder.empty()
|
416 |
+
server_message_placeholder.empty()
|
417 |
|
418 |
# Check if the user is logged in
|
419 |
if st.session_state.get("jwt_token") is None:
|
|
|
453 |
)
|
454 |
return
|
455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
456 |
# Prepare the prompt and payload for the music generation API
|
457 |
prompt = f"Genre: {genre}, Energy Level: {energy_level}, Tempo: {tempo}, Description: {description}"
|
458 |
payload = {"inputs": {"prompt": prompt, "duration": duration}}
|
459 |
|
|
|
|
|
|
|
460 |
# Enhanced retry logic with better feedback
|
461 |
max_retries = 3
|
462 |
retry_delay = 30 # increased initial delay
|
|
|
469 |
|
470 |
if response is None:
|
471 |
server_message_placeholder.warning(
|
472 |
+
"π Finalizing server preparation. "
|
473 |
f"Retrying in {current_delay} seconds... \n\n"
|
474 |
"π‘ Premium subscribers enjoy faster access with dedicated servers!"
|
475 |
)
|