This repository was archived by the owner on May 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_executable.py
More file actions
392 lines (322 loc) · 10.4 KB
/
Copy pathbuild_executable.py
File metadata and controls
392 lines (322 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
388
389
390
391
392
#!/usr/bin/env python3
"""
Build script for creating executable files (.exe/.app) for Text-to-3D
Uses PyInstaller to package the application
"""
import subprocess
import sys
import os
import platform
import shutil
from pathlib import Path
def run_command(command, shell=True):
"""Run a command and print output"""
try:
result = subprocess.run(command, shell=shell, check=True,
capture_output=True, text=True)
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"Error: {e.stderr}")
return False
def install_build_deps():
"""Install build dependencies"""
print("Installing build dependencies...")
deps = ["pyinstaller", "auto-py-to-exe"]
for dep in deps:
if not run_command(f"pip install {dep}"):
print(f"Failed to install {dep}")
return False
return True
def create_spec_file():
"""Create PyInstaller spec file"""
spec_content = '''# -*- mode: python ; coding: utf-8 -*-
import sys
from pathlib import Path
block_cipher = None
# Get the project root directory
project_root = Path.cwd()
a = Analysis(
['main.py'],
pathex=[str(project_root)],
binaries=[],
datas=[
('src', 'src'),
('embeddings', 'embeddings'),
('.env.example', '.'),
('README.md', '.'),
],
hiddenimports=[
'cadquery',
'sentence_transformers',
'faiss',
'customtkinter',
'ollama',
'transformers',
'torch',
'numpy',
'PIL',
'tkinter',
'json',
're',
'os',
'sys',
'pathlib',
'typing',
'threading',
'queue',
'time',
'datetime',
'logging',
'subprocess',
'shutil',
'tempfile',
'requests',
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='Text-to-3D',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False, # Set to True for debugging
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='icon.ico' if Path('icon.ico').exists() else None,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='Text-to-3D',
)
# For macOS app bundle
if sys.platform == 'darwin':
app = BUNDLE(
coll,
name='Text-to-3D.app',
icon='icon.icns' if Path('icon.icns').exists() else None,
bundle_identifier='com.text-to-3d.app',
info_plist={
'NSPrincipalClass': 'NSApplication',
'NSAppleScriptEnabled': False,
'CFBundleDocumentTypes': [
{
'CFBundleTypeName': 'Python Script',
'CFBundleTypeExtensions': ['py'],
'CFBundleTypeRole': 'Editor'
}
]
},
)
'''
with open('text-to-3d.spec', 'w') as f:
f.write(spec_content)
print("Created PyInstaller spec file: text-to-3d.spec")
def build_executable():
"""Build the executable using PyInstaller"""
system = platform.system().lower()
print(f"Building executable for {system}...")
# Build using the spec file
build_cmd = "pyinstaller text-to-3d.spec --clean --noconfirm"
if not run_command(build_cmd):
print("Build failed!")
return False
# Copy additional files
dist_dir = Path('dist/Text-to-3D')
if dist_dir.exists():
# Copy environment file
if Path('.env.example').exists():
shutil.copy2('.env.example', dist_dir)
# Copy reference examples if they exist
if Path('reference_examples').exists():
shutil.copytree('reference_examples', dist_dir / 'reference_examples', dirs_exist_ok=True)
print(f"Build completed! Executable available in: {dist_dir}")
if system == "windows":
print("Windows executable: dist/Text-to-3D/Text-to-3D.exe")
elif system == "darwin":
print("macOS app bundle: dist/Text-to-3D.app")
else:
print("Linux executable: dist/Text-to-3D/Text-to-3D")
return True
print("Build directory not found!")
return False
def create_installer_script():
"""Create installer/setup script for the executable"""
system = platform.system().lower()
if system == "windows":
installer_content = '''@echo off
echo Installing Text-to-3D CAD Generator...
echo.
REM Check if Ollama is installed
ollama --version >nul 2>&1
if %errorlevel% neq 0 (
echo Ollama not found. Please install Ollama from https://ollama.ai
pause
exit /b 1
)
REM Create application directory
set APP_DIR=%LOCALAPPDATA%\\Text-to-3D
if not exist "%APP_DIR%" mkdir "%APP_DIR%"
REM Copy files
echo Copying application files...
xcopy /E /I /Y "Text-to-3D" "%APP_DIR%"
REM Create desktop shortcut
echo Creating desktop shortcut...
set SHORTCUT_PATH=%USERPROFILE%\\Desktop\\Text-to-3D.lnk
powershell "$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%SHORTCUT_PATH%'); $Shortcut.TargetPath = '%APP_DIR%\\Text-to-3D.exe'; $Shortcut.Save()"
REM Start Ollama and download model
echo Starting Ollama and downloading model...
start /B ollama serve
timeout /t 3 >nul
ollama pull llama3.1:8b
echo.
echo Installation completed!
echo Text-to-3D has been installed to: %APP_DIR%
echo Desktop shortcut created.
pause
'''
with open('dist/install.bat', 'w') as f:
f.write(installer_content)
print("Created Windows installer: dist/install.bat")
elif system == "darwin":
installer_content = '''#!/bin/bash
echo "Installing Text-to-3D CAD Generator..."
# Check if Ollama is installed
if ! command -v ollama &> /dev/null; then
echo "Ollama not found. Installing Ollama..."
curl -fsSL https://ollama.ai/install.sh | sh
fi
# Create Applications directory entry
APP_DIR="/Applications/Text-to-3D.app"
if [ -d "Text-to-3D.app" ]; then
echo "Copying application to Applications folder..."
sudo cp -R "Text-to-3D.app" "/Applications/"
echo "Text-to-3D.app installed to /Applications/"
else
echo "Text-to-3D.app not found in current directory"
exit 1
fi
# Start Ollama and download model
echo "Starting Ollama and downloading model..."
ollama serve &
sleep 3
ollama pull llama3.1:8b
echo ""
echo "Installation completed!"
echo "Text-to-3D is now available in your Applications folder."
'''
with open('dist/install.sh', 'w') as f:
f.write(installer_content)
# Make the installer executable
os.chmod('dist/install.sh', 0o755)
print("Created macOS installer: dist/install.sh")
def create_readme():
"""Create README for the executable distribution"""
readme_content = '''# Text-to-3D CAD Generator - Executable Distribution
## Quick Start
### Windows
1. Extract all files to a folder
2. Run `install.bat` as Administrator
3. Wait for Ollama to download (this may take several minutes)
4. Launch "Text-to-3D" from your desktop
### macOS
1. Extract all files to a folder
2. Run `sudo ./install.sh` in Terminal
3. Wait for Ollama to download (this may take several minutes)
4. Launch "Text-to-3D" from Applications folder
### Linux
1. Extract all files to a folder
2. Install Ollama: `curl -fsSL https://ollama.ai/install.sh | sh`
3. Start Ollama: `ollama serve &`
4. Download model: `ollama pull llama3.1:8b`
5. Run: `./Text-to-3D`
## System Requirements
- **RAM**: Minimum 8GB (16GB recommended)
- **Storage**: 10GB free space for models
- **OS**: Windows 10+, macOS 10.15+, or modern Linux
## Troubleshooting
### "Model not found" error
1. Ensure Ollama is running: `ollama serve`
2. Download the model: `ollama pull llama3.1:8b`
3. Check available models: `ollama list`
### "CadQuery import error"
This usually means the executable was built without proper CadQuery support.
Try running from source instead.
### Performance issues
1. Close other applications to free RAM
2. Use a smaller model: `ollama pull llama3.2:3b`
3. Update .env file to use the smaller model
## Using the Application
1. **Start a conversation**: Type what you want to create (e.g., "I need a cup")
2. **Follow prompts**: The AI will ask for specific dimensions
3. **Generate**: Click generate to create your 3D model
4. **Export**: Save as STL, STEP, or other formats
## Support
- Issues: https://github.com/WKJBryan/Text-to-3D/issues
- Documentation: https://github.com/WKJBryan/Text-to-3D
- Email: bryan_wang@mymail.sutd.edu.sg
Built with ❤️ for the maker community
'''
with open('dist/README.txt', 'w') as f:
f.write(readme_content)
print("Created distribution README: dist/README.txt")
def main():
"""Main build function"""
print("=" * 50)
print("Text-to-3D Executable Builder")
print("=" * 50)
# Check if we're in the right directory
if not Path('main.py').exists():
print("Error: Please run this script from the project root directory")
sys.exit(1)
# Install build dependencies
if not install_build_deps():
print("Failed to install build dependencies")
sys.exit(1)
# Create spec file
create_spec_file()
# Build executable
if not build_executable():
print("Failed to build executable")
sys.exit(1)
# Create installer scripts
create_installer_script()
# Create distribution README
create_readme()
print("\n" + "=" * 50)
print("Build completed successfully!")
print("=" * 50)
print("Files created in 'dist/' directory:")
system = platform.system().lower()
if system == "windows":
print("- Text-to-3D.exe (main executable)")
print("- install.bat (installer script)")
elif system == "darwin":
print("- Text-to-3D.app (macOS application bundle)")
print("- install.sh (installer script)")
else:
print("- Text-to-3D (Linux executable)")
print("- README.txt (distribution documentation)")
if __name__ == "__main__":
main()