Spaces:
Running
Running
futurespyhi
commited on
Commit
Β·
e3adaee
1
Parent(s):
ce7990e
Add detailed progress updates and extend timeouts for music generation
Browse files- Increase GPU timeout to 5 minutes for complex generation
- Add background thread for progress updates every 15 seconds
- Show detailed stages: Stage 1 (7B model), Stage 2 (1B model), audio decoding
- Extend subprocess timeout to 30 minutes for safety
- Add generation settings and time estimates in logs
- Improve user feedback during long generation process
app.py
CHANGED
|
@@ -285,7 +285,7 @@ def validate_file_structure():
|
|
| 285 |
print("β
All required files found")
|
| 286 |
return True
|
| 287 |
|
| 288 |
-
@spaces.GPU #
|
| 289 |
def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progress()) -> str:
|
| 290 |
"""
|
| 291 |
Generate music using YuE model with high-performance Spaces configuration
|
|
@@ -373,12 +373,15 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 373 |
if not flash_attn_available:
|
| 374 |
cmd.append("--sdpa")
|
| 375 |
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
-
# Run with generous timeout for high-quality generation
|
| 379 |
print("π΅ Starting high-quality music generation...")
|
|
|
|
|
|
|
| 380 |
print(f"Working directory: {os.getcwd()}")
|
| 381 |
-
print(f"Infer script path: {infer_script_path}")
|
| 382 |
print(f"Command: {' '.join(cmd)}")
|
| 383 |
|
| 384 |
# Change to YuEGP/inference directory for execution
|
|
@@ -388,13 +391,40 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 388 |
try:
|
| 389 |
os.chdir(inference_dir)
|
| 390 |
print(f"Changed to inference directory: {inference_dir}")
|
| 391 |
-
|
| 392 |
-
# Update command to use relative path since we're in the inference directory
|
| 393 |
cmd[1] = "infer.py"
|
| 394 |
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
print(f"π Executing command: {' '.join(cmd)}")
|
| 397 |
-
result = subprocess.run(cmd, capture_output=True, text=True, timeout=
|
| 398 |
|
| 399 |
# Print stdout and stderr for debugging
|
| 400 |
if result.stdout:
|
|
@@ -402,11 +432,11 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 402 |
if result.stderr:
|
| 403 |
print(f"β οΈ Command stderr:\n{result.stderr}")
|
| 404 |
print(f"π Return code: {result.returncode}")
|
|
|
|
| 405 |
finally:
|
| 406 |
-
# Always restore original working directory
|
| 407 |
os.chdir(original_cwd)
|
| 408 |
|
| 409 |
-
progress(0.
|
| 410 |
|
| 411 |
# Clean up input files
|
| 412 |
os.unlink(genre_file_path)
|
|
|
|
| 285 |
print("β
All required files found")
|
| 286 |
return True
|
| 287 |
|
| 288 |
+
@spaces.GPU(duration=300) # Increase GPU timeout to 5 minutes
|
| 289 |
def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progress()) -> str:
|
| 290 |
"""
|
| 291 |
Generate music using YuE model with high-performance Spaces configuration
|
|
|
|
| 373 |
if not flash_attn_available:
|
| 374 |
cmd.append("--sdpa")
|
| 375 |
|
| 376 |
+
# More detailed progress updates
|
| 377 |
+
progress(0.1, desc="π Initializing models...")
|
| 378 |
+
progress(0.15, desc="π Processing lyrics...")
|
| 379 |
+
progress(0.2, desc="π΅ Starting Stage 1 (7B model generation)...")
|
| 380 |
|
|
|
|
| 381 |
print("π΅ Starting high-quality music generation...")
|
| 382 |
+
print(f"π Generation settings: {run_n_segments} segments, {max_new_tokens} tokens, 30s audio")
|
| 383 |
+
print(f"β±οΈ Estimated time: 2-4 minutes for high-quality generation")
|
| 384 |
print(f"Working directory: {os.getcwd()}")
|
|
|
|
| 385 |
print(f"Command: {' '.join(cmd)}")
|
| 386 |
|
| 387 |
# Change to YuEGP/inference directory for execution
|
|
|
|
| 391 |
try:
|
| 392 |
os.chdir(inference_dir)
|
| 393 |
print(f"Changed to inference directory: {inference_dir}")
|
|
|
|
|
|
|
| 394 |
cmd[1] = "infer.py"
|
| 395 |
|
| 396 |
+
progress(0.25, desc="π₯ Stage 1: Running 7B parameter model...")
|
| 397 |
+
|
| 398 |
+
# Start the subprocess
|
| 399 |
+
import threading
|
| 400 |
+
import time
|
| 401 |
+
|
| 402 |
+
def update_progress_periodically():
|
| 403 |
+
"""Update progress periodically to show the process is alive"""
|
| 404 |
+
stages = [
|
| 405 |
+
(30, "π§ Stage 1: Generating musical concepts..."),
|
| 406 |
+
(45, "πΌ Stage 1: Creating melody patterns..."),
|
| 407 |
+
(60, "πΉ Stage 1: Composing harmony structure..."),
|
| 408 |
+
(70, "β‘ Starting Stage 2: Refining with 1B model..."),
|
| 409 |
+
(80, "π΅ Stage 2: Adding musical details..."),
|
| 410 |
+
(85, "πΆ Stage 2: Finalizing composition..."),
|
| 411 |
+
(90, "π Decoding to audio format...")
|
| 412 |
+
]
|
| 413 |
+
|
| 414 |
+
for percent, desc in stages:
|
| 415 |
+
time.sleep(15) # Update every 15 seconds
|
| 416 |
+
try:
|
| 417 |
+
progress(percent/100, desc=desc)
|
| 418 |
+
print(f"β³ {desc}")
|
| 419 |
+
except:
|
| 420 |
+
break # Stop if main process finished
|
| 421 |
+
|
| 422 |
+
# Start progress updates in background
|
| 423 |
+
progress_thread = threading.Thread(target=update_progress_periodically, daemon=True)
|
| 424 |
+
progress_thread.start()
|
| 425 |
+
|
| 426 |
print(f"π Executing command: {' '.join(cmd)}")
|
| 427 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=1800) # 30 minutes timeout
|
| 428 |
|
| 429 |
# Print stdout and stderr for debugging
|
| 430 |
if result.stdout:
|
|
|
|
| 432 |
if result.stderr:
|
| 433 |
print(f"β οΈ Command stderr:\n{result.stderr}")
|
| 434 |
print(f"π Return code: {result.returncode}")
|
| 435 |
+
|
| 436 |
finally:
|
|
|
|
| 437 |
os.chdir(original_cwd)
|
| 438 |
|
| 439 |
+
progress(0.95, desc="π Processing completed, finalizing output...")
|
| 440 |
|
| 441 |
# Clean up input files
|
| 442 |
os.unlink(genre_file_path)
|