• Implemented global offline mode for all HuggingFace-dependent modules to eliminate unauthenticated request warnings and prevent external connection attempts during startup and runtime.

   Changes
   • Global Offline Configuration: Added HF_HUB_OFFLINE=1 and TRANSFORMERS_OFFLINE=1 to the environment variables at the top of edit_api.py, embeddings.py, watcher.py, and pose_llm/pose_llm_api.py.
   • Explicit Local Files Only: Updated all huggingface_hub.hf_hub_download calls in edit_api.py to include local_files_only=True, ensuring they never attempt to reach the Hub if models are already cached.
   • LLM Service Optimization: Updated AutoTokenizer and AutoModelForCausalLM calls in pose_llm/pose_llm_api.py to use local_files_only=True.
   • Consistency: Ensured that shared modules like embeddings.py which uses open_clip are also locked to offline mode to prevent background downloads.
This commit is contained in:
mike
2026-06-28 16:56:07 +02:00
parent da1fd4a26c
commit 3b9b9e829b
6 changed files with 881 additions and 239 deletions

View File

@@ -63,6 +63,14 @@ FastAPI :8500 (edit_api.py)
- **Systemd**: `comfyui-api`
- **DB**: PostgreSQL at `192.168.1.160:5433`, database `dv`, table `person`
#### In-Memory File Metadata Cache
To mitigate performance and network latency bottlenecks on remote/shared storage filesystems (e.g. `/mnt/zim`), the API server employs a light, thread-safe in-memory metadata cache (`_file_meta_cache`):
- **Cached Items**: File existence (`exists`) and modification timestamps (`mtime`) mapped by `filename`.
- **Cache TTL**: 5.0 seconds.
- **Idempotency & Invalidation**: Any mutation endpoints (such as crop, padding, duplication, background removal, or deletion) automatically update (`_update_cached_file_meta`) or explicitly delete (`_clear_cached_file_meta`) entries to keep cache and disk perfectly in sync.
- **Preloading Optimization**: Leverages cache queries in static indexing loops (`_sync_preloaded_images`, `_write_all_static`, `list_images`) and tracks changes to completely skip redundant static HTML rewrites if the preloaded image set is identical (`_last_preloaded_images_set`).
#### Endpoints Library
##### Core Generation & Upload
@@ -112,6 +120,12 @@ FastAPI :8500 (edit_api.py)
| `GET` | `/similar/{filename}` | Find visually similar images using database embeddings |
| `GET` | `/names` | Map `filename → person name` |
| `POST` | `/names/{filename}` | Map image file to custom character name |
| `POST` | `/images/{filename}/tags` | Set image tags list (supports tags like `ARCHIVED`, `HIDDEN`, `SOURCE`, `VISIBLE`, `LIKE`, `DISLIKE`, `21+`) |
| `POST` | `/images/{filename}/tag-action` | Add, remove, or toggle a specific tag on an image (automatically handles mutual exclusivity of `LIKE`/`DISLIKE`) |
| `POST` | `/images/{filename}/source` | Explicitly toggle marking an image as a source asset (sets/clears `is_source` and toggles the `SOURCE` tag) |
| `POST` | `/images/{filename}/estimate-21plus` | Analyze image with the WD tagger to estimate adult/sensitive rating and apply `21+` tag |
| `POST` | `/images/bulk-move` | Move a list of filenames to a specific target filmstrip (`VISIBLE`, `HIDDEN`, `ARCHIVED`, `SOURCE`) in bulk, updating tags/columns |
| `POST` | `/images/{filename}/undress` | Queue an asynchronous batch job utilizing the `UNDRESS_PROMPT` on the given reference image |
##### Visibility, Archiving & Deletion
| Method | Path | Purpose |
@@ -192,11 +206,13 @@ prompt
│ set negative: "deformed anatomy, watermark, logo"
├─ Canvas Expansion / Outpainting requested?
│ YES → if outpaint=True, append/use natural outpainting instructions:
"Naturally outpaint and extend the borders of the image to complete the scene."
│ YES → if outpaint=True:
├─ If source is transparent (RGBA): composite onto flat black background for maximum contrast.
│ ├─ Formulate dynamic prompt description: e.g. "replacing the black/white background areas"
│ └─ Append outpainting prompt instructions: "Naturally outpaint and extend..."
├─ Upload reference image(s) to ComfyUI /upload/image
│ image1 = source image
│ image1 = source image (composited RGB if outpainting transparent images)
│ image2 = wireframe pose guide frame (optional)
├─ Patch workflow graph nodes (prompt, size, seed, sampler)
@@ -315,6 +331,9 @@ Model: `buffalo_l`
| faceswap_source_video | TEXT | Source video for faceswapped clips |
| face_embedding | `vector(512)` | Face recognition embedding for visually matching character faces |
| is_source | `BOOLEAN` | Whether the file is a primary reference/source asset |
| tags | TEXT (JSON) | Custom user-applied tags/labels (e.g., `['VISIBLE', 'LIKE', '21+']`) |
| pose_description | TEXT | AI-generated descriptive text of the body pose |
| pose_skeleton | TEXT | Coordinates and scoring details of the 2D COCO-17 body pose skeleton |
---
@@ -352,10 +371,51 @@ To prevent desyncs during image transitions, crops, canvas expansion, or 2.2x zo
- A `ResizeObserver` is registered on the primary studio viewer image (`lbImg`).
- Automatically triggers a layout and geometry recalculation, cleanly and immediately adjusting the background transparency checkerboard grid and padding visual overlays to match the actual visual boundaries of the contained image.
#### Multiple Filmstrips System
The filmstrip bar has been updated with five tabs that filter the group's images dynamically:
- **Group Active**: The default filmstrip containing the main/preferred assets of the group.
- **Group Variant** (`VISIBLE`): Shows all standard visible variants within the group.
- **Hidden** (`HIDDEN`): Soft-hidden variants (excluded from main cycling).
- **Source** (`SOURCE`): Displays reference images explicitly marked as source assets.
- **Archived** (`ARCHIVED`): Displays soft-archived variants.
- **Drag-and-Drop Reclassification**: Users can drag any variant thumbnail from the filmstrip and drop it directly onto any of the tab buttons to instantly update its tag/status and reassign it to that list.
#### Bulk Multi-Select & Actions
Toggling the **Multi-select** button unlocks checkbox-based selection across the filmstrip:
- Provides a live selection counter.
- Enables bulk move/reclassification buttons to dispatch batch updates to `/images/bulk-move` (e.g., `Move to Group`, `Move to Hidden`, `Move to Source`, `Move to Archived`).
#### Seamless Non-Blinking State Updates
To prevent irritating browser reload blinks or blank screen latency during intensive image editing operations:
- **Local Metadata Cloning**: Duplication, manual cropping, padding, and background removal immediately clone the original's DB metadata values locally on the client and splice the new file record into the active filmstrip list.
- **Optimistic Merge**: During periodic background server syncs (`refreshNow`), an optimistic merge algorithm compares the local client-side list and the server JSON. It preserves any freshly created local assets that haven't yet been processed/synced on the backend, maintaining perfect continuity.
#### Studio Keyboard Shortcuts Reference
| Key | Action | Description |
|-----|--------|-------------|
| `P` | Toggle Privacy Mode | Replaces the page with a discrete "AI Assist" study-chat and disguises taskbar thumbnails. |
| `C` | Toggle Checkerboard | Toggle transparent background checkerboard grid. |
| `A` | Expand/Pad Canvas | Instantly trigger the manual padding toolbar. |
| `G` / `Alt+Enter` | Trigger Generation | Clicks the main "Generate" button (when Generate tab is active). |
| `ArrowLeft` / `ArrowRight` | Nav Filmstrip | Cycle through the current list of image variants (debounced). |
| `Home` / `End` | Jump to Bounds | Instantly jump to the first or last variant in the filmstrip. |
| `Space` | Play/Pause Video | Pauses or plays a running wireframe/clip inside the viewer. |
| `H` | Toggle Hidden | Reclasses the image between standard variants and hidden list. |
| `F` | Set as Preferred | Reorders the group, placing the current image at index 0 (as preferred thumbnail). |
| `S` | Toggle Source | Mark/unmark current image as a primary reference/source asset. |
| `E` | Run 21+ Tagger | Analyze image via WD tagger and apply/remove the `21+` tag. |
| `Delete` | Soft-Archive | Move the current image into the Archive filmstrip. |
| `ArrowUp` / `ArrowDown` | Shift Order | Move/reorder the current image earlier or later in the group (debounced). |
| `2` | Move to Second | Instantly reorder current image to the 2nd position in the group. |
| `9` | Move to Last-1 | Instantly reorder current image to the second to last position. |
| `Escape` | Cancel / Dismiss | Cancel cropping, padding, close variant picker, or exit selection mode. |
**Key state variables**:
- `lbCurrentGid` — active group ID
- `lbIdx` — current filmstrip position
- `_followLatestGid` — auto-follow newly generated image
- `_followLatestFilename` — auto-follow specific new output file
- `_sbSelectedAngles` — selected camera angle names
- `_sbWireframeRef` / `_sbWireframeTime` — wireframe video + frame time
- `privacyMode` — privacy overlay toggle (key: `P`)