-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathwindows.bat
More file actions
151 lines (135 loc) · 5.4 KB
/
Copy pathwindows.bat
File metadata and controls
151 lines (135 loc) · 5.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
@echo off
setlocal EnableExtensions EnableDelayedExpansion
title Uncensored AI Studio
cd /d "%~dp0"
set APP=%~dp0app
set NODE=%APP%\tools\node-win\node.exe
set NPM=%APP%\tools\node-win\npm.cmd
set DIST=%APP%\dist\index.html
set SETUP=%~dp0scripts\setup\setup.ps1
set CUDA_BACKEND=%APP%\backend\win\cuda\sd-cuda.exe
set VULKAN_BACKEND=%APP%\backend\win\vulkan\sd-vulkan.exe
set LLM_CUDA_BACKEND=%APP%\llm-backend\win\cuda\llama-server.exe
set LLM_HIP_BACKEND=%APP%\llm-backend\win\hip\llama-server.exe
set LLM_VULKAN_BACKEND=%APP%\llm-backend\win\vulkan\llama-server.exe
set LLM_SYCL_BACKEND=%APP%\llm-backend\win\sycl\llama-server.exe
set LLM_CPU_BACKEND=%APP%\llm-backend\win\cpu\llama-server.exe
set SPEECH_BACKEND=%APP%\speech-backend\win\cpu\whisper-cli.exe
set TTS_RUNTIME=%APP%\tts-runtime\node_modules\kokoro-js
set SERVE=%~dp0scripts\server\serve.cjs
if "%FRONTEND_PORT%"=="" set FRONTEND_PORT=1420
if "%LLM_PORT%"=="" set LLM_PORT=10086
set SETUP_REASON=
set SETUP_MODE=Repair
:: -- First-time setup check ----------------------------------------------------
if not exist "%APP%\tools\node-win" set SETUP_MODE=First-Time Setup
if not exist "%NODE%" (
set SETUP_REASON=Portable Node.js is missing.
goto :run_setup
)
if not exist "%NPM%" (
set SETUP_REASON=Portable npm is missing.
goto :run_setup
)
if not exist "%DIST%" (
set SETUP_REASON=Frontend build is missing.
goto :run_setup
)
if not exist "%LLM_CUDA_BACKEND%" if not exist "%LLM_HIP_BACKEND%" if not exist "%LLM_VULKAN_BACKEND%" if not exist "%LLM_SYCL_BACKEND%" if not exist "%LLM_CPU_BACKEND%" (
set SETUP_REASON=llama.cpp text backend is missing.
goto :run_setup
)
if not exist "%SPEECH_BACKEND%" (
set SETUP_REASON=whisper.cpp speech backend is missing.
goto :run_setup
)
if not exist "%TTS_RUNTIME%" (
set SETUP_REASON=Kokoro text-to-speech runtime is missing.
goto :run_setup
)
if exist "%CUDA_BACKEND%" goto :launch
if exist "%VULKAN_BACKEND%" goto :launch
set SETUP_REASON=No backend binary is installed.
goto :run_setup
:run_setup
echo.
echo ============================================================
echo UNCENSORED AI STUDIO ^| %SETUP_MODE%
echo ============================================================
echo.
if "%SETUP_MODE%"=="First-Time Setup" (
echo This looks like your first run. Setting up automatically...
) else (
echo Uncensored AI Studio needs a quick repair before launch.
)
if not "%SETUP_REASON%"=="" echo Reason: %SETUP_REASON%
echo Models are not downloaded during setup. Download or import them in the app.
echo.
echo Press any key to continue, or Ctrl+C to cancel.
pause >nul
:: Clear old managed backend processes before setup so app/tools/node-win can be replaced.
:: Do not kill the frontend port; launch will select a free frontend port automatically.
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":8080 "') do taskkill /f /pid %%a >nul 2>nul
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":%LLM_PORT% "') do taskkill /f /pid %%a >nul 2>nul
powershell -ExecutionPolicy Bypass -File "%SETUP%"
if errorlevel 1 (
echo.
echo [ERROR] Setup failed. Please check the output above.
pause
exit /b 1
)
:: After setup, continue to launch
goto :launch
:: -- Launch -------------------------------------------------------------------
:launch
echo.
echo ============================================================
echo UNCENSORED AI STUDIO ^| Launching...
echo ============================================================
echo.
set "REQUESTED_FRONTEND_PORT=%FRONTEND_PORT%"
call :resolve_frontend_port
if errorlevel 1 exit /b 1
if not "%FRONTEND_PORT%"=="%REQUESTED_FRONTEND_PORT%" echo Frontend port %REQUESTED_FRONTEND_PORT% is busy; using %FRONTEND_PORT% instead.
:: Clear managed backend ports to prevent stale API conflicts.
echo Clearing backend port 8080 and text port %LLM_PORT%...
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":8080 "') do taskkill /f /pid %%a >nul 2>nul
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":%LLM_PORT% "') do taskkill /f /pid %%a >nul 2>nul
:: Start frontend server + backend manager (serve.cjs manages sd-vulkan.exe)
echo Starting Uncensored AI Studio...
echo Opening browser at http://localhost:%FRONTEND_PORT%...
start /b cmd /c "timeout /t 2 >nul && start http://localhost:%FRONTEND_PORT%"
echo.
echo ============================================================
echo Running!
echo Web UI: http://localhost:%FRONTEND_PORT%
echo GPU API: Auto-selected by the app (starts at 8080)
echo Text API: Starts when a GGUF model is loaded (port %LLM_PORT%)
echo Speech: Managed locally by the app
echo TTS: Managed locally by the app
echo.
echo Press Ctrl+C in this window to stop all services.
echo ============================================================
echo.
"%NODE%" "%SERVE%"
exit /b %ERRORLEVEL%
:resolve_frontend_port
call :is_port_available "%FRONTEND_PORT%"
if "%PORT_AVAILABLE%"=="1" exit /b 0
for /L %%p in (1421,1,1499) do (
if not "%%p"=="%FRONTEND_PORT%" (
call :is_port_available "%%p"
if "!PORT_AVAILABLE!"=="1" (
set "FRONTEND_PORT=%%p"
exit /b 0
)
)
)
echo [ERROR] No free frontend port found. Tried %FRONTEND_PORT% and 1421-1499.
exit /b 1
:is_port_available
set "PORT_AVAILABLE=1"
for /f "tokens=5" %%a in ('netstat -aon 2^>nul ^| findstr ":%~1 " ^| findstr /I "LISTENING"') do (
set "PORT_AVAILABLE=0"
)
exit /b 0