Metadata-Version: 2.5
Name: argus-lens
Version: 0.16.0
Summary: Intent-aware, multi-model captioning pipeline for LoRA training, dataset curation, and generative AI workflows
Project-URL: Homepage, https://dragonhound.dev/packages/lens/
Project-URL: Documentation, https://docs.dragonhound.dev/packages/lens/
Project-URL: Demo, https://lightbox.dragonhound.dev/
Project-URL: Repository, https://github.com/smk762/argus-lens
Project-URL: Issues, https://github.com/smk762/argus-lens/issues
Project-URL: Changelog, https://github.com/smk762/argus-lens/blob/main/CHANGELOG.md
Author: smk762
License-Expression: MIT
License-File: LICENSE
Keywords: annotation,blip,captioning,dataset,diffusion,florence,flux,image,lora,sdxl,stable-diffusion,structured-captions,tagging,training,wd14
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: argus-cortex[remote]<0.19,>=0.18.0
Requires-Dist: certifi>=2026.10.19
Requires-Dist: httpx>=0.27
Requires-Dist: pillow>=13.0
Requires-Dist: structlog>=24.0
Provides-Extra: all
Requires-Dist: argus-cortex[gpu,remote,yaml]<0.19,>=0.18.0; extra == 'all'
Requires-Dist: argus-cortex[postgres,s3]<0.19,>=0.18.0; extra == 'all'
Requires-Dist: argus-cortex[server]<0.19,>=0.18.0; extra == 'all'
Requires-Dist: fastapi>=0.110; extra == 'all'
Requires-Dist: numpy>=1.24; extra == 'all'
Requires-Dist: onnxruntime>=1.16; extra == 'all'
Requires-Dist: openai>=1.30; extra == 'all'
Requires-Dist: psycopg[binary]>=3.1; extra == 'all'
Requires-Dist: python-multipart>=0.0.7; extra == 'all'
Requires-Dist: replicate>=0.25; extra == 'all'
Requires-Dist: rich>=13.0; extra == 'all'
Requires-Dist: safetensors>=0.4; extra == 'all'
Requires-Dist: torch>=2.1; extra == 'all'
Requires-Dist: transformers>=4.46; extra == 'all'
Requires-Dist: typer>=0.12; extra == 'all'
Requires-Dist: uvicorn>=0.27; extra == 'all'
Provides-Extra: cli
Requires-Dist: rich>=13.0; extra == 'cli'
Requires-Dist: typer>=0.12; extra == 'cli'
Provides-Extra: dev
Requires-Dist: argus-cortex[remote,yaml]<0.19,>=0.18.0; extra == 'dev'
Requires-Dist: httpx2>=2.7; extra == 'dev'
Requires-Dist: interrogate>=1.7; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff==0.15.16; extra == 'dev'
Provides-Extra: eval
Requires-Dist: torch>=2.1; extra == 'eval'
Requires-Dist: transformers>=4.46; extra == 'eval'
Provides-Extra: lineage
Requires-Dist: argus-cortex[postgres,s3]<0.19,>=0.18.0; extra == 'lineage'
Provides-Extra: local
Requires-Dist: argus-cortex[gpu,remote,yaml]<0.19,>=0.18.0; extra == 'local'
Requires-Dist: numpy>=1.24; extra == 'local'
Requires-Dist: onnxruntime>=1.16; extra == 'local'
Requires-Dist: safetensors>=0.4; extra == 'local'
Requires-Dist: torch>=2.1; extra == 'local'
Requires-Dist: transformers>=4.46; extra == 'local'
Provides-Extra: openai
Requires-Dist: openai>=1.30; extra == 'openai'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
Provides-Extra: replay
Requires-Dist: psycopg[binary]>=3.1; extra == 'replay'
Provides-Extra: replicate
Requires-Dist: replicate>=0.25; extra == 'replicate'
Provides-Extra: server
Requires-Dist: argus-cortex[server]<0.19,>=0.18.0; extra == 'server'
Requires-Dist: fastapi>=0.110; extra == 'server'
Requires-Dist: python-multipart>=0.0.7; extra == 'server'
Requires-Dist: uvicorn>=0.27; extra == 'server'
Provides-Extra: supabase
Requires-Dist: supabase<3,>=2.34; extra == 'supabase'
Provides-Extra: torch
Requires-Dist: argus-cortex[gpu,remote,yaml]<0.19,>=0.18.0; extra == 'torch'
Requires-Dist: safetensors>=0.4; extra == 'torch'
Requires-Dist: torch>=2.1; extra == 'torch'
Requires-Dist: transformers>=4.46; extra == 'torch'
Provides-Extra: wd14
Requires-Dist: numpy>=1.24; extra == 'wd14'
Requires-Dist: onnxruntime>=1.16; extra == 'wd14'
Provides-Extra: wd14-gpu
Requires-Dist: argus-cortex[gpu,remote,yaml]<0.19,>=0.18.0; extra == 'wd14-gpu'
Requires-Dist: numpy>=1.24; extra == 'wd14-gpu'
Requires-Dist: onnxruntime-gpu>=1.16; extra == 'wd14-gpu'
Description-Content-Type: text/markdown

<h1>
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/smk762/argus-cortex/dev/brand/packages/lens/argus-lens-lockup-dark.svg">
    <img alt="Argus Lens" src="https://raw.githubusercontent.com/smk762/argus-cortex/dev/brand/packages/lens/argus-lens-lockup-light.svg" height="52">
  </picture>
</h1>

[![PyPI](https://img.shields.io/pypi/v/argus-lens)](https://pypi.org/project/argus-lens/)
[![Python](https://img.shields.io/pypi/pyversions/argus-lens)](https://pypi.org/project/argus-lens/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/smk762/argus-lens/blob/main/LICENSE)
[![CI](https://github.com/smk762/argus-lens/actions/workflows/ci.yml/badge.svg)](https://github.com/smk762/argus-lens/actions/workflows/ci.yml)
[![dragonhound.dev](https://img.shields.io/badge/dragonhound.dev-argus--lens-1d5f74)](https://dragonhound.dev/packages/lens/)
[![Docs](https://img.shields.io/badge/docs-docs.dragonhound.dev-2a4a7a)](https://docs.dragonhound.dev/packages/lens/)
[![Live demo](https://img.shields.io/badge/live_demo-lightbox.dragonhound.dev-8f6210)](https://lightbox.dragonhound.dev/)

Captions built for how they will be used. Argus Lens runs a tagger and a vision model over an image, then
assembles their output into structured caption variants for LoRA training, dataset curation and zero-shot
generation, and reports everything it removed and why.

The model is only an input. The work is in the assembly pipeline that runs after it, which every backend's
output goes through.

**See it run:** [Lightbox](https://lightbox.dragonhound.dev) is a live demo with real captions, every variant,
and what each step removed.

## One photo, in and out

<img alt="A lake at dusk with a small island, a hill on the horizon and lit buildings on the far shore" src="https://raw.githubusercontent.com/smk762/argus-lens/dev/docs/img/example-lake.jpg" width="300" align="right">

What the models said (`hybrid:ram+florence2`):

> **Tags:** lake, water, mountain, island, sunset, dusk, calm, sky, cloudy, twilight, night view
>
> **Prose:** The image is a landscape photograph of a lake at sunset. The sky is a beautiful orange and pink
> color, with the sun setting in the background. The lake is calm and still, reflecting the colors of the sky.
> [...] The mountains in the distance are silhouetted against the sky, creating a stunning view. The overall
> mood of the photograph is peaceful and serene.

What Lens made of it, for an SDXL target (60 CLIP tokens):

| Variant | Caption |
|---|---|
| `training` | dusk, sunset, sky, mountain, water, island, calm, cloudy |
| `training_prose` | A landscape photograph of a lake at sunset. The sky is a beautiful orange and pink color, with the sun setting in the background. |
| `lighting` | sunset, dusk, twilight, night view, water, island |
| `setting` | lake, mountain, sky, the sky is a beautiful orange and pink color, with the sun setting in the background, water, island, calm |

And what it reported removing: the opener ("The image is"), the editorial lines ("creating a stunning view",
"The overall mood of the photograph is peaceful and serene"), and each prose clause that only repeated a tag.

This is one of the 240 captions in the [eval fixture](https://github.com/smk762/argus-lens/blob/dev/eval/agent_query/README.md), from a CC0 photo, with
no LLM rewrite. There are nine variants per image: one per category (identity, wardrobe, pose and composition,
setting, lighting, action) plus `training`, `training_prose` and `zeroshot`.

## Quick start

```bash
pip install "argus-lens[openai]"
```

```python
from argus_lens import ArgusLens

engine = ArgusLens(backend="openai", api_key="sk-...")
result = engine.caption("photo.jpg", trigger_word="sks_person")

print(result.final_caption)
print(result.caption_variants["training"])
print(result.removed_phrases)
```

```bash
pip install "argus-lens[cli,local]"
argus-lens caption ./images/ --backend hybrid --format txt   # one .txt sidecar per image
```

Local backends need a GPU or a patient CPU; cloud and self-hosted OpenAI-compatible backends (Ollama, vLLM,
LM Studio) need neither. [Installation](https://github.com/smk762/argus-lens/blob/dev/docs/install.md) lists the extras and
[Usage](https://github.com/smk762/argus-lens/blob/dev/docs/usage.md) has more examples.

## What the assembly pipeline does

1. **Classify.** Every tag and prose clause goes into a bucket: identity, wardrobe, pose and composition,
   setting, lighting or action.
2. **Filter.** Prose that mostly repeats the tags (over 50% overlap), filler openers ("The image shows...")
   and training noise (rating tags, meta tokens) are removed.
3. **Specialise.** The training variant leaves out identity traits, because a LoRA learns those from the
   pixels and stating them fights the base model's prior. The zero-shot variant puts identity first, because
   no LoRA will supply it.
4. **Budget.** Fragments are assembled under the target's token limit: 60 for SDXL (CLIP), 200 for Flux and
   SD3 (T5). Framing tags are never dropped, and short generic tags go first.
5. **Diversify.** Across a dataset, omission cycles leave out a different bucket per image, so a concept is
   not tied to one phrasing.
6. **Enrich.** Compound nouns found only in the prose ("gray sweater", "wooden door") are added last, to use
   what budget remains.

Every removed phrase and every compaction decision is in the result (`removed_phrases`, `compaction_notes`),
so a caption can be audited. The [caption result reference](https://github.com/smk762/argus-lens/blob/dev/docs/caption-result.md) documents each field.

## What else it does

| | | Read more |
|---|---|---|
| **Backends** | WD14, RAM++, Florence-2 and BLIP-2 locally; OpenAI, Hugging Face, Replicate, NVIDIA NIM and any OpenAI-compatible server; hybrids that pair a tagger with a prose model | [Backends and prompts](https://github.com/smk762/argus-lens/blob/dev/docs/backends.md) |
| **Reconciliation** | Where prose and tags disagree on a colour, posture, headcount or a quoted name, a verifier decides: the tags, a vision model, OCR, or a measured pose | [Reconciliation](https://github.com/smk762/argus-lens/blob/dev/docs/reconciliation.md) |
| **Refinement** | An optional LLM rewrite, accepted only if it passes the same checks as the deterministic caption | [Refinement](https://github.com/smk762/argus-lens/blob/dev/docs/refinement.md) |
| **Evaluation** | A reference-free harness: tag and prose contradiction rate, token-budget adherence, redundancy, optional CLIPScore and a VLM faithfulness judge, and a flag that fails a run on regression | [Evaluation](https://github.com/smk762/argus-lens/blob/dev/docs/evaluation.md) |
| **CLI and server** | `argus-lens caption`, `eval` and `serve`; a FastAPI server with batch, streaming, folder and manifest endpoints and an OpenAI-compatible `/v1` | [CLI reference](https://github.com/smk762/argus-lens/blob/dev/docs/cli.md), [HTTP server](https://github.com/smk762/argus-lens/blob/dev/docs/server.md) |
| **Photo libraries** | Captions and keywords pushed to Immich, or written as XMP sidecars that Immich, Lightroom and digiKam read | [Immich](https://github.com/smk762/argus-lens/blob/dev/docs/immich.md) |
| **Dataset export** | Captions as a relational dataset in Postgres or Supabase, with thumbnails, a change feed and pgvector search | [Dataset export](https://github.com/smk762/argus-lens/blob/dev/docs/dataset-export.md) |
| **GPU sharing** | Lazy loading, idle unload, and a lease so several services take turns on one card | [GPU sharing](https://github.com/smk762/argus-lens/blob/dev/docs/gpu-sharing.md) |
| **Replay** | Serve recorded captions with no model and no GPU, for demos | [Replay](https://github.com/smk762/argus-lens/blob/dev/docs/replay.md) |
| **Deployment** | A CUDA image and a standalone image on GHCR | [Docker](https://github.com/smk762/argus-lens/blob/dev/docs/docker.md) |

## How it is checked

- **Tests.** About 1,500, run twice in CI: without torch, and again with CPU torch so the model-gated tests run.
- **Rules with a named test.** Each thing that must never happen (a batch overwriting a caption on a name
  collision, a fetch reaching an internal address, a failed OCR read silently dropping a claim) is listed in
  [CLAUDE.md](https://github.com/smk762/argus-lens/blob/dev/CLAUDE.md) beside the test that enforces it.
- **Measured, not asserted.** The caption eval scores a change against a baseline. A second eval asks whether
  an agent can answer questions about exported captions, in three arms over 40 checked tasks:

  | Model | Schema in the prompt | Supabase MCP | MCP + docs for agents |
  |---|---|---|---|
  | Claude Haiku 5.5 | 76.7% | 100% | 100% |
  | Gemini 3.5 Flash-Lite | 68.3% | 93.3% | 100% |
  | `qwen3:8b` (local) | 56.7% | 38.3% | 68.3% |

  The [write-up](https://github.com/smk762/argus-lens/blob/dev/docs/supabase-writeup.md) covers the method, the noise floor, the arm that made a small
  model worse, and what building on Supabase was like ([friction log](https://github.com/smk762/argus-lens/blob/dev/docs/supabase-friction-log.md)). Two
  fixes found along the way are proposed upstream:
  [supabase/postgres#2741](https://github.com/supabase/postgres/pull/2741) and
  [supabase/vecs#123](https://github.com/supabase/vecs/pull/123).

## Security

- The server binds to `127.0.0.1` by default. Its caption endpoints have no authentication, so expose it only
  on a network you trust. Cross-site writes are refused whatever the CORS setting.
- URL fetches are fenced against internal addresses, and folder and manifest paths cannot leave the source root.
- No Python from a model repository runs unless `HF_TRUST_REMOTE_CODE=true` is set.

Details are in [HTTP server](https://github.com/smk762/argus-lens/blob/dev/docs/server.md) and
[Backends and prompts](https://github.com/smk762/argus-lens/blob/dev/docs/backends.md#remote-code-trust_remote_code).

## Part of the Argus suite

```
argus-quarry -> argus-curator -> argus-lens -> argus-forge -> your trainer -> argus-proof
```

Lens is the captioning stage. [argus-studio](https://github.com/smk762/argus-studio) is a web UI over it, and
the suite's docs are at [docs.dragonhound.dev](https://docs.dragonhound.dev/packages/lens/).

## License

MIT. The vendored RAM++ port in `backends/_ram/` is Apache-2.0, with Microsoft's MIT-licensed Swin
([LICENSE-RAM](https://github.com/smk762/argus-lens/blob/dev/src/argus_lens/backends/_ram/LICENSE-RAM)).
