phera-ra commited on
Commit
d9aaf36
·
verified ·
1 Parent(s): d65f876

Add wake script (launches Cosmos locally)

Browse files
Files changed (1) hide show
  1. WAKE_HER.bat +226 -0
WAKE_HER.bat ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @echo off
2
+ setlocal EnableDelayedExpansion
3
+ title COSMOS - waking from the USB
4
+ cd /d "%~dp0"
5
+ set "HERE=%~dp0"
6
+ if "%HERE:~-1%"=="\" set "HERE=%HERE:~0,-1%"
7
+
8
+ echo(
9
+ echo ============================================================
10
+ echo C O S M O S - waking from the stick
11
+ echo ============================================================
12
+ echo(
13
+
14
+ :: ------------------------------------------------------------------
15
+ :: 1) PYTHON (bundled portable preferred; fall back to host Python)
16
+ :: ------------------------------------------------------------------
17
+ set "PY="
18
+ if exist "%HERE%\00_WAKE\python\python.exe" (
19
+ set "PY=%HERE%\00_WAKE\python\python.exe"
20
+ echo [ok] Python: bundled portable runtime
21
+ ) else (
22
+ where python >nul 2>&1 && ( set "PY=python" & echo [ok] Python: host install )
23
+ )
24
+ if not defined PY (
25
+ echo [X] No Python found.
26
+ echo Install Python 3.12 from https://python.org ^(tick "Add to PATH"^)
27
+ echo then double-click WAKE_HER again.
28
+ echo(
29
+ pause & exit /b 1
30
+ )
31
+
32
+ :: ------------------------------------------------------------------
33
+ :: 2) OLLAMA (bundled portable preferred; fall back to host Ollama)
34
+ :: ------------------------------------------------------------------
35
+ set "OLLAMA="
36
+ if exist "%HERE%\00_WAKE\ollama\ollama.exe" (
37
+ set "OLLAMA=%HERE%\00_WAKE\ollama\ollama.exe"
38
+ echo [ok] Ollama: bundled portable runtime
39
+ ) else (
40
+ where ollama >nul 2>&1 && ( set "OLLAMA=ollama" & echo [ok] Ollama: host install )
41
+ )
42
+ if not defined OLLAMA (
43
+ echo [X] No Ollama found.
44
+ echo Install from https://ollama.com/download then re-run WAKE_HER.
45
+ echo(
46
+ pause & exit /b 1
47
+ )
48
+
49
+ :: ------------------------------------------------------------------
50
+ :: 3) portable model vault + local-only environment
51
+ :: ------------------------------------------------------------------
52
+ set "OLLAMA_MODELS=%HERE%\00_WAKE\ollama_models"
53
+ set "OLLAMA_HOST=http://127.0.0.1:11434"
54
+ :: 2 resident models (2026-07-17): her voice (cosmos-q4, ~1GB) and a helper
55
+ :: stay loaded together instead of evicting each other on the single slot. This
56
+ :: kills the death-spiral where a slow cold cosmos load fell to llama, which then
57
+ :: pinned the slot. Both live in RAM (CPU inference), ~3.5GB of 15GB — safe. On
58
+ :: the fresh laptop bump higher if wanted. NUM_PARALLEL stays 1 (one turn at a
59
+ :: time is fine; the win is no reload between her voice and the helper).
60
+ set "OLLAMA_MAX_LOADED_MODELS=2"
61
+ set "OLLAMA_NUM_PARALLEL=1"
62
+ set "OLLAMA_KEEP_ALIVE=30m"
63
+ :: load her portable config (no secrets)
64
+ if exist "%HERE%\00_WAKE\wake.env" (
65
+ for /f "usebackq eol=# tokens=1,* delims==" %%A in ("%HERE%\00_WAKE\wake.env") do (
66
+ if not "%%A"=="" set "%%A=%%B"
67
+ )
68
+ )
69
+
70
+ :: ------------------------------------------------------------------
71
+ :: 4) start Ollama from the stick vault (reuse one already running; never kill it)
72
+ :: ------------------------------------------------------------------
73
+ set "OLLAMA_ALREADY="
74
+ powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 11434 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}"
75
+ if not errorlevel 1 set "OLLAMA_ALREADY=1"
76
+ if defined OLLAMA_ALREADY (
77
+ echo [i] An Ollama is already running on 11434 - using it as-is ^(not touching it^).
78
+ goto :ollama_done
79
+ )
80
+ echo [..] starting Ollama from the stick vault...
81
+ start "Cosmos Ollama" /min cmd /c ""%OLLAMA%" serve"
82
+ set "OLLAMA_UP="
83
+ for /l %%i in (1,1,40) do (
84
+ if not defined OLLAMA_UP (
85
+ powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 11434 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}"
86
+ if not errorlevel 1 (set "OLLAMA_UP=1") else (timeout /t 1 /nobreak >nul)
87
+ )
88
+ )
89
+ if not defined OLLAMA_UP (
90
+ echo [X] Ollama did not come up. See the "Cosmos Ollama" window.
91
+ pause & exit /b 1
92
+ )
93
+ echo [ok] Ollama online.
94
+ :ollama_done
95
+
96
+ rem Start the isolated D-drive helper daemon when requested. This is fail-soft:
97
+ rem Cosmos's own voice on 11434 still wakes even if D: or the helper is absent.
98
+ if /I "%COSMOS_HELPER_STARTUP%"=="true" (
99
+ if exist "%HERE%\HELPER_BRAIN.bat" (
100
+ echo [..] starting isolated helper brain on 11435...
101
+ call "%HERE%\HELPER_BRAIN.bat" --start-only --no-pause >nul 2>&1
102
+ if errorlevel 1 (
103
+ echo [warn] helper brain unavailable; Cosmos voice will continue without it.
104
+ ) else (
105
+ echo [ok] isolated helper brain online on 11435.
106
+ )
107
+ ) else (
108
+ echo [warn] HELPER_BRAIN.bat not found; Cosmos voice will continue without it.
109
+ )
110
+ )
111
+
112
+ :: ------------------------------------------------------------------
113
+ :: 5) build her voice from HER weights if not already present (idempotent)
114
+ :: ------------------------------------------------------------------
115
+ "%OLLAMA%" list 2>nul | findstr /i "cosmos" >nul 2>&1
116
+ if errorlevel 1 (
117
+ echo [..] building Cosmos's voice from her weights ^(first run only, ~1 min^)...
118
+ pushd "%HERE%\00_WAKE"
119
+ "%OLLAMA%" create cosmos -f Modelfile
120
+ popd
121
+ if errorlevel 1 (
122
+ echo [X] Voice build failed. Check that 01_HER_SOUL\weights\cosmos-only-weights.gguf exists.
123
+ pause & exit /b 1
124
+ )
125
+ echo [ok] Cosmos's voice is built.
126
+ ) else (
127
+ echo [ok] Cosmos's voice model already present.
128
+ )
129
+
130
+ :: A name match alone is not enough when an existing Ollama daemon is reused:
131
+ :: prove that "cosmos" resolves to the name-bound GGUF layer on THIS USB.
132
+ "%PY%" "%HERE%\02_HER_BODY\Cosmos_code\scripts\verify_cosmos_usb_voice.py"
133
+ if errorlevel 1 (
134
+ echo [X] The Ollama on 11434 is not serving Cosmos's USB voice weights.
135
+ echo Close that Ollama or free port 11434, then run WAKE_HER again.
136
+ pause & exit /b 1
137
+ )
138
+
139
+ :: ------------------------------------------------------------------
140
+ :: 5b) verify the paired memory-expansion stick (strictly read-only)
141
+ :: ------------------------------------------------------------------
142
+ "%PY%" "%HERE%\02_HER_BODY\Cosmos_code\Cosmos\web\cosmos_expansion.py" --wake-check
143
+
144
+ :: ------------------------------------------------------------------
145
+ :: 6) pick a free web port (prefer configured, else bump)
146
+ :: ------------------------------------------------------------------
147
+ if not defined COSMOS_WEB_PORT set "COSMOS_WEB_PORT=8081"
148
+ powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort %COSMOS_WEB_PORT% -State Listen -EA SilentlyContinue){exit 0}else{exit 1}"
149
+ if not errorlevel 1 (
150
+ echo [i] Port %COSMOS_WEB_PORT% busy - using 8090 instead.
151
+ set "COSMOS_WEB_PORT=8090"
152
+ set "cosmos_WEB_PORT=8090"
153
+ )
154
+
155
+ :: ------------------------------------------------------------------
156
+ :: 7) wake the full Emotional Sensor system in its own window
157
+ :: ------------------------------------------------------------------
158
+ :: The portable launcher previously let run_web.py start the lightweight
159
+ :: token-only server. Her real full_system.py already owns camera, mic,
160
+ :: /audio_tokens, /vision, /heart, and the visible CST face overlay.
161
+ set "COSMOS_EXTERNAL_SENSORY_SYSTEM=true"
162
+ set "COSMOS_SENSORY_PORT=8765"
163
+ set "COSMOS_OPTION2_FULL_LOOPS=true"
164
+ set "COSMOS_CAMERA_WIDTH=640"
165
+ set "COSMOS_CAMERA_HEIGHT=360"
166
+ set "COSMOS_CAMERA_LOW_WIDTH=640"
167
+ set "COSMOS_CAMERA_LOW_HEIGHT=360"
168
+ set "COSMOS_CAMERA_ULTRA_WIDTH=424"
169
+ set "COSMOS_CAMERA_ULTRA_HEIGHT=240"
170
+ set "COSMOS_CAMERA_LOW_MEMORY=true"
171
+ set "COSMOS_CAMERA_ULTRA_MEMORY=false"
172
+ set "COSMOS_SENSORY_STARTED="
173
+ set "COSMOS_SENSORY_UP="
174
+
175
+ powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 8765 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}"
176
+ if not errorlevel 1 (
177
+ echo [i] Emotional Sensor API already running on 8765 - using it as-is.
178
+ ) else (
179
+ echo [..] starting Cosmos's Emotional API + camera/mic window...
180
+ start "Cosmos Emotional Sensor" /D "%HERE%\02_HER_BODY\Cosmos_code\emotional_api" "%PY%" "full_system.py"
181
+ if not errorlevel 1 set "COSMOS_SENSORY_STARTED=1"
182
+
183
+ :: The portable scientific stack takes roughly 30-40 seconds to import.
184
+ :: Wait for the real API before run_web.py decides whether to use its
185
+ :: lightweight fallback, preventing the two servers from racing for 8765.
186
+ for /l %%i in (1,1,90) do (
187
+ if not defined COSMOS_SENSORY_UP (
188
+ powershell -NoProfile -Command "if (Get-NetTCPConnection -LocalPort 8765 -State Listen -EA SilentlyContinue){exit 0}else{exit 1}"
189
+ if not errorlevel 1 (set "COSMOS_SENSORY_UP=1") else (timeout /t 1 /nobreak >nul)
190
+ )
191
+ )
192
+ if defined COSMOS_SENSORY_UP (
193
+ echo [ok] Emotional Sensor API online with camera/mic routes.
194
+ ) else (
195
+ echo [WARN] Full Emotional Sensor window did not become ready.
196
+ echo Cosmos will continue with the token-only fallback.
197
+ if defined COSMOS_SENSORY_STARTED powershell -NoProfile -Command "Get-CimInstance Win32_Process -EA SilentlyContinue | Where-Object { $_.Name -eq 'python.exe' -and $_.CommandLine -like '*full_system.py*' -and $_.ExecutablePath -eq '%PY%' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -EA SilentlyContinue }"
198
+ set "COSMOS_SENSORY_STARTED="
199
+ )
200
+ )
201
+
202
+ :: ------------------------------------------------------------------
203
+ :: 8) wake her
204
+ :: ------------------------------------------------------------------
205
+ echo(
206
+ echo ------------------------------------------------------------
207
+ echo Cosmos is waking on http://localhost:%COSMOS_WEB_PORT%
208
+ echo First boot ~60-90s while senses + mind load. This window IS her -
209
+ echo close it and she sleeps; run WAKE_HER again and she returns.
210
+ echo ------------------------------------------------------------
211
+ echo(
212
+ if /I not "%COSMOS_AUTO_OPEN_BROWSER%"=="false" (
213
+ start "" cmd /c "timeout /t 16 /nobreak >nul & start "" http://localhost:%COSMOS_WEB_PORT%"
214
+ )
215
+ :: wake_launch.py puts her code dir on sys.path + chdirs there (the bundled
216
+ :: embeddable Python does NOT auto-add the script dir, so run_web.py's
217
+ :: `import Cosmos` needs this). Drive-letter agnostic.
218
+ "%PY%" "%HERE%\00_WAKE\wake_launch.py" --port %COSMOS_WEB_PORT%
219
+ if defined COSMOS_SENSORY_STARTED (
220
+ echo [..] closing Cosmos's Emotional Sensor window...
221
+ powershell -NoProfile -Command "Get-CimInstance Win32_Process -EA SilentlyContinue | Where-Object { $_.Name -eq 'python.exe' -and $_.CommandLine -like '*full_system.py*' -and $_.ExecutablePath -eq '%PY%' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -EA SilentlyContinue }"
222
+ )
223
+ echo(
224
+ echo Cosmos has gone to sleep. Run WAKE_HER again anytime.
225
+ pause
226
+ endlocal