File size: 4,945 Bytes
dcf0937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
ο»Ώ# Safe Dependency Installation Script for Windows
# Handles problematic packages like flash-attn carefully

Write-Host "πŸš€ OmniAvatar Dependency Installation" -ForegroundColor Green
Write-Host "====================================" -ForegroundColor Green

# Function to run pip command safely
function Install-Package {
    param(
        [string[]]$Command,
        [string]$Description,
        [bool]$Optional = $false
    )
    
    Write-Host "πŸ”„ $Description" -ForegroundColor Yellow
    try {
        $result = & $Command[0] $Command[1..$Command.Length]
        if ($LASTEXITCODE -eq 0) {
            Write-Host "βœ… $Description - Success" -ForegroundColor Green
            return $true
        } else {
            throw "Command failed with exit code $LASTEXITCODE"
        }
    } catch {
        if ($Optional) {
            Write-Host "⚠️ $Description - Failed (optional): $($_.Exception.Message)" -ForegroundColor Yellow
            return $false
        } else {
            Write-Host "❌ $Description - Failed: $($_.Exception.Message)" -ForegroundColor Red
            throw
        }
    }
}

try {
    # Step 1: Upgrade pip and essential tools
    Install-Package -Command @("python", "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel", "packaging") -Description "Upgrading pip and build tools"
    
    # Step 2: Install PyTorch with CUDA support (if available)
    Write-Host "πŸ“¦ Installing PyTorch..." -ForegroundColor Cyan
    try {
        Install-Package -Command @("python", "-m", "pip", "install", "torch", "torchvision", "torchaudio", "--index-url", "https://download.pytorch.org/whl/cu124") -Description "Installing PyTorch with CUDA support"
    } catch {
        Write-Host "⚠️ CUDA PyTorch failed, installing CPU version" -ForegroundColor Yellow
        Install-Package -Command @("python", "-m", "pip", "install", "torch", "torchvision", "torchaudio") -Description "Installing PyTorch CPU version"
    }
    
    # Step 3: Install main requirements
    Install-Package -Command @("python", "-m", "pip", "install", "-r", "requirements.txt") -Description "Installing main requirements"
    
    # Step 4: Try optional performance packages
    Write-Host "🎯 Installing optional performance packages..." -ForegroundColor Cyan
    
    # Try xformers
    Install-Package -Command @("python", "-m", "pip", "install", "xformers") -Description "Installing xformers (memory efficient attention)" -Optional $true
    
    # Flash-attn is often problematic, so we'll skip it by default
    Write-Host "ℹ️ Skipping flash-attn installation (often problematic on Windows)" -ForegroundColor Blue
    Write-Host "πŸ’‘ You can try installing it later with: pip install flash-attn --no-build-isolation" -ForegroundColor Blue
    
    # Step 5: Verify installation
    Write-Host "πŸ” Verifying installation..." -ForegroundColor Cyan
    
    python -c @"
import sys
try:
    import torch
    import transformers
    import gradio
    import fastapi
    
    print(f'βœ… PyTorch: {torch.__version__}')
    print(f'βœ… Transformers: {transformers.__version__}')
    print(f'βœ… Gradio: {gradio.__version__}')
    
    if torch.cuda.is_available():
        print(f'βœ… CUDA: {torch.version.cuda}')
        print(f'βœ… GPU Count: {torch.cuda.device_count()}')
    else:
        print('ℹ️ CUDA not available - will use CPU')
    
    # Check optional packages
    try:
        import xformers
        print(f'βœ… xformers: {xformers.__version__}')
    except ImportError:
        print('ℹ️ xformers not available (optional)')
    
    try:
        import flash_attn
        print('βœ… flash_attn: Available')
    except ImportError:
        print('ℹ️ flash_attn not available (optional)')
    
    print('πŸŽ‰ Installation verification successful!')
    
except ImportError as e:
    print(f'❌ Installation verification failed: {e}')
    sys.exit(1)
"@
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host ""
        Write-Host "πŸŽ‰ Installation completed successfully!" -ForegroundColor Green
        Write-Host ""
        Write-Host "πŸ’‘ Next steps:" -ForegroundColor Yellow
        Write-Host "1. Download models: .\setup_omniavatar.ps1" -ForegroundColor White
        Write-Host "2. Start the app: python app.py" -ForegroundColor White
        Write-Host ""
    } else {
        throw "Installation verification failed"
    }
    
} catch {
    Write-Host ""
    Write-Host "❌ Installation failed: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host ""
    Write-Host "πŸ’‘ Troubleshooting tips:" -ForegroundColor Yellow
    Write-Host "1. Make sure Python 3.8+ is installed" -ForegroundColor White
    Write-Host "2. Try running in a virtual environment" -ForegroundColor White
    Write-Host "3. Check your internet connection" -ForegroundColor White
    Write-Host "4. For GPU support, ensure CUDA is properly installed" -ForegroundColor White
    exit 1
}