Repository navigation
Expand file tree
/
Copy pathbuild_executable.py
More file actions
133 lines (104 loc) · 3.67 KB
/
Copy pathbuild_executable.py
File metadata and controls
133 lines (104 loc) · 3.67 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
#!/usr/bin/env python3
"""
Build script for creating standalone executables
"""
import os
import shutil
import subprocess
import sys
from pathlib import Path
def build_executable():
"""Build the executable using PyInstaller"""
print("Cleaning previous builds...")
try:
if os.path.exists('dist'):
shutil.rmtree('dist')
except PermissionError:
print("Warning: Could not remove dist folder (file may be in use)")
print("Please close any running executables and try again")
return False
try:
if os.path.exists('build'):
shutil.rmtree('build')
except PermissionError:
print("Warning: Could not remove build folder")
# PyInstaller command - simple single file approach
cmd = [
sys.executable, '-m', 'PyInstaller',
'--onefile',
'--name=ai-studio-server',
'--add-data=config.json;.',
'--hidden-import=playwright',
'--hidden-import=playwright.async_api',
'--collect-all=playwright',
'api_server.py'
]
print("Building executable with PyInstaller...")
print("This may take 2-3 minutes, please wait...")
# Run with real-time output
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True, bufsize=1)
# Show progress dots
import time
import threading
def show_progress():
while process.poll() is None:
print(".", end="", flush=True)
time.sleep(2)
progress_thread = threading.Thread(target=show_progress)
progress_thread.daemon = True
progress_thread.start()
# Wait for completion
stdout, _ = process.communicate()
if process.returncode != 0:
print("\nBuild failed:")
print(stdout)
return False
print("\nBuild successful!")
# Create distribution folder with config
dist_folder = Path('dist/ai-studio-server-release')
dist_folder.mkdir(exist_ok=True)
# Copy executable (single file)
exe_name = 'ai-studio-server.exe' if sys.platform == 'win32' else 'ai-studio-server'
shutil.copy(f'dist/{exe_name}', dist_folder)
# Copy config template to the release folder
shutil.copy('config.json', dist_folder / 'config.json')
# Create README for users
readme_content = """# AI Studio Server
## Quick Start
1. **FIRST TIME ONLY**: Install Playwright browsers
Open Command Prompt/Terminal and run:
```
python -m playwright install chromium
```
(If you don't have Python, install it from python.org first)
2. Edit `config.json` and fill in your URLs:
- Replace `drive_folder_url` with your Google Drive folder URL
- Replace `aistudio_url` with your AI Studio prompt URL
3. Run the executable:
- Windows: Double-click `ai-studio-server.exe`
- Mac/Linux: `./ai-studio-server`
4. Follow the authentication prompts in your browser
## Configuration
Edit `config.json` to customize:
- Server port (default: 8383)
- Browser settings (headless mode, etc.)
- Gemini model parameters
- Timeout settings
The config file must be in the same directory as the executable.
## Troubleshooting
If you get "Playwright browsers not found":
1. Make sure Python is installed
2. Run: `python -m playwright install chromium`
3. Try running the executable again
"""
with open(dist_folder / 'README.txt', 'w') as f:
f.write(readme_content)
print(f"Distribution created in: {dist_folder}")
return True
if __name__ == '__main__':
if build_executable():
print("Ready for distribution!")
else:
print("Build failed!")
sys.exit(1)