File size: 6,010 Bytes
09fa60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Install ML Dependencies for AudioForge
# Requires Microsoft Visual C++ Build Tools

$Colors = @{
    Red = "Red"
    Green = "Green"
    Yellow = "Yellow"
    Blue = "Cyan"
    Cyan = "Cyan"
}

function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }
function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }
function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }
function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }

Write-Host "`n╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "β•‘    ML Dependencies Installation Guide                    β•‘" -ForegroundColor Cyan
Write-Host "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•`n" -ForegroundColor Cyan

$ProjectRoot = Split-Path -Parent $PSScriptRoot
$BackendPath = Join-Path $ProjectRoot "backend"
$VenvPath = Join-Path $BackendPath ".venv311"

# Check for Visual C++ Build Tools
Write-Info "Checking for Visual C++ Build Tools..."

$vcToolsFound = $false
$vcToolsPaths = @(
    "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools",
    "C:\Program Files\Microsoft Visual Studio\2022\Community",
    "C:\Program Files\Microsoft Visual Studio\2022\Professional",
    "C:\Program Files\Microsoft Visual Studio\2022\Enterprise"
)

foreach ($path in $vcToolsPaths) {
    if (Test-Path $path) {
        Write-Success "Found Visual Studio at: $path"
        $vcToolsFound = $true
        break
    }
}

# Check for cl.exe (C++ compiler)
try {
    $null = Get-Command cl -ErrorAction Stop
    Write-Success "C++ compiler (cl.exe) found in PATH"
    $vcToolsFound = $true
} catch {
    # Not in PATH, but might still be installed
}

if (-not $vcToolsFound) {
    Write-Warning "Visual C++ Build Tools not detected!"
    Write-Host ""
    Write-Host "πŸ“₯ Please install Visual C++ Build Tools:" -ForegroundColor Cyan
    Write-Host ""
    Write-Host "1. Download from:" -ForegroundColor White
    Write-Host "   https://visualstudio.microsoft.com/visual-cpp-build-tools/" -ForegroundColor Gray
    Write-Host ""
    Write-Host "2. Run the installer and select:" -ForegroundColor White
    Write-Host "   β˜‘ Desktop development with C++" -ForegroundColor Gray
    Write-Host "   β˜‘ C++ build tools" -ForegroundColor Gray
    Write-Host ""
    Write-Host "3. After installation, restart your terminal and run this script again." -ForegroundColor Yellow
    Write-Host ""
    Write-Host "πŸ’‘ Quick download link:" -ForegroundColor Cyan
    Write-Host "   https://aka.ms/vs/17/release/vs_buildtools.exe" -ForegroundColor Gray
    Write-Host ""
    
    $openBrowser = Read-Host "Open download page in browser? (Y/n)"
    if ($openBrowser -ne "n") {
        Start-Process "https://visualstudio.microsoft.com/visual-cpp-build-tools/"
    }
    
    exit 1
}

Write-Success "Visual C++ Build Tools detected!"

# Check Python 3.11
Write-Info "Checking for Python 3.11..."
$python311 = $null

try {
    $version = py -3.11 --version 2>&1
    if ($LASTEXITCODE -eq 0) {
        $python311 = "py -3.11"
        Write-Success "Found Python 3.11: $version"
    }
} catch {}

if (-not $python311) {
    try {
        $version = python3.11 --version 2>&1
        if ($LASTEXITCODE -eq 0) {
            $python311 = "python3.11"
            Write-Success "Found Python 3.11: $version"
        }
    } catch {}
}

if (-not $python311) {
    Write-Error "Python 3.11 not found!"
    Write-Host "Please install Python 3.11 first." -ForegroundColor Yellow
    exit 1
}

# Create/verify virtual environment
Set-Location $BackendPath

if (-not (Test-Path $VenvPath)) {
    Write-Info "Creating Python 3.11 virtual environment..."
    & $python311 -m venv .venv311
    Write-Success "Virtual environment created"
} else {
    Write-Info "Virtual environment already exists"
}

# Install dependencies
Write-Host ""
Write-Info "Installing ML dependencies..."
Write-Warning "This will take 5-10 minutes and download ~2GB of files"
Write-Host ""

# Upgrade pip and install uv
Write-Info "Setting up package manager..."
& "$VenvPath\Scripts\python.exe" -m pip install --upgrade pip --quiet
& "$VenvPath\Scripts\python.exe" -m pip install uv --quiet
Write-Success "Package manager ready"

# Install ML dependencies
Write-Host ""
Write-Info "Installing PyTorch, AudioCraft, and dependencies..."
Write-Host "This may take several minutes...`n" -ForegroundColor Yellow

& "$VenvPath\Scripts\uv.exe" pip install --python "$VenvPath\Scripts\python.exe" -e ".[ml]"

if ($LASTEXITCODE -eq 0) {
    Write-Host ""
    Write-Success "βœ… ML dependencies installed successfully!"
    Write-Host ""
    Write-Host "πŸ“ To use the ML-enabled backend:" -ForegroundColor Cyan
    Write-Host "   cd backend" -ForegroundColor White
    Write-Host "   .venv311\Scripts\Activate.ps1" -ForegroundColor White
    Write-Host "   uvicorn app.main:app --reload" -ForegroundColor White
    Write-Host ""
    Write-Host "🎡 Music generation is now ready!`n" -ForegroundColor Green
    exit 0
} else {
    Write-Host ""
    Write-Error "Installation failed!"
    Write-Host "Check the error messages above for details." -ForegroundColor Yellow
    Write-Host ""
    Write-Host "Common issues:" -ForegroundColor Cyan
    Write-Host "  β€’ Visual C++ Build Tools not properly installed" -ForegroundColor White
    Write-Host "  β€’ Need to restart terminal after installing build tools" -ForegroundColor White
    Write-Host "  β€’ Network issues downloading packages" -ForegroundColor White
    Write-Host ""
    exit 1
}