diff --git a/.gitignore b/.gitignore index 4add8a3..afb8ea0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vs/ /Server/ -/Agent/ \ No newline at end of file +/Agent/ +/Pyinstaller_Temp/ +Borealis-Server.spec +/dist/ \ No newline at end of file diff --git a/Data/Agent/borealis-agent.py b/Data/Agent/borealis-agent.py index 2ff9193..f3a68ad 100644 --- a/Data/Agent/borealis-agent.py +++ b/Data/Agent/borealis-agent.py @@ -163,7 +163,7 @@ def run_screenshot_loop(node_id, cfg): if node_id not in region_launchers: launcher = RegionLauncher(node_id) region_launchers[node_id] = launcher - launcher.trigger.emit(x, y, w, h) + QtCore.QTimer.singleShot(0, lambda: launcher.trigger.emit(x, y, w, h)) widget = overlay_widgets.get(node_id) if widget: diff --git a/Data/Python_API_Endpoints/ocr_engines.py b/Data/Python_API_Endpoints/ocr_engines.py index 73e086a..22e9c6e 100644 --- a/Data/Python_API_Endpoints/ocr_engines.py +++ b/Data/Python_API_Endpoints/ocr_engines.py @@ -2,6 +2,7 @@ import os import io +import sys import base64 import torch import pytesseract @@ -13,16 +14,25 @@ from PIL import Image # --------------------------------------------------------------------- # Configure cross-platform Tesseract path # --------------------------------------------------------------------- -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) SYSTEM = platform.system() +def get_tesseract_folder(): + if getattr(sys, 'frozen', False): + # PyInstaller EXE + base_path = sys._MEIPASS + return os.path.join(base_path, "Borealis", "Python_API_Endpoints", "Tesseract-OCR") + else: + # Normal Python environment + base_dir = os.path.dirname(os.path.abspath(__file__)) + return os.path.join(base_dir, "Tesseract-OCR") + if SYSTEM == "Windows": - TESSERACT_FOLDER = os.path.join(BASE_DIR, "Tesseract-OCR") + TESSERACT_FOLDER = get_tesseract_folder() TESSERACT_EXE = os.path.join(TESSERACT_FOLDER, "tesseract.exe") TESSDATA_DIR = os.path.join(TESSERACT_FOLDER, "tessdata") if not os.path.isfile(TESSERACT_EXE): - raise EnvironmentError("Missing tesseract.exe in /Tesseract-OCR. Ensure the full folder is copied.") + raise EnvironmentError(f"Missing tesseract.exe at expected path: {TESSERACT_EXE}") pytesseract.pytesseract.tesseract_cmd = TESSERACT_EXE os.environ["TESSDATA_PREFIX"] = TESSDATA_DIR diff --git a/Launch-Borealis.ps1 b/Launch-Borealis.ps1 index da51ed3..6e5bba3 100644 --- a/Launch-Borealis.ps1 +++ b/Launch-Borealis.ps1 @@ -177,14 +177,14 @@ switch ($choice) { Run-Step "Create Virtual Python Environment for Agent" { # Create virtual environment for the agent if (!(Test-Path "$venvFolder\Scripts\Activate")) { - python -m venv $venvFolder | Out-Null + python -m venv $venvFolder } # Copy the agent script if it exists if (Test-Path $agentSourcePath) { if (Test-Path $agentDestinationFolder) { - Remove-Item -Recurse -Force $agentDestinationFolder | Out-Null + Remove-Item -Recurse -Force $agentDestinationFolder } - New-Item -Path $agentDestinationFolder -ItemType Directory -Force | Out-Null + New-Item -Path $agentDestinationFolder -ItemType Directory -Force Copy-Item -Path $agentSourcePath -Destination $agentDestinationFile -Force } else { Write-Host "`r$($symbols.Info) Warning: Agent script not found at '$agentSourcePath', skipping copy." -ForegroundColor Yellow @@ -196,7 +196,7 @@ switch ($choice) { # ---------------------- Agent: Install Python Dependencies ---------------------- Run-Step "Install Python Dependencies for Agent" { if (Test-Path $agentRequirements) { - pip install -q -r $agentRequirements 2>&1 | Out-Null + pip install -q -r $agentRequirements 2>&1 } else { Write-Host "`r$($symbols.Info) Agent-specific requirements.txt not found at '$agentRequirements', skipping Python packages." -ForegroundColor Yellow } diff --git a/Package-Borealis-Server.ps1 b/Package-Borealis-Server.ps1 new file mode 100644 index 0000000..757d64c --- /dev/null +++ b/Package-Borealis-Server.ps1 @@ -0,0 +1,75 @@ +#////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: /Package-Borealis-Server.ps1 + +# ------------------- CONFIGURATION ------------------- +$venvDir = "Pyinstaller_Virtual_Environment" +$serverScript = "Server\Borealis\server.py" +$outputName = "Borealis-Server" +$distExePath = "dist\$outputName.exe" +$buildDir = "Pyinstaller_Server_Build" +$specFile = "$outputName.spec" + +$reactBuild = "Server\web-interface\build" +$tesseractDir = "Server\Borealis\Python_API_Endpoints\Tesseract-OCR" + +# ------------------- ENV SETUP ------------------- +Write-Host "`n[INFO] Preparing virtual environment and dependencies..." -ForegroundColor Cyan + +$activateScript = "$venvDir\Scripts\Activate.ps1" + +if (-Not (Test-Path $activateScript)) { + Write-Host "[SETUP] Creating virtual environment at $venvDir" + python -m venv $venvDir +} + +# ------------------- ACTIVATE ------------------- +Write-Host "[INFO] Activating virtual environment..." +. $activateScript + +# ------------------- INSTALL DEPENDENCIES ------------------- +Write-Host "[INFO] Installing project dependencies into virtual environment..." +pip install --upgrade pip > $null +pip install -r requirements.txt + +# ------------------- INSTALL PYINSTALLER ------------------- +Write-Host "[INFO] Installing PyInstaller..." +pip install pyinstaller > $null + +# Resolve PyInstaller path +$pyInstallerPath = "$venvDir\Scripts\pyinstaller.exe" + +if (-Not (Test-Path $pyInstallerPath)) { + Write-Host "[ERROR] PyInstaller not found even after install. Aborting." -ForegroundColor Red + exit 1 +} + +# ------------------- CLEANUP OLD BUILD ------------------- +Write-Host "[INFO] Cleaning previous build artifacts..." -ForegroundColor Gray +Remove-Item -Recurse -Force "dist", "build", $specFile -ErrorAction SilentlyContinue + +# ------------------- BUILD PYINSTALLER CMD ------------------- +$reactStaticAssets = "$reactBuild;web-interface/build" +$tesseractAssets = "$tesseractDir;Borealis/Python_API_Endpoints/Tesseract-OCR" + +$cmdArgs = @( + "--onefile", + "--noconfirm", + "--name", "$outputName", + "--add-data", "`"$reactStaticAssets`"", + "--add-data", "`"$tesseractAssets`"", + "--hidden-import=eventlet", + "--clean", + "`"$serverScript`"" +) + +$arguments = $cmdArgs -join " " + +Write-Host "`n[INFO] Running PyInstaller with Start-Process..." -ForegroundColor Yellow +Start-Process -FilePath $pyInstallerPath -ArgumentList $arguments -Wait -NoNewWindow + +# ------------------- DONE ------------------- +if (Test-Path $distExePath) { + Write-Host "`n[SUCCESS] Packaging complete!" + Write-Host " Output: $distExePath" -ForegroundColor Green +} else { + Write-Host "`n[FAILURE] Packaging failed." -ForegroundColor Red +} diff --git a/requirements.txt b/requirements.txt index d26bad4..456f45d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ eventlet # GUI-related dependencies (Qt for GUI components) Qt.py qtpy -OdenGraphQt PyQt5 # Computer Vision & OCR Dependencies