futurespyhi commited on
Commit
035fdcd
Β·
1 Parent(s): a128360

add GPU processing time for full model

Browse files
Files changed (1) hide show
  1. app.py +80 -23
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=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
@@ -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 update_progress_periodically():
407
- """Update progress periodically to show the process is alive"""
408
- stages = [
409
- (30, "🧠 Stage 1: Generating musical concepts..."),
410
- (45, "🎼 Stage 1: Creating melody patterns..."),
411
- (60, "🎹 Stage 1: Composing harmony structure..."),
412
- (70, "⚑ Starting Stage 2: Refining with 1B model..."),
413
- (80, "🎡 Stage 2: Adding musical details..."),
414
- (85, "🎢 Stage 2: Finalizing composition..."),
415
- (90, "πŸ”Š Decoding to audio format...")
 
416
  ]
417
 
418
- for percent, desc in stages:
419
- time.sleep(15) # Update every 15 seconds
420
- try:
421
- progress(percent/100, desc=desc)
422
- print(f"⏳ {desc}")
423
- except:
424
- break # Stop if main process finished
425
-
426
- # Start progress updates in background
427
- progress_thread = threading.Thread(target=update_progress_periodically, daemon=True)
428
- progress_thread.start()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
 
430
  print(f"πŸš€ Executing command: {' '.join(cmd)}")
431
- result = subprocess.run(cmd, capture_output=True, text=True, timeout=1800) # 30 minutes timeout
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: