Commit Graph

48 Commits (e0faa149dd3a20fd6ef4f69a750f3457fb4a950e)

Author SHA1 Message Date
vladmandic e0faa149dd cleanup
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-13 14:44:58 +01:00
vladmandic a2624bebdc merge: modules/api/endpoints.py 2026-03-12 14:16:50 +01:00
vladmandic 20e8b8ab18 add upload api endpoint
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-09 16:02:05 +01:00
Vladimir Mandic e5c494f999 cleanup logger 2026-02-19 11:09:13 +01:00
Vladimir Mandic a3074baf8b unified logger 2026-02-19 09:46:42 +01:00
Vladimir Mandic bfe014f5da modernize typing 2026-02-19 09:15:37 +01:00
Vladimir Mandic 41f206dec9
Merge pull request #4637 from CalamitousFelicitousness/refactor/remove-face-restoration
Refactor/remove face restoration
2026-02-11 11:12:34 +01:00
CalamitousFelicitousness 6c20e49897 refactor(caption): extract caption API into standalone module
Move all caption/interrogate/tagger/VQA API code out of the monolithic
endpoints.py and models.py into a new self-contained modules/api/caption.py,
following the loras.py / nudenet.py self-registering pattern.

- Move 15 Pydantic models (ReqCaption, ResCaption, ReqVQA, ResVQA,
  ReqTagger, ResTagger, dispatch union types, etc.) from models.py
- Move 11 handler functions from endpoints.py
- Deduplicate ~150 lines via shared _do_openclip, _do_tagger, _do_vqa
  core functions called by both direct and dispatch endpoints
- Add register_api() that registers all 8 caption routes
- Add promptgen field to ResVLMPrompts (bug fix: handler returned it
  but response model silently dropped it)
- Improve all endpoint docstrings and Field descriptions for API docs
2026-02-11 02:50:06 +00:00
CalamitousFelicitousness 443a73b740 refactor(caption): code review fixes for offload, inference, and maintainability
Comprehensive review of modules/caption/ addressing memory management,
consistency, and code quality:

Inference correctness:
- Add devices.inference_context() to _qwen(), _smol(), _sa2() handlers
- Remove redundant @torch.no_grad() decorator from joycaption predict()
- Remove dead dtype=torch.bfloat16 kwarg from Florence loader

Memory management:
- Bound moondream3 image cache with LRU eviction (max 8 entries)
- Replace fragile id(image) cache keys with content-based md5 hash
- Add devices.torch_gc() after model loading in deepseek
- Move deepbooru model to CPU before dropping reference on unload
- Add external handler delegation to VQA.unload() (moondream3,
  joycaption, joytag, deepseek)
- Protect batch offload mutation with try/finally

Code deduplication:
- Extract strip_think_xml_tags() shared helper for Qwen/Gemma/SmolVLM
- Extract save_tags_to_file() into tagger.py from deepbooru and
  waifudiffusion

Documentation and clarity:
- Document deepseek global monkey-patches (LlamaFlashAttention2, attrdict)
- Document Florence task="task" as intentional design choice
- Add vendored-code comment to joytag.py
- Document openclip direct .to() usage vs sd_models.move_model
- Comment model.eval() calls that are required (trust_remote_code,
  custom loaders) vs removed where redundant (standard from_pretrained)

API robustness:
- Add HTTP 422 error response for VQA caption error strings in API
  endpoints (post_vqa, _dispatch_vlm)
2026-02-11 02:48:11 +00:00
CalamitousFelicitousness bf7a72f12e fix(caption): remove dead min_length param, split Florence/PromptGen prompts, fix gaze detection
- Remove caption_openclip_min_length from settings, API models, endpoints, and UI
  (clip_interrogator library has no min_length support; parameter was never functional)
- Split vlm_prompts_florence into base Florence prompts and PromptGen-only prompts
  (GENERATE_TAGS, Analyze, Mixed Caption require MiaoshouAI PromptGen fine-tune)
- Add 'promptgen' category to /vqa/prompts API endpoint
- Fix gaze detection: move DETECT_GAZE check before generic 'detect ' prefix
  to prevent "Detect Gaze" matching as detect target="Gaze"
- Update test suite: remove min_length tests, fix min_flavors to use mode='best',
  add acceptance-only notes, fix thinking trace detection, improve bracket/OCR tests,
  split Florence/PromptGen test coverage
2026-02-11 02:48:11 +00:00
CalamitousFelicitousness f4b5abde68 refactor: update API for caption module
Update API endpoints and models for caption module rename:
- modules/api/api.py - update imports and endpoint handlers
- modules/api/endpoints.py - update endpoint definitions
- modules/api/models.py - update request/response models
2026-02-11 02:48:11 +00:00
CalamitousFelicitousness 83fa8e39ba refactor(api): update cli tools for DeepBooru tagger migration
- Update cli/api-interrogate.py to use /sdapi/v1/tagger for DeepBooru
- Handle tagger response format (scores dict or tags string)
- Remove DeepBooru test from interrogate endpoint tests
- Update API model descriptions to reference tagger for anime tagging
2026-02-11 02:47:41 +00:00
CalamitousFelicitousness 7825f44581 refactor(api): remove DeepBooru from interrogate endpoint
DeepBooru/DeepDanbooru should only be accessed via the tagger endpoint.
The interrogate endpoint is now exclusively for OpenCLIP/BLIP.

- Remove DeepDanbooru handling from post_interrogate
- Update docstring to reference tagger endpoint for anime tagging
- Simplify code by removing if/else branching
2026-02-11 02:47:40 +00:00
CalamitousFelicitousness a04ba1e482 feat(api): add missing caption API parameters for UI parity
Add prompt field to VQA endpoint and advanced settings to OpenCLIP endpoint
to achieve full parity between UI and API capabilities.

VLM endpoint changes:
- Add prompt field for custom text input (required for 'Use Prompt' task)
- Pass prompt to vqa.interrogate instead of hardcoded empty string

OpenCLIP endpoint changes:
- Add 7 optional per-request override fields: min_length, max_length,
  chunk_size, min_flavors, max_flavors, flavor_count, num_beams
- Add get_clip_setting() helper for override support in openclip.py
- Apply overrides via update_interrogate_params() before interrogation

All new fields are optional with None defaults for backwards compatibility.
2026-02-11 02:47:40 +00:00
CalamitousFelicitousness f431141d2f feat(api): add LLM generation parameters to VQA endpoint
Add optional LLM generation parameters to the VQA API request model,
allowing per-request override of settings:

- max_tokens, temperature, top_k, top_p, num_beams, do_sample
- thinking_mode, prefill, keep_thinking, keep_prefill

Changes:
- Add 10 new optional fields to ReqVQA model with descriptive docs
- Update get_kwargs() to support per-request overrides via singleton
- Add helper functions get_keep_thinking(), get_keep_prefill()
- Update post_vqa endpoint to pass generation kwargs
- Add _generation_overrides instance variable to VQA class
2026-02-11 02:47:40 +00:00
CalamitousFelicitousness ec7934799e feat(api): add caption API endpoints and documentation
Add comprehensive caption/interrogate API with documentation:

- GET /sdapi/v1/interrogate: List available interrogation models
- POST /sdapi/v1/interrogate: Interrogate with OpenCLIP/BLIP/DeepDanbooru
- POST /sdapi/v1/vqa: Caption with Vision-Language Models (VLM)
- GET /sdapi/v1/vqa: List available VLM models
- POST /sdapi/v1/vqa/batch: Batch caption multiple images
- POST /sdapi/v1/tagger: Tag images with WaifuDiffusion/DeepBooru

Updates:
- Add detailed docstrings with usage examples
- Fix analyze_image response parsing for Gradio update dicts
- Add request/response models for all endpoints
2026-02-11 02:47:40 +00:00
CalamitousFelicitousness 8d764951cf refactor(api): remove face restoration endpoints and parameters
- Remove /sdapi/v1/face-restorers route from api.py
- Remove get_restorers() function from endpoints.py
- Remove gfpgan_visibility, codeformer_visibility, codeformer_weight
  fields from ReqProcess model
- Remove GFPGAN and CodeFormer entries from run_extras() signature
  and create_args_for_run dict in postprocessing.py
2026-02-08 22:59:28 +00:00
vladmandic d9a2a21c8c add sampler api endpoints
Signed-off-by: vladmandic <mandic00@live.com>
2026-02-04 13:08:31 +01:00
vladmandic 7bd04e0b5c add /detailers api endpoint
Signed-off-by: vladmandic <mandic00@live.com>
2025-12-06 12:33:52 +01:00
Vladimir Mandic 72a9094b42 better model version detect and experimental pydantic v2
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-09-04 12:41:40 -04:00
Vladimir Mandic 2318f97991 manual set dtype via api
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-08-14 15:35:50 -04:00
Vladimir Mandic 2aa917b58e add /sdapi/v1/modules endpoint
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-08-12 15:09:08 -04:00
Vladimir Mandic 73049f7bb8 add load-checkpoint api endpoint and test all models script
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-08-09 14:06:54 -04:00
Vladimir Mandic b2a52a146b fix ansi controle output and add model locking
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-07-06 12:50:09 -04:00
Vladimir Mandic e8b5ea3847 major refactor: remove backend original
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-07-05 13:16:46 -04:00
Vladimir Mandic 42b3e08e65 Control add setting to run hires with or without control
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-06-25 18:43:29 -04:00
Vladimir Mandic f8977d2f01 add /sdapi/v1/controlnets api endpoint
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-06-25 15:54:43 -04:00
Vladimir Mandic 3d52e3fe9f add /sdapi/v1/lora endpoint
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-06-25 10:54:02 -04:00
Vladimir Mandic 78e22350b9 add api get-checkpoint
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-05-07 10:31:06 -04:00
Vladimir Mandic 57da399a1e fix api checkpoint list
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-04-29 17:20:29 -04:00
Vladimir Mandic 10fb362bdc server state history
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-04-25 12:25:30 -04:00
Vladimir Mandic b5031a5eba lora modularize code
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-04-01 13:39:47 -04:00
Vladimir Mandic dbfd59434f add gemma3
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-03-15 15:30:57 -04:00
Vladimir Mandic e95bd93f67 caption ui redesign
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-02-15 12:57:19 -05:00
Vladimir Mandic 2963ce127c refactor interrogate/caption
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-02-01 15:40:19 -05:00
Vladimir Mandic 654f44f66f refactor interrogate/analyze/vqa code
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2025-02-01 11:47:20 -05:00
Vladimir Mandic 6aa7a4707e modules.lora full integration
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2024-11-29 09:39:38 -05:00
Vladimir Mandic 2e08a26d53 add latent history
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2024-10-08 09:23:16 -04:00
Vladimir Mandic 3bbcc33181 add detailer
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2024-10-07 09:32:56 -04:00
Vladimir Mandic 04a5071249 face-hires -> detailer refactor
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2024-10-06 11:23:33 -04:00
Vladimir Mandic 9bc217644d improve metadata parser 2024-06-06 11:24:31 -04:00
Vladimir Mandic 1227e76128 initial control api draft 2024-03-26 19:30:31 -04:00
Vladimir Mandic 902f02300d add vqa api 2024-03-26 09:24:01 -04:00
Vladimir Mandic 1b44a16a4e merge process and interrogate, add exif handler 2024-03-03 13:36:10 -05:00
Vladimir Mandic 537170fa2d fix api info endpoint 2024-02-28 11:11:48 -05:00
Vladimir Mandic 19e5062fa8 fix interrogate api 2024-02-10 09:13:07 -05:00
Vladimir Mandic b79d8ea6c3 cleanup api model defs 2024-01-28 10:25:26 -05:00
Vladimir Mandic 7e447222a1 refactor api 2024-01-28 10:13:09 -05:00