directedbykobyperez commited on
Commit
feead2c
路
verified 路
1 Parent(s): a81dd92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -18
app.py CHANGED
@@ -19,7 +19,11 @@ def get_pipeline():
19
  if pipe is None:
20
  from yue2 import YuE2Pipeline
21
  print("Loading YuE2-3B pipeline on GPU...")
22
- pipe = YuE2Pipeline.from_pretrained(REPO, device="cuda" if torch.cuda.is_available() else "cpu")
 
 
 
 
23
  print("Pipeline loaded.")
24
  return pipe
25
 
@@ -30,7 +34,6 @@ def flac_to_mp3(flac_path, mp3_path, bitrate="320k"):
30
  )
31
  return mp3_path
32
 
33
- # 讛-Decorator 讛拽专讬讟讬 砖诪驻注讬诇 讗转 讛-ZeroGPU 讘讝诪谉 讬爪讬专转 讛砖讬专
34
  @spaces.GPU(duration=120)
35
  def generate(style, lyrics, cot, seed, cfg_scale):
36
  pipeline = get_pipeline()
@@ -51,25 +54,85 @@ def generate(style, lyrics, cot, seed, cfg_scale):
51
  song.save(flac_path)
52
  flac_to_mp3(flac_path, mp3_path)
53
 
54
- return flac_path, mp3_path, f"seed={seed} | {os.path.getsize(mp3_path) // 1024}KB MP3 320kbps"
55
 
56
- with gr.Blocks(title="YuE2-3B Music") as demo:
57
- gr.Markdown("# YuE2-3B Music Generator\nFull song (vocals + accompaniment) from a style prompt and lyrics.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  with gr.Row():
59
- with gr.Column():
60
- style = gr.Textbox(label="Style prompt", value="Cyber metal, English, aggressive male vocals, distorted guitars, double-kick drums", lines=3)
61
- lyrics = gr.Textbox(label="Lyrics ([verse]/[chorus] etc.)", value="[verse]\nnothing here but static skies\nwe ride the current till it dies", lines=8)
 
 
 
 
 
 
 
 
62
  with gr.Row():
63
- cot = gr.Radio(["full", "melody", "off"], value="full", label="CoT mode")
64
- seed = gr.Number(label="Seed", value=0, precision=0)
65
- cfg = gr.Number(label="CFG scale (1.0 = default)", value=1.0, precision=2)
66
- btn = gr.Button("Generate song", variant="primary")
67
- with gr.Column():
68
- audio = gr.Audio(label="Play song", type="filepath")
69
- mp3_file = gr.File(label="Download MP3 320kbps")
70
- info = gr.Textbox(label="Info")
71
 
72
- btn.click(fn=generate, inputs=[style, lyrics, cot, seed, cfg], outputs=[audio, mp3_file, info], queue=True)
 
 
 
 
 
 
 
 
 
 
73
 
74
- # 讛专爪讛 转讜讗诪转 Hugging Face Spaces
75
  demo.queue().launch()
 
19
  if pipe is None:
20
  from yue2 import YuE2Pipeline
21
  print("Loading YuE2-3B pipeline on GPU...")
22
+ pipe = YuE2Pipeline.from_pretrained(
23
+ REPO,
24
+ device="cuda" if torch.cuda.is_available() else "cpu",
25
+ trust_remote_code=True
26
+ )
27
  print("Pipeline loaded.")
28
  return pipe
29
 
 
34
  )
35
  return mp3_path
36
 
 
37
  @spaces.GPU(duration=120)
38
  def generate(style, lyrics, cot, seed, cfg_scale):
39
  pipeline = get_pipeline()
 
54
  song.save(flac_path)
55
  flac_to_mp3(flac_path, mp3_path)
56
 
57
+ return flac_path, mp3_path, f"Seed: {seed} | Size: {os.path.getsize(mp3_path) // 1024} KB (MP3 320kbps)"
58
 
59
+ # CSS 诇注讬爪讜讘 讬讜拽专转讬 讘住讙谞讜谉 Dark Theme
60
+ custom_css = """
61
+ body {
62
+ background-color: #0b0f19 !important;
63
+ color: #e2e8f0 !important;
64
+ }
65
+ .gradio-container {
66
+ max-width: 1100px !important;
67
+ margin: 0 auto !important;
68
+ }
69
+ .main-title {
70
+ text-align: center;
71
+ margin-bottom: 20px;
72
+ }
73
+ .main-title h1 {
74
+ font-size: 2.5rem;
75
+ font-weight: 800;
76
+ background: linear-gradient(90deg, #ff4b4b, #6b21a8);
77
+ -webkit-background-clip: text;
78
+ -webkit-text-fill-color: transparent;
79
+ }
80
+ .generate-btn {
81
+ background: linear-gradient(135deg, #ff4b4b 0%, #a855f7 100%) !important;
82
+ border: none !important;
83
+ color: white !important;
84
+ font-size: 1.1rem !important;
85
+ font-weight: bold !important;
86
+ border-radius: 12px !important;
87
+ padding: 12px !important;
88
+ box-shadow: 0 4px 15px rgba(255, 75, 75, 0.3) !important;
89
+ transition: all 0.3s ease !important;
90
+ }
91
+ .generate-btn:hover {
92
+ transform: translateY(-2px);
93
+ box-shadow: 0 6px 20px rgba(255, 75, 75, 0.5) !important;
94
+ }
95
+ """
96
+
97
+ with gr.Blocks(css=custom_css, title="YuE2-3B Music Generator") as demo:
98
+ gr.HTML(
99
+ """
100
+ <div class="main-title">
101
+ <h1>馃幍 YuE2-3B Music Studio</h1>
102
+ <p style="color: #94a3b8; font-size: 1.05rem;">Generate full songs with vocals and accompaniment directly on ZeroGPU</p>
103
+ </div>
104
+ """
105
+ )
106
+
107
  with gr.Row():
108
+ with gr.Column(scale=5):
109
+ style = gr.Textbox(
110
+ label="馃帹 Style Prompt",
111
+ value="Cyber metal, English, aggressive male vocals, distorted guitars, double-kick drums",
112
+ lines=3
113
+ )
114
+ lyrics = gr.Textbox(
115
+ label="馃摐 Lyrics ([verse] / [chorus] structure)",
116
+ value="[verse]\nnothing here but static skies\nwe ride the current till it dies",
117
+ lines=8
118
+ )
119
  with gr.Row():
120
+ cot = gr.Radio(["full", "melody", "off"], value="full", label="CoT Mode")
121
+ seed = gr.Number(label="Seed (0 for Random)", value=0, precision=0)
122
+ cfg = gr.Number(label="CFG Scale", value=1.0, precision=2)
123
+
124
+ btn = gr.Button("馃殌 Generate Song", elem_classes=["generate-btn"])
 
 
 
125
 
126
+ with gr.Column(scale=5):
127
+ audio = gr.Audio(label="馃帶 Generated Song Player", type="filepath")
128
+ mp3_file = gr.File(label="馃摜 Download MP3 (320kbps)")
129
+ info = gr.Textbox(label="鈩癸笍 Generation Info", interactive=False)
130
+
131
+ btn.click(
132
+ fn=generate,
133
+ inputs=[style, lyrics, cot, seed, cfg],
134
+ outputs=[audio, mp3_file, info],
135
+ queue=True
136
+ )
137
 
 
138
  demo.queue().launch()