File size: 4,716 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
# Setup Python 3.11 Environment for AudioForge ML Dependencies
# AudioCraft requires Python 3.11 (doesn't support 3.13)

$Colors = @{
    Red = "Red"
    Green = "Green"
    Yellow = "Yellow"
    Blue = "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 "β•‘    Python 3.11 Setup for ML Dependencies                β•‘" -ForegroundColor Cyan
Write-Host "β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•`n" -ForegroundColor Cyan

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

# Check for Python 3.11
Write-Info "Checking for Python 3.11..."

$python311 = $null
$python311Path = $null

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

# Try direct python3.11
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 {}
}

# Try python -V to check current version
if (-not $python311) {
    try {
        $currentVersion = python --version 2>&1
        if ($currentVersion -match "3\.11") {
            $python311 = "python"
            Write-Success "Current Python is 3.11: $currentVersion"
        } else {
            Write-Warning "Current Python is not 3.11: $currentVersion"
        }
    } catch {}
}

if (-not $python311) {
    Write-Error "Python 3.11 not found!"
    Write-Host ""
    Write-Host "πŸ“‹ To install Python 3.11:" -ForegroundColor Cyan
    Write-Host "1. Download from: https://www.python.org/downloads/release/python-3110/" -ForegroundColor White
    Write-Host "2. Or use Windows Store: Search for 'Python 3.11'" -ForegroundColor White
    Write-Host "3. Or use py launcher: py -3.11 -m pip install --upgrade pip" -ForegroundColor White
    Write-Host ""
    Write-Host "After installing Python 3.11, run this script again." -ForegroundColor Yellow
    exit 1
}

# Create virtual environment
Write-Info "Creating Python 3.11 virtual environment..."
Set-Location $BackendPath

if (Test-Path $VenvPath) {
    Write-Warning "Virtual environment .venv311 already exists"
    $overwrite = Read-Host "Overwrite? (y/N)"
    if ($overwrite -ne "y") {
        Write-Info "Skipping virtual environment creation"
    } else {
        Remove-Item -Recurse -Force $VenvPath
        & $python311 -m venv .venv311
        Write-Success "Virtual environment created"
    }
} else {
    & $python311 -m venv .venv311
    Write-Success "Virtual environment created"
}

# Activate and install dependencies
Write-Info "Installing ML dependencies..."
$activateScript = Join-Path $VenvPath "Scripts\Activate.ps1"

if (-not (Test-Path $activateScript)) {
    Write-Error "Activation script not found: $activateScript"
    exit 1
}

# Install uv first
Write-Info "Installing uv package manager..."
& "$VenvPath\Scripts\python.exe" -m pip install --upgrade pip
& "$VenvPath\Scripts\python.exe" -m pip install uv

# Install ML dependencies
Write-Info "Installing ML dependencies (this may take 5-10 minutes)..."
Write-Warning "This will download ~2GB of files (PyTorch, AudioCraft models)"

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

if ($LASTEXITCODE -eq 0) {
    Write-Success "ML dependencies installed successfully!"
    Write-Host ""
    Write-Host "πŸ“ To use this environment:" -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 ""
} else {
    Write-Error "Failed to install ML dependencies"
    Write-Host "Check the error messages above for details." -ForegroundColor Yellow
    exit 1
}