Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/app/services/music_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,16 @@ def _pad_audio_token(token):
if callback is not None:
callback(95, "Decoding audio...")

# Get codec dtype once for consistency
codec_dtype = getattr(pipeline, 'codec_dtype', torch.float32)

# Lazy codec loading: Load HeartCodec only when needed (for 12GB GPU mode)
lazy_codec = getattr(pipeline, '_lazy_codec', False)
if lazy_codec and pipeline._codec is None:
print("[Lazy Loading] Loading HeartCodec for decoding...", flush=True)
codec_path = getattr(pipeline, '_codec_path', None)
if codec_path:
# Use the same dtype as specified in the pipeline for consistency
codec_dtype = getattr(pipeline, 'codec_dtype', torch.float32)
pipeline._codec = HeartCodec.from_pretrained(
codec_path,
device_map=pipeline.codec_device,
Expand All @@ -842,7 +844,8 @@ def _pad_audio_token(token):
else:
raise RuntimeError("Cannot load HeartCodec: codec_path not available")

frames_for_codec = frames.to(pipeline.codec_device)
# Convert frames to codec device and dtype (important for MPS float16)
frames_for_codec = frames.to(device=pipeline.codec_device, dtype=codec_dtype)
wav = pipeline.codec.detokenize(frames_for_codec)

# Cleanup codec if using lazy loading (free VRAM for next generation)
Expand Down
20 changes: 14 additions & 6 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,25 @@ def run_server():
print("Warning: pywebview not available, falling back to browser")
import webbrowser
webbrowser.open("http://127.0.0.1:8000")
# Keep the server running
while True:
time.sleep(1)
# Keep the server running - wait for user to terminate
print("Server is running. Press Ctrl+C to stop.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nStopping server...")
except Exception as e:
print(f"Error launching window: {e}")
print("Falling back to browser...")
import webbrowser
webbrowser.open("http://127.0.0.1:8000")
# Keep the server running
while True:
time.sleep(1)
# Keep the server running - wait for user to terminate
print("Server is running. Press Ctrl+C to stop.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nStopping server...")

def main():
"""Main entry point."""
Expand Down