Spaces:
Sleeping
Sleeping
futurespyhi
commited on
Commit
Β·
035fdcd
1
Parent(s):
a128360
add GPU processing time for full model
Browse files
app.py
CHANGED
|
@@ -285,7 +285,7 @@ def validate_file_structure():
|
|
| 285 |
print("β
All required files found")
|
| 286 |
return True
|
| 287 |
|
| 288 |
-
@spaces.GPU(duration=
|
| 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
|
|
@@ -403,32 +403,89 @@ def generate_music_spaces(lyrics: str, genre: str, mood: str, progress=gr.Progre
|
|
| 403 |
import threading
|
| 404 |
import time
|
| 405 |
|
| 406 |
-
def
|
| 407 |
-
"""
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
|
|
|
| 416 |
]
|
| 417 |
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
print(f"π Executing command: {' '.join(cmd)}")
|
| 431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
|
| 433 |
# Print stdout and stderr for debugging
|
| 434 |
if result.stdout:
|
|
|
|
| 285 |
print("β
All required files found")
|
| 286 |
return True
|
| 287 |
|
| 288 |
+
@spaces.GPU(duration=900) # Increase GPU timeout to 15 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
|
|
|
|
| 403 |
import threading
|
| 404 |
import time
|
| 405 |
|
| 406 |
+
def parse_output_and_update_progress(process):
|
| 407 |
+
"""Parse subprocess output in real-time and update progress accordingly"""
|
| 408 |
+
stage1_messages = [
|
| 409 |
+
"π§ Stage 1: Generating musical concepts...",
|
| 410 |
+
"πΌ Stage 1: Creating melody patterns...",
|
| 411 |
+
"πΉ Stage 1: Composing harmony structure..."
|
| 412 |
+
]
|
| 413 |
+
stage2_messages = [
|
| 414 |
+
"β‘ Starting Stage 2: Refining with 1B model...",
|
| 415 |
+
"π΅ Stage 2: Adding musical details...",
|
| 416 |
+
"πΆ Stage 2: Finalizing composition..."
|
| 417 |
]
|
| 418 |
|
| 419 |
+
stage1_progress = [0.3, 0.45, 0.6]
|
| 420 |
+
stage2_progress = [0.7, 0.8, 0.85]
|
| 421 |
+
|
| 422 |
+
current_stage = 1
|
| 423 |
+
stage1_step = 0
|
| 424 |
+
stage2_step = 0
|
| 425 |
+
|
| 426 |
+
output_lines = []
|
| 427 |
+
|
| 428 |
+
try:
|
| 429 |
+
while True:
|
| 430 |
+
line = process.stdout.readline()
|
| 431 |
+
if not line:
|
| 432 |
+
break
|
| 433 |
+
|
| 434 |
+
line = line.strip()
|
| 435 |
+
output_lines.append(line)
|
| 436 |
+
print(line) # Still print for debugging
|
| 437 |
+
|
| 438 |
+
# Check for stage transitions based on actual output
|
| 439 |
+
if "Stage 2 inference..." in line:
|
| 440 |
+
current_stage = 2
|
| 441 |
+
stage2_step = 0
|
| 442 |
+
progress(0.7, desc=stage2_messages[0])
|
| 443 |
+
print(f"β³ {stage2_messages[0]}")
|
| 444 |
+
|
| 445 |
+
elif "Stage 2 DONE" in line:
|
| 446 |
+
progress(0.9, desc="π Decoding to audio format...")
|
| 447 |
+
print("β³ π Decoding to audio format...")
|
| 448 |
+
|
| 449 |
+
# Update Stage 1 progress periodically
|
| 450 |
+
elif current_stage == 1 and stage1_step < len(stage1_messages):
|
| 451 |
+
# Update Stage 1 progress every 15 seconds or on specific markers
|
| 452 |
+
if stage1_step < len(stage1_progress):
|
| 453 |
+
progress(stage1_progress[stage1_step], desc=stage1_messages[stage1_step])
|
| 454 |
+
print(f"β³ {stage1_messages[stage1_step]}")
|
| 455 |
+
stage1_step += 1
|
| 456 |
+
|
| 457 |
+
# Update Stage 2 progress periodically
|
| 458 |
+
elif current_stage == 2 and stage2_step < len(stage2_messages) - 1:
|
| 459 |
+
stage2_step += 1
|
| 460 |
+
if stage2_step < len(stage2_progress):
|
| 461 |
+
progress(stage2_progress[stage2_step], desc=stage2_messages[stage2_step])
|
| 462 |
+
print(f"β³ {stage2_messages[stage2_step]}")
|
| 463 |
+
|
| 464 |
+
except Exception as e:
|
| 465 |
+
print(f"Progress parsing error: {e}")
|
| 466 |
+
|
| 467 |
+
return '\n'.join(output_lines)
|
| 468 |
|
| 469 |
print(f"π Executing command: {' '.join(cmd)}")
|
| 470 |
+
|
| 471 |
+
# Use Popen for real-time output processing
|
| 472 |
+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 473 |
+
text=True, bufsize=1, universal_newlines=True)
|
| 474 |
+
|
| 475 |
+
# Parse output in real-time
|
| 476 |
+
stdout_output = parse_output_and_update_progress(process)
|
| 477 |
+
|
| 478 |
+
# Wait for process to complete and get return code
|
| 479 |
+
return_code = process.wait()
|
| 480 |
+
|
| 481 |
+
# Create result object similar to subprocess.run
|
| 482 |
+
class Result:
|
| 483 |
+
def __init__(self, returncode, stdout, stderr=""):
|
| 484 |
+
self.returncode = returncode
|
| 485 |
+
self.stdout = stdout
|
| 486 |
+
self.stderr = stderr
|
| 487 |
+
|
| 488 |
+
result = Result(return_code, stdout_output)
|
| 489 |
|
| 490 |
# Print stdout and stderr for debugging
|
| 491 |
if result.stdout:
|