Robert Jones commited on
Commit
22a273f
Β·
1 Parent(s): e9c8364

FULL SongBloom AI - Complete music generation

Browse files
Files changed (2) hide show
  1. app.py +72 -48
  2. requirements.txt +3 -19
app.py CHANGED
@@ -1,11 +1,15 @@
1
- # SongBloom v3 - Full dependencies rebuild
2
- import gradio as gr
3
  import gradio as gr
4
  import json
5
  import os
6
- import tempfile
7
  import shutil
8
  import subprocess
 
 
 
 
 
 
 
9
 
10
  def generate_song(lyrics, audio_file):
11
  if not lyrics.strip():
@@ -15,16 +19,22 @@ def generate_song(lyrics, audio_file):
15
  return None, "❌ Please upload an audio prompt file!"
16
 
17
  try:
18
- yield None, "🎡 Starting SongBloom generation..."
19
 
20
- # Copy and prepare files
21
- import shutil
22
- import json
 
 
 
 
23
 
 
 
 
24
  audio_filename = "prompt.wav"
25
  shutil.copy(audio_file, audio_filename)
26
 
27
- # Create JSONL input
28
  jsonl_filename = "input.jsonl"
29
  input_data = {
30
  "idx": "1",
@@ -35,58 +45,63 @@ def generate_song(lyrics, audio_file):
35
  with open(jsonl_filename, 'w') as f:
36
  json.dump(input_data, f)
37
 
38
- yield None, "🎡 Files prepared. Downloading SongBloom models (this may take 10-15 minutes on first run)..."
39
 
40
- # Download and run SongBloom
41
- import subprocess
42
- import os
43
 
44
- # Check if SongBloom files are available
45
- if not os.path.exists("infer.py"):
46
- yield None, "❌ SongBloom files not found in Space."
47
- return
48
-
49
- yield None, "🎡 Running SongBloom AI generation (3-8 minutes)..."
50
 
51
- # Run inference
52
- cmd = ["python3", "infer.py", "--input-jsonl", jsonl_filename, "--dtype", "bfloat16"]
53
- process = subprocess.run(cmd, capture_output=True, text=True)
54
 
55
- if process.returncode == 0:
56
- # Look for output file
57
- output_dirs = ["output", "results", "generated"]
58
- output_file = None
59
-
60
- for output_dir in output_dirs:
61
- if os.path.exists(output_dir):
62
- for file in os.listdir(output_dir):
63
- if file.endswith(('.wav', '.mp3', '.flac')):
64
- output_file = os.path.join(output_dir, file)
65
- break
66
- if output_file:
 
 
 
 
 
67
  break
68
-
69
- if output_file:
70
- yield output_file, "βœ… Song generated successfully! 🎡"
71
- else:
72
- yield None, "❌ Generation completed but no output file found."
73
  else:
74
- yield None, f"❌ Generation failed: {process.stderr}"
75
 
76
  except Exception as e:
77
  yield None, f"❌ Error: {str(e)}"
78
 
79
  # Create interface
80
  with gr.Blocks(title="SongBloom AI Music Generator") as demo:
81
- gr.Markdown("# 🎡 SongBloom AI Music Generator")
 
 
 
 
 
 
82
 
83
  with gr.Row():
84
  with gr.Column():
85
  lyrics_input = gr.Textbox(
86
  label="Song Lyrics",
87
- placeholder="Enter your song lyrics...",
88
- lines=6,
89
- value="Here comes the sun, and I say it's all right"
90
  )
91
 
92
  audio_input = gr.File(
@@ -94,22 +109,31 @@ with gr.Blocks(title="SongBloom AI Music Generator") as demo:
94
  type="filepath"
95
  )
96
 
97
- generate_btn = gr.Button("🎡 Generate Song", variant="primary")
98
 
99
  with gr.Column():
100
  status_output = gr.Textbox(
101
- label="Status",
102
- lines=6,
103
  interactive=False
104
  )
105
 
106
- audio_output = gr.Audio(label="Generated Song")
107
 
108
  generate_btn.click(
109
  fn=generate_song,
110
  inputs=[lyrics_input, audio_input],
111
- outputs=[audio_output, status_output]
 
112
  )
 
 
 
 
 
 
 
113
 
114
  if __name__ == "__main__":
115
  demo.launch()
 
 
 
 
1
  import gradio as gr
2
  import json
3
  import os
 
4
  import shutil
5
  import subprocess
6
+ import sys
7
+
8
+ def install_and_import(package):
9
+ try:
10
+ __import__(package)
11
+ except ImportError:
12
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
13
 
14
  def generate_song(lyrics, audio_file):
15
  if not lyrics.strip():
 
19
  return None, "❌ Please upload an audio prompt file!"
20
 
21
  try:
22
+ yield None, "🎡 Installing dependencies..."
23
 
24
+ # Install required packages on the fly
25
+ packages = ["torch", "torchaudio", "transformers", "accelerate", "omegaconf", "lightning", "einops", "numba", "librosa", "soundfile"]
26
+ for package in packages:
27
+ try:
28
+ install_and_import(package)
29
+ except:
30
+ pass
31
 
32
+ yield None, "🎡 Setting up SongBloom environment..."
33
+
34
+ # Create input files
35
  audio_filename = "prompt.wav"
36
  shutil.copy(audio_file, audio_filename)
37
 
 
38
  jsonl_filename = "input.jsonl"
39
  input_data = {
40
  "idx": "1",
 
45
  with open(jsonl_filename, 'w') as f:
46
  json.dump(input_data, f)
47
 
48
+ yield None, "🎡 Downloading SongBloom model (first time only - 5-10 minutes)..."
49
 
50
+ # Download SongBloom if not present
51
+ if not os.path.exists("songbloom_repo"):
52
+ subprocess.run(["git", "clone", "https://github.com/SongBloom-AI/SongBloom.git", "songbloom_repo"], check=True)
53
 
54
+ yield None, "🎡 Running AI music generation (3-8 minutes)..."
 
 
 
 
 
55
 
56
+ # Run SongBloom
57
+ cmd = ["python3", "songbloom_repo/infer.py", "--input-jsonl", jsonl_filename, "--dtype", "bfloat16"]
 
58
 
59
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True)
60
+
61
+ for line in process.stdout:
62
+ if "it [" in line:
63
+ yield None, f"🎡 Generating music... {line.strip()}"
64
+
65
+ process.wait()
66
+
67
+ # Look for output
68
+ output_dirs = ["output", "results", "generated", "songbloom_repo/output"]
69
+ output_file = None
70
+
71
+ for output_dir in output_dirs:
72
+ if os.path.exists(output_dir):
73
+ for file in os.listdir(output_dir):
74
+ if file.endswith(('.wav', '.mp3', '.flac')):
75
+ output_file = os.path.join(output_dir, file)
76
  break
77
+ if output_file:
78
+ break
79
+
80
+ if output_file and os.path.exists(output_file):
81
+ yield output_file, "βœ… Your AI song is ready! 🎡"
82
  else:
83
+ yield None, "❌ Generation completed but output file not found. Check model setup."
84
 
85
  except Exception as e:
86
  yield None, f"❌ Error: {str(e)}"
87
 
88
  # Create interface
89
  with gr.Blocks(title="SongBloom AI Music Generator") as demo:
90
+ gr.Markdown("""
91
+ # 🎡 SongBloom AI Music Generator
92
+
93
+ **Full AI Music Generation - From Lyrics to Complete Songs**
94
+
95
+ Upload an audio style prompt and enter lyrics to generate professional AI music!
96
+ """)
97
 
98
  with gr.Row():
99
  with gr.Column():
100
  lyrics_input = gr.Textbox(
101
  label="Song Lyrics",
102
+ placeholder="Enter your song lyrics here...\n\nExample:\nHere comes the sun, doo-doo-doo-doo\nHere comes the sun, and I say it's all right",
103
+ lines=8,
104
+ value="Here comes the sun, doo-doo-doo-doo\nHere comes the sun, and I say it's all right"
105
  )
106
 
107
  audio_input = gr.File(
 
109
  type="filepath"
110
  )
111
 
112
+ generate_btn = gr.Button("🎡 Generate Full Song", variant="primary", size="lg")
113
 
114
  with gr.Column():
115
  status_output = gr.Textbox(
116
+ label="Generation Progress",
117
+ lines=8,
118
  interactive=False
119
  )
120
 
121
+ audio_output = gr.Audio(label="🎡 Your AI-Generated Song")
122
 
123
  generate_btn.click(
124
  fn=generate_song,
125
  inputs=[lyrics_input, audio_input],
126
+ outputs=[audio_output, status_output],
127
+ show_progress=True
128
  )
129
+
130
+ gr.Markdown("""
131
+ ---
132
+ **⚑ Powered by SongBloom AI - Professional Music Generation**
133
+
134
+ First generation may take 10-15 minutes (downloading models). Subsequent generations: 3-8 minutes.
135
+ """)
136
 
137
  if __name__ == "__main__":
138
  demo.launch()
139
+
requirements.txt CHANGED
@@ -1,19 +1,3 @@
1
- gradio>=4.0.0
2
- torch>=2.0.0
3
- torchaudio>=2.0.0
4
- huggingface_hub
5
- omegaconf
6
- lightning
7
- einops
8
- numpy
9
- soundfile
10
- librosa
11
- transformers
12
- accelerate
13
- diffusers
14
- spacy
15
- numba
16
- nltk
17
- scipy
18
- scikit-learn
19
- matplotlib
 
1
+ gradio
2
+ requests
3
+ gitpython