|
@@ -363,3 +363,155 @@ The server will automatically use the correct parameters when loading models bas
|
|
|
4. Provide correct command-line flags for manual loading
|
|
4. Provide correct command-line flags for manual loading
|
|
|
|
|
|
|
|
See `MODEL_DETECTION.md` for complete documentation on the detection system.
|
|
See `MODEL_DETECTION.md` for complete documentation on the detection system.
|
|
|
|
|
+
|
|
|
|
|
+## Web UI Architecture
|
|
|
|
|
+
|
|
|
|
|
+The project includes a Next.js-based web UI located in `/webui` that provides a modern interface for interacting with the REST API.
|
|
|
|
|
+
|
|
|
|
|
+### Building the Web UI
|
|
|
|
|
+
|
|
|
|
|
+```bash
|
|
|
|
|
+# Build Web UI manually
|
|
|
|
|
+cd webui
|
|
|
|
|
+npm install
|
|
|
|
|
+npm run build
|
|
|
|
|
+
|
|
|
|
|
+# Build via CMake (automatically copies to build directory)
|
|
|
|
|
+cmake --build build --target webui-build
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+The built UI is automatically copied to `build/webui/` and served by the REST API server at `/ui/`.
|
|
|
|
|
+
|
|
|
|
|
+### WebUI Structure
|
|
|
|
|
+
|
|
|
|
|
+- **Framework**: Next.js 16 with React, TypeScript, and Tailwind CSS
|
|
|
|
|
+- **Routing**: App router with static page generation
|
|
|
|
|
+- **UI Components**: Shadcn/ui components in `/webui/components/ui/`
|
|
|
|
|
+- **Pages**:
|
|
|
|
|
+ - `/webui/app/text2img/page.tsx` - Text-to-image generation
|
|
|
|
|
+ - `/webui/app/img2img/page.tsx` - Image-to-image generation
|
|
|
|
|
+ - `/webui/app/upscaler/page.tsx` - Image upscaling
|
|
|
|
|
+ - `/webui/app/models/page.tsx` - Model management
|
|
|
|
|
+ - `/webui/app/queue/page.tsx` - Queue status
|
|
|
|
|
+
|
|
|
|
|
+### Important Components
|
|
|
|
|
+
|
|
|
|
|
+1. **Main Layout** (`/webui/components/main-layout.tsx`)
|
|
|
|
|
+ - Provides consistent layout with sidebar and status bar
|
|
|
|
|
+ - Includes `Sidebar` and `ModelStatusBar` components
|
|
|
|
|
+
|
|
|
|
|
+2. **Sidebar** (`/webui/components/sidebar.tsx`)
|
|
|
|
|
+ - Fixed position navigation (z-index: 40)
|
|
|
|
|
+ - Always visible on the left side
|
|
|
|
|
+ - Handles page navigation
|
|
|
|
|
+
|
|
|
|
|
+3. **Model Status Bar** (`/webui/components/model-status-bar.tsx`)
|
|
|
|
|
+ - Fixed position at bottom (z-index: 35)
|
|
|
|
|
+ - Positioned with `left-64` to avoid overlapping sidebar
|
|
|
|
|
+ - Shows current model status, queue status, and generation progress
|
|
|
|
|
+ - Polls server every 1-5 seconds for updates
|
|
|
|
|
+
|
|
|
|
|
+4. **Prompt Textarea** (`/webui/components/prompt-textarea.tsx`)
|
|
|
|
|
+ - Advanced textarea with syntax highlighting
|
|
|
|
|
+ - Autocomplete for LoRAs and embeddings
|
|
|
|
|
+ - Suggestions dropdown (z-index: 30 - below sidebar)
|
|
|
|
|
+ - Highlights LoRA tags (`<lora:name:weight>`) and embedding names
|
|
|
|
|
+
|
|
|
|
|
+### Z-Index Layering
|
|
|
|
|
+
|
|
|
|
|
+The WebUI uses a specific z-index hierarchy to ensure proper stacking:
|
|
|
|
|
+
|
|
|
|
|
+```
|
|
|
|
|
+Sidebar: z-40 (always on top for navigation)
|
|
|
|
|
+Model Status Bar: z-35 (visible but doesn't block sidebar)
|
|
|
|
|
+Autocomplete Dropdowns: z-30 (below sidebar to allow navigation)
|
|
|
|
|
+Main Content: z-0 (default)
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+**Important**: When adding new floating/fixed elements, respect this hierarchy to avoid blocking the sidebar navigation.
|
|
|
|
|
+
|
|
|
|
|
+### Form State Persistence
|
|
|
|
|
+
|
|
|
|
|
+All generation pages (text2img, img2img, upscaler) use localStorage to persist form state across navigation.
|
|
|
|
|
+
|
|
|
|
|
+**Implementation** (`/webui/lib/hooks.ts`):
|
|
|
|
|
+
|
|
|
|
|
+```typescript
|
|
|
|
|
+// Custom hook for localStorage persistence
|
|
|
|
|
+const [formData, setFormData] = useLocalStorage('page-form-data', defaultValues);
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+**Keys used**:
|
|
|
|
|
+- `text2img-form-data` - Text-to-image form state
|
|
|
|
|
+- `img2img-form-data` - Image-to-image form state
|
|
|
|
|
+- `upscaler-form-data` - Upscaler form state
|
|
|
|
|
+
|
|
|
|
|
+**Behavior**:
|
|
|
|
|
+- Form state is automatically saved to localStorage on every change
|
|
|
|
|
+- State is restored when returning to the page
|
|
|
|
|
+- Users can navigate away and return without losing their settings
|
|
|
|
|
+- Large base64 images (img2img, upscaler) are also persisted but may hit localStorage size limits (~5-10MB)
|
|
|
|
|
+
|
|
|
|
|
+### API Client
|
|
|
|
|
+
|
|
|
|
|
+The WebUI communicates with the REST API via `/webui/lib/api.ts`:
|
|
|
|
|
+
|
|
|
|
|
+```typescript
|
|
|
|
|
+import { apiClient } from '@/lib/api';
|
|
|
|
|
+
|
|
|
|
|
+// Examples
|
|
|
|
|
+const models = await apiClient.getModels('checkpoint');
|
|
|
|
|
+const job = await apiClient.text2img(formData);
|
|
|
|
|
+const status = await apiClient.getJobStatus(jobId);
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+**Base URL Configuration**: The API base URL is configured in `/webui/.env.local` and defaults to the server's configured endpoint.
|
|
|
|
|
+
|
|
|
|
|
+### Development Workflow for WebUI
|
|
|
|
|
+
|
|
|
|
|
+1. **Making UI Changes**:
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ cd webui
|
|
|
|
|
+ npm run dev # Start development server on port 3000
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+2. **Building for Production**:
|
|
|
|
|
+ ```bash
|
|
|
|
|
+ # Via CMake (recommended)
|
|
|
|
|
+ cmake --build build --target webui-build
|
|
|
|
|
+
|
|
|
|
|
+ # Or manually
|
|
|
|
|
+ cd webui && npm run build
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+3. **Testing**:
|
|
|
|
|
+ - Development: Changes are hot-reloaded at `http://localhost:3000`
|
|
|
|
|
+ - Production: Build and access via REST server at `http://localhost:8080/ui/`
|
|
|
|
|
+
|
|
|
|
|
+### Common UI Issues and Solutions
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: Sidebar menu items not clickable
|
|
|
|
|
+- **Cause**: Element with higher z-index overlapping sidebar
|
|
|
|
|
+- **Solution**: Ensure all floating elements have z-index < 40
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: Form state lost on navigation
|
|
|
|
|
+- **Cause**: Not using `useLocalStorage` hook
|
|
|
|
|
+- **Solution**: Replace `useState` with `useLocalStorage` for form data
|
|
|
|
|
+
|
|
|
|
|
+**Issue**: Status bar not visible
|
|
|
|
|
+- **Cause**: Z-index too low or hidden behind content
|
|
|
|
|
+- **Solution**: Use z-index 35 and adjust `left` offset to avoid sidebar
|
|
|
|
|
+
|
|
|
|
|
+### WebUI Configuration
|
|
|
|
|
+
|
|
|
|
|
+The server dynamically generates `/ui/config.js` with runtime configuration:
|
|
|
|
|
+
|
|
|
|
|
+```javascript
|
|
|
|
|
+window.SD_REST_CONFIG = {
|
|
|
|
|
+ apiBaseUrl: 'http://localhost:8080',
|
|
|
|
|
+ version: '1.0.0',
|
|
|
|
|
+ features: { /* enabled features */ }
|
|
|
|
|
+};
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+This allows the WebUI to adapt to different server configurations without rebuilding.
|