forked from GreyDGL/MusicAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·387 lines (321 loc) · 10.4 KB
/
install.sh
File metadata and controls
executable file
·387 lines (321 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/bin/bash
# MusicGen AI Installation Script
# Supports macOS, Linux, and Windows (via WSL/Git Bash)
# Version 1.0
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print colored output
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
print_info "Detected macOS"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
print_info "Detected Linux"
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
OS="windows"
print_info "Detected Windows"
else
print_error "Unsupported operating system: $OSTYPE"
exit 1
fi
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check Python version
check_python() {
print_info "Checking Python installation..."
if command_exists python3; then
PYTHON_CMD="python3"
elif command_exists python; then
PYTHON_CMD="python"
else
print_error "Python is not installed. Please install Python 3.8 or higher."
if [[ "$OS" == "macos" ]]; then
print_info "Install Python using Homebrew: brew install python3"
elif [[ "$OS" == "linux" ]]; then
print_info "Install Python using: sudo apt-get install python3 python3-pip (Ubuntu/Debian)"
print_info "Or: sudo yum install python3 python3-pip (CentOS/RHEL)"
elif [[ "$OS" == "windows" ]]; then
print_info "Download Python from: https://www.python.org/downloads/"
fi
exit 1
fi
# Check Python version
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | awk '{print $2}')
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
if [[ $PYTHON_MAJOR -lt 3 ]] || [[ $PYTHON_MAJOR -eq 3 && $PYTHON_MINOR -lt 8 ]]; then
print_error "Python 3.8 or higher is required. Current version: $PYTHON_VERSION"
exit 1
fi
print_success "Python $PYTHON_VERSION found"
}
# Check pip
check_pip() {
print_info "Checking pip installation..."
if ! $PYTHON_CMD -m pip --version >/dev/null 2>&1; then
print_warning "pip not found. Installing pip..."
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$PYTHON_CMD get-pip.py
rm get-pip.py
fi
print_success "pip is installed"
}
# Check system dependencies
check_dependencies() {
print_info "Checking system dependencies..."
# Check for ffmpeg (required for audio processing)
if ! command_exists ffmpeg; then
print_warning "ffmpeg not found. Installing ffmpeg..."
if [[ "$OS" == "macos" ]]; then
if command_exists brew; then
brew install ffmpeg
else
print_error "Homebrew not found. Please install Homebrew first: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
exit 1
fi
elif [[ "$OS" == "linux" ]]; then
if command_exists apt-get; then
sudo apt-get update && sudo apt-get install -y ffmpeg
elif command_exists yum; then
sudo yum install -y ffmpeg
else
print_warning "Please install ffmpeg manually for your Linux distribution"
fi
elif [[ "$OS" == "windows" ]]; then
print_warning "Please download and install ffmpeg from: https://ffmpeg.org/download.html"
print_warning "Add ffmpeg to your PATH environment variable"
fi
else
print_success "ffmpeg is installed"
fi
# Check for git (optional but recommended)
if ! command_exists git; then
print_warning "git not found. Git is recommended for version control."
else
print_success "git is installed"
fi
}
# Create virtual environment
create_venv() {
print_info "Creating Python virtual environment..."
if [ -d ".venv" ]; then
print_warning "Virtual environment already exists. Removing old environment..."
rm -rf .venv
fi
$PYTHON_CMD -m venv .venv
# Activate virtual environment
if [[ "$OS" == "windows" ]]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
print_success "Virtual environment created and activated"
}
# Upgrade pip and install wheel
upgrade_pip() {
print_info "Upgrading pip and installing wheel..."
pip install --upgrade pip wheel setuptools
print_success "pip, wheel, and setuptools upgraded"
}
# Install PyTorch with appropriate backend
install_pytorch() {
print_info "Installing PyTorch..."
if [[ "$OS" == "macos" ]]; then
# Check if Apple Silicon
if [[ $(uname -m) == "arm64" ]]; then
print_info "Detected Apple Silicon Mac. Installing PyTorch with MPS support..."
pip install torch==2.4.1 torchaudio==2.4.1
else
print_info "Detected Intel Mac. Installing PyTorch for CPU..."
pip install torch==2.4.1 torchaudio==2.4.1
fi
elif [[ "$OS" == "linux" ]]; then
# Check for NVIDIA GPU
if command_exists nvidia-smi; then
print_info "NVIDIA GPU detected. Installing PyTorch with CUDA support..."
pip install torch==2.4.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu121
else
print_info "No NVIDIA GPU detected. Installing PyTorch for CPU..."
pip install torch==2.4.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cpu
fi
else
print_info "Installing PyTorch for CPU..."
pip install torch==2.4.1 torchaudio==2.4.1
fi
print_success "PyTorch installed successfully"
}
# Install Python dependencies
install_dependencies() {
print_info "Installing Python dependencies..."
# Install main requirements
print_info "Installing Flask and core dependencies..."
pip install -r requirements.txt
# Install MusicGen requirements (excluding torch as we already installed it)
print_info "Installing MusicGen dependencies..."
pip install transformers==4.44.2
pip install scipy==1.14.0
pip install accelerate==0.33.0
# Install xformers if supported (skip on Windows and older systems)
if [[ "$OS" != "windows" ]]; then
print_info "Attempting to install xformers for performance optimization..."
pip install xformers==0.0.27.post2 || print_warning "xformers installation failed. Continuing without it (optional optimization)."
fi
# Install datasets with audio support
pip install datasets[audio]
print_success "All Python dependencies installed"
}
# Initialize database
init_database() {
print_info "Initializing database..."
$PYTHON_CMD -c "
from app import app, db
with app.app_context():
db.create_all()
print('Database initialized successfully')
"
print_success "Database initialized"
}
# Create necessary directories
create_directories() {
print_info "Creating necessary directories..."
mkdir -p music
mkdir -p instance
mkdir -p logs
print_success "Directories created"
}
# Test installation
test_installation() {
print_info "Testing installation..."
# Test imports
$PYTHON_CMD -c "
import torch
import torchaudio
import transformers
import flask
import librosa
import numpy
print('All imports successful!')
# Check PyTorch device
if torch.cuda.is_available():
print(f'CUDA available: {torch.cuda.get_device_name(0)}')
elif torch.backends.mps.is_available():
print('MPS (Metal Performance Shaders) available for Apple Silicon')
else:
print('Using CPU for computation')
" || {
print_error "Installation test failed. Some modules could not be imported."
exit 1
}
print_success "Installation test passed"
}
# Create start script
create_start_script() {
print_info "Creating start script..."
cat > start.sh << 'EOF'
#!/bin/bash
# MusicGen AI Start Script
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}Starting MusicGen AI Application...${NC}"
# Activate virtual environment
if [ -f ".venv/bin/activate" ]; then
source .venv/bin/activate
elif [ -f ".venv/Scripts/activate" ]; then
source .venv/Scripts/activate
else
echo "Virtual environment not found. Please run install.sh first."
exit 1
fi
# Start the application
echo -e "${GREEN}Starting Flask application on http://localhost:8080${NC}"
python app.py
EOF
chmod +x start.sh
print_success "Start script created (./start.sh)"
}
# Create stop script
create_stop_script() {
print_info "Creating stop script..."
cat > stop.sh << 'EOF'
#!/bin/bash
# MusicGen AI Stop Script
echo "Stopping MusicGen AI Application..."
# Find and kill the Flask process
if pgrep -f "python app.py" > /dev/null; then
pkill -f "python app.py"
echo "Application stopped successfully"
else
echo "Application is not running"
fi
EOF
chmod +x stop.sh
print_success "Stop script created (./stop.sh)"
}
# Main installation flow
main() {
echo ""
echo "========================================="
echo " MusicGen AI Installation Script"
echo "========================================="
echo ""
# Check if we're in the right directory
if [ ! -f "app.py" ]; then
print_error "app.py not found. Please run this script from the MusicGen project directory."
exit 1
fi
detect_os
check_python
check_pip
check_dependencies
create_venv
upgrade_pip
install_pytorch
install_dependencies
create_directories
init_database
test_installation
create_start_script
create_stop_script
echo ""
echo "========================================="
echo -e "${GREEN} Installation Complete!${NC}"
echo "========================================="
echo ""
print_info "To start the application, run:"
echo " ./start.sh"
echo ""
print_info "To stop the application, run:"
echo " ./stop.sh"
echo ""
print_info "Access the application at:"
echo " http://localhost:8080"
echo ""
print_warning "First music generation will download the model (~2GB)"
echo ""
}
# Run main function
main