-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmake_pyinstaller_image.ps1
More file actions
104 lines (90 loc) · 3.06 KB
/
make_pyinstaller_image.ps1
File metadata and controls
104 lines (90 loc) · 3.06 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
<#
.SYNOPSIS
Build a PyInstaller executable for PhotoMap on Windows.
.DESCRIPTION
Usage: .\make_pyinstaller_image.ps1 [cpu|cu121|cu118|cu124|cu129|...]
- cpu : Install CPU-only PyTorch (default)
- cuXXX : Install CUDA-enabled PyTorch (e.g., cu121 for CUDA 12.1)
#>
param(
[string]$TorchVariant = "cpu"
)
function Show-Usage {
Write-Host "Usage: .\make_pyinstaller_image.ps1 [cpu|cu121|cu118|cu124|cu129|...]"
Write-Host " cpu - Install CPU-only PyTorch (default)"
Write-Host " cuXXX - Install CUDA-enabled PyTorch (e.g., cu121 for CUDA 12.1)"
exit 1
}
Write-Host "Requested PyTorch variant: $TorchVariant"
switch ($TorchVariant) {
"cpu" {
pip install torch torchvision -U --index-url https://download.pytorch.org/whl/cpu
}
{ $_ -match "^cu\d+$" } {
pip install torch torchvision -U --index-url "https://download.pytorch.org/whl/$TorchVariant"
}
Default { Show-Usage }
}
# Set PyInstaller mode based on torch variant
if ($TorchVariant -eq "cpu") {
$pyinstallerMode = "--onefile"
} else {
$pyinstallerMode = "--onedir"
}
# Upgrade build tools and hooks
python -m pip install -U pip wheel setuptools
python -m pip install -U pyinstaller pyinstaller-hooks-contrib
# Install runtime dependencies
python -m pip install -U numpy pillow scikit-learn
# Install CLIP and your package
pip install clip-anytorch
pip install .
Write-Host "Installing CLIP model..."
python -c "import clip; clip.load('ViT-B/32')"
# to permit testing on non-windows platforms
if ($IsWindows) {
$sep = ";"
} else {
$sep = ":"
}
# After installing PyTorch
pip cache purge
# Before running PyInstaller
Write-Host "Disk space before PyInstaller:"
Get-PSDrive C
# Run PyInstaller
pyinstaller `
--hidden-import clip `
--hidden-import numpy `
--hidden-import torch `
--hidden-import torchvision `
--hidden-import photomap `
--hidden-import photomap.backend `
--hidden-import photomap.backend.photomap_server `
--hidden-import photomap.backend.main_wrapper `
--hidden-import photomap.backend.routers `
--hidden-import photomap.backend.routers.album `
--hidden-import photomap.backend.routers.search `
--hidden-import photomap.backend.embeddings `
--hidden-import photomap.backend.config `
--hidden-import uvicorn `
--hidden-import fastapi `
--collect-all torch `
--collect-all torchvision `
--collect-all clip `
--collect-all numpy `
--collect-all sklearn `
--collect-all PIL `
--collect-all photomap `
--add-data "$(python -c "import clip; print(clip.__path__[0])"):clip" `
--add-data "$env:USERPROFILE/.cache/clip${sep}clip_models" `
--add-data "photomap/frontend/static${sep}photomap/frontend/static" `
--add-data "photomap/frontend/templates${sep}photomap/frontend/templates" `
--add-data "THIRD_PARTY_LICENSES.txt${sep}.THIRD_PARTY_LICENSES" `
--paths . `
$pyinstallerMode `
--name photomap `
-y `
photomap/backend/photomap_server.py
# After PyInstaller
Remove-Item -Recurse -Force build/ -ErrorAction SilentlyContinue