-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_alternative.py
More file actions
291 lines (242 loc) · 8.66 KB
/
Copy pathbuild_alternative.py
File metadata and controls
291 lines (242 loc) · 8.66 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
#!/usr/bin/env python3
"""
Alternative build approach using site-packages copy method
"""
import os
import sys
import subprocess
import shutil
import site
from pathlib import Path
def get_site_packages_path():
"""Get the site-packages path from the current environment"""
for path in site.getsitepackages():
if 'site-packages' in path and os.path.exists(path):
return path
# Fallback for virtual environment
env_path = os.path.join(os.getcwd(), 'env', 'Lib', 'site-packages')
if os.path.exists(env_path):
return env_path
return None
def create_bundled_app():
"""Create a bundled application with all dependencies"""
print("Creating bundled application...")
# Create app directory
app_dir = "FloorPlanConverter_Bundled"
if os.path.exists(app_dir):
shutil.rmtree(app_dir)
os.makedirs(app_dir)
# Copy main application files
app_files = [
"app_local.py",
"local_png_to_dxf.py",
"standalone.py"
]
for file in app_files:
if os.path.exists(file):
shutil.copy2(file, app_dir)
print(f" ✅ Copied {file}")
# Copy src directory
if os.path.exists("src"):
shutil.copytree("src", os.path.join(app_dir, "src"))
print(" ✅ Copied src directory")
# Copy models directory
if os.path.exists("models"):
shutil.copytree("models", os.path.join(app_dir, "models"))
print(" ✅ Copied models directory")
# Copy build directory
if os.path.exists("build"):
shutil.copytree("build", os.path.join(app_dir, "build"))
print(" ✅ Copied build directory")
# Create outputs directory
os.makedirs(os.path.join(app_dir, "outputs"), exist_ok=True)
# Get site-packages path
site_packages = get_site_packages_path()
if not site_packages:
print("❌ Could not find site-packages directory")
return False
print(f"Using site-packages: {site_packages}")
# Copy essential packages
essential_packages = [
"gradio",
"gradio_client",
"matplotlib",
"torch",
"torchvision",
"onnxruntime",
"cv2",
"PIL",
"ezdxf",
"numpy",
"psutil",
"uvicorn",
"fastapi",
"starlette",
"websockets",
"httpx",
"h11",
"anyio",
"sniffio",
"pydantic",
"typing_extensions",
"click",
"colorama",
"jinja2",
"markupsafe",
"packaging",
"six",
"urllib3",
"certifi",
"charset_normalizer",
"idna",
"requests"
]
# Create lib directory in app
lib_dir = os.path.join(app_dir, "lib")
os.makedirs(lib_dir)
copied_packages = []
for package in essential_packages:
package_path = os.path.join(site_packages, package)
if os.path.exists(package_path):
try:
if os.path.isdir(package_path):
shutil.copytree(package_path, os.path.join(lib_dir, package))
else:
shutil.copy2(package_path, lib_dir)
copied_packages.append(package)
print(f" ✅ Copied package: {package}")
except Exception as e:
print(f" ⚠️ Failed to copy {package}: {e}")
else:
# Try with .py extension for single file modules
package_file = os.path.join(site_packages, f"{package}.py")
if os.path.exists(package_file):
shutil.copy2(package_file, lib_dir)
copied_packages.append(package)
print(f" ✅ Copied module: {package}.py")
print(f"Copied {len(copied_packages)} packages")
# Create launcher script
launcher_content = '''#!/usr/bin/env python3
"""
FloorPlan Converter Launcher
"""
import sys
import os
# Add lib directory to Python path
app_dir = os.path.dirname(os.path.abspath(__file__))
lib_dir = os.path.join(app_dir, "lib")
sys.path.insert(0, lib_dir)
sys.path.insert(0, app_dir)
# Set environment variables
os.environ["PYTHONPATH"] = lib_dir + os.pathsep + app_dir
os.environ["GRADIO_TEMP_DIR"] = os.path.join(app_dir, "temp")
# Create temp directory
os.makedirs(os.path.join(app_dir, "temp"), exist_ok=True)
try:
print("Starting FloorPlan Converter...")
print("Loading dependencies...")
# Import and run the app
import app_local
print("SUCCESS: All modules loaded successfully!")
print("WEB: Opening web interface...")
print("URL: Go to: http://localhost:7860")
except Exception as e:
print(f"ERROR: Error starting application: {e}")
print("Make sure all dependencies are properly installed.")
input("Press Enter to exit...")
'''
with open(os.path.join(app_dir, "launch.py"), "w", encoding='utf-8') as f:
f.write(launcher_content)
# Create batch launcher
batch_content = f'''@echo off
echo Starting FloorPlan Converter Bundled Application...
echo.
cd /d "%~dp0"
python launch.py
pause
'''
with open(os.path.join(app_dir, "Launch_FloorPlan_Converter.bat"), "w") as f:
f.write(batch_content)
# Create PowerShell launcher
ps_content = f'''Write-Host "Starting FloorPlan Converter Bundled Application..." -ForegroundColor Green
Set-Location $PSScriptRoot
python launch.py
Read-Host "Press Enter to exit"
'''
with open(os.path.join(app_dir, "Launch_FloorPlan_Converter.ps1"), "w") as f:
f.write(ps_content)
# Create README
readme_content = f'''# FloorPlan Converter - Bundled Application
## Requirements
- Python 3.8+ installed on the target machine
- No additional packages need to be installed
## How to Run
1. **Windows**: Double-click `Launch_FloorPlan_Converter.bat`
2. **PowerShell**: Run `Launch_FloorPlan_Converter.ps1`
3. **Manual**: Run `python launch.py`
## What's Included
- Complete FloorPlan Converter application
- All required Python packages bundled
- Sample inputs and models
- No internet connection required
## Features
- Hand-drawn sketch processing
- PNG image to DXF conversion
- Web-based interface
- Adjustable parameters
## Troubleshooting
- Make sure Python is installed and in PATH
- Run from Command Prompt if batch file doesn't work
- Check that all files are in the same directory
Bundled packages: {', '.join(copied_packages)}
'''
with open(os.path.join(app_dir, "README.txt"), "w") as f:
f.write(readme_content)
print(f"\n✅ Bundled application created: {app_dir}")
return True
def test_bundled_app():
"""Test the bundled application"""
app_dir = "FloorPlanConverter_Bundled"
launcher = os.path.join(app_dir, "launch.py")
if not os.path.exists(launcher):
print("❌ Bundled app not found")
return False
print(f"Testing bundled application...")
try:
# Test import capabilities
result = subprocess.run([
sys.executable, launcher
], cwd=app_dir, capture_output=True, text=True, timeout=10)
if "All modules loaded successfully!" in result.stdout:
print("✅ Bundled application test passed!")
return True
else:
print("❌ Bundled application test failed")
if result.stderr:
print(f"Error: {result.stderr}")
if result.stdout:
print(f"Output: {result.stdout}")
return False
except subprocess.TimeoutExpired:
print("✅ Application started (timeout reached - this is expected)")
return True
except Exception as e:
print(f"❌ Error testing bundled app: {e}")
return False
def main():
"""Main process"""
print("🔨 Creating Bundled FloorPlan Converter Application")
print("=" * 60)
if create_bundled_app():
if test_bundled_app():
print("\n🎉 Bundled application created successfully!")
print("📁 Location: FloorPlanConverter_Bundled/")
print("🚀 Run: Launch_FloorPlan_Converter.bat")
print("\n💡 This approach bundles all dependencies with the app")
print(" and doesn't require PyInstaller compilation.")
else:
print("\n⚠️ Bundled app created but test failed")
else:
print("\n❌ Failed to create bundled application")
if __name__ == "__main__":
main()