alignlyPhotos 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- alignlyphotos-0.3.0/.gitignore +16 -0
- alignlyphotos-0.3.0/CHANGELOG.md +51 -0
- alignlyphotos-0.3.0/PKG-INFO +298 -0
- alignlyphotos-0.3.0/README.md +282 -0
- alignlyphotos-0.3.0/pyproject.toml +48 -0
- alignlyphotos-0.3.0/src/alignlyphotos/__init__.py +58 -0
- alignlyphotos-0.3.0/src/alignlyphotos/adapters.py +147 -0
- alignlyphotos-0.3.0/src/alignlyphotos/batch.py +144 -0
- alignlyphotos-0.3.0/src/alignlyphotos/card.py +147 -0
- alignlyphotos-0.3.0/src/alignlyphotos/check.py +282 -0
- alignlyphotos-0.3.0/src/alignlyphotos/cli.py +272 -0
- alignlyphotos-0.3.0/src/alignlyphotos/evaluate.py +169 -0
- alignlyphotos-0.3.0/src/alignlyphotos/images.py +203 -0
- alignlyphotos-0.3.0/src/alignlyphotos/mcp_server.py +148 -0
- alignlyphotos-0.3.0/src/alignlyphotos/model.py +182 -0
- alignlyphotos-0.3.0/src/alignlyphotos/report.py +98 -0
- alignlyphotos-0.3.0/src/alignlyphotos/scorer.py +453 -0
- alignlyphotos-0.3.0/tests/conftest.py +199 -0
- alignlyphotos-0.3.0/tests/test_adapters.py +129 -0
- alignlyphotos-0.3.0/tests/test_batch.py +98 -0
- alignlyphotos-0.3.0/tests/test_card.py +74 -0
- alignlyphotos-0.3.0/tests/test_check.py +254 -0
- alignlyphotos-0.3.0/tests/test_cli.py +141 -0
- alignlyphotos-0.3.0/tests/test_evaluate.py +85 -0
- alignlyphotos-0.3.0/tests/test_mcp.py +68 -0
- alignlyphotos-0.3.0/tests/test_model.py +18 -0
- alignlyphotos-0.3.0/tests/test_retries.py +69 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
Renamed from `brandcheck` to `alignlyPhotos`. Install with `pip install alignlyPhotos`, import
|
|
6
|
+
`alignlyphotos`, run `alignlyphotos` and `alignlyphotos-mcp`. Versions up to 0.2.0 were
|
|
7
|
+
published as `brandcheck`.
|
|
8
|
+
|
|
9
|
+
Changed, and not compatible with 0.2 (see "Moving from 0.2 to 0.3" in the README):
|
|
10
|
+
- Cards are written in Python (`Card` and `Rule`). Each rule says what a photo that `meets` it
|
|
11
|
+
shows and what signs mean it `misses`.
|
|
12
|
+
- Each rule is asked in its own model call, and a photo's calls run at once. `calls="one"` or a
|
|
13
|
+
list of groups packs rules into fewer calls.
|
|
14
|
+
- Each rule comes back as a level (`meets`, `mixed`, `misses`, `cannot_assess` or
|
|
15
|
+
`not_applicable`) with a justification, in place of a 0-100 score.
|
|
16
|
+
- Rules that only apply to some kinds of photo are skipped, using one extra call that asks what
|
|
17
|
+
kind of photo it is.
|
|
18
|
+
- `alignlyphotos check` replaces `score`. `evaluate` compares levels per rule with people's labels.
|
|
19
|
+
- Removed: `make_card`, JSON and Markdown cards, weights, must-pass, the brand score,
|
|
20
|
+
`show-card`, `edit-card` and `--min-score`.
|
|
21
|
+
- The scorer lives in `alignlyphotos.scorer` and is the same code the Alignly app runs.
|
|
22
|
+
|
|
23
|
+
## 0.2.0 (published as brandcheck)
|
|
24
|
+
|
|
25
|
+
New:
|
|
26
|
+
- `brandcheck score` takes folders and scores several photos at a time (`--workers`, default 4).
|
|
27
|
+
One photo failing no longer stops the rest.
|
|
28
|
+
- Retries: a timeout, dropped connection, busy server (429 or 5xx) or broken JSON is tried again,
|
|
29
|
+
waiting 2, 5 then 10 seconds (`--retries`, default 2). Missing settings or a wrong key stop the
|
|
30
|
+
whole run straight away with a clear message.
|
|
31
|
+
- `--csv FILE`: one row per photo, best first, with a column per rule.
|
|
32
|
+
- `--html FILE`: a single-file report with thumbnails, scores and the reasons for each photo.
|
|
33
|
+
- `--cache DIR`: photos already scored with the same card, settings and model are not sent again.
|
|
34
|
+
- `--min-score N`: exit code 3 when any photo scores below N, for automated pipelines.
|
|
35
|
+
- `brandcheck show-card` and `brandcheck edit-card`: review a card as a table and change weights
|
|
36
|
+
or must-pass rules without editing JSON.
|
|
37
|
+
- `brandcheck evaluate`: compare scores with human labels (on-brand yes/no and per-rule scores).
|
|
38
|
+
Reports agreement, off-brand photos caught, the best cut-off, per-rule agreement and the
|
|
39
|
+
biggest disagreements.
|
|
40
|
+
- `AnthropicModel` to run on Claude (`pip install brandcheck[anthropic]`,
|
|
41
|
+
`VISION_MODEL_PROVIDER=anthropic`).
|
|
42
|
+
- `brandcheck-mcp`: brandcheck as tools for chatbots such as Claude Desktop
|
|
43
|
+
(`pip install brandcheck[mcp]`).
|
|
44
|
+
|
|
45
|
+
Changed:
|
|
46
|
+
- `check_photo` results include `cached` (True or False).
|
|
47
|
+
- `score --json` with more than one photo prints a list. Failed photos appear with an `error`.
|
|
48
|
+
|
|
49
|
+
## 0.1.0
|
|
50
|
+
|
|
51
|
+
First release: `make_card`, `check_photo`, `brandcheck make-card` and `brandcheck score`.
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: alignlyPhotos
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Check brand photos against photo rules written in code, with a vision model
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: jsonschema>=4.23
|
|
7
|
+
Requires-Dist: openai<3,>=2
|
|
8
|
+
Requires-Dist: pillow<13,>=11
|
|
9
|
+
Provides-Extra: anthropic
|
|
10
|
+
Requires-Dist: anthropic>=0.40; extra == 'anthropic'
|
|
11
|
+
Provides-Extra: mcp
|
|
12
|
+
Requires-Dist: mcp>=1.23; extra == 'mcp'
|
|
13
|
+
Provides-Extra: test
|
|
14
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# alignlyPhotos
|
|
18
|
+
|
|
19
|
+
Check brand photos against your brand's photo rules with a vision model.
|
|
20
|
+
|
|
21
|
+
You write the rules in Python. For each photo, alignlyPhotos asks the model about every rule and
|
|
22
|
+
gives you, per rule, a level (**meets**, **mixed** or **misses**, or **cannot_assess** /
|
|
23
|
+
**not_applicable**) and a short justification saying what in the photo led to it. It is the
|
|
24
|
+
same scorer the Alignly app uses, so a card gives the same calls and answers in both.
|
|
25
|
+
|
|
26
|
+
Every answer is a suggestion for a person to review, not an approval.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install alignlyPhotos
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Needs Python 3.10 or newer. Extras: `alignlyPhotos[anthropic]` to run on Claude,
|
|
35
|
+
`alignlyPhotos[mcp]` to use it from a chatbot.
|
|
36
|
+
|
|
37
|
+
## Set up the model
|
|
38
|
+
|
|
39
|
+
alignlyPhotos works with any OpenAI-compatible vision model (for example Qwen3-VL served by vLLM,
|
|
40
|
+
Ollama, or OpenAI itself). Set three environment variables, with no quotes inside the values:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
export VISION_MODEL_BASE_URL=https://your-server/v1
|
|
44
|
+
export VISION_MODEL_API_KEY=your-key
|
|
45
|
+
export VISION_MODEL_NAME=your-model-name
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
On Windows PowerShell use `$env:VISION_MODEL_BASE_URL="https://your-server/v1"` and so on.
|
|
49
|
+
|
|
50
|
+
To use Claude instead: `pip install alignlyPhotos[anthropic]`, then set
|
|
51
|
+
`VISION_MODEL_PROVIDER=anthropic`, `ANTHROPIC_API_KEY` and `VISION_MODEL_NAME` (a Claude model
|
|
52
|
+
name).
|
|
53
|
+
|
|
54
|
+
## 1. Write the card
|
|
55
|
+
|
|
56
|
+
A card is a name and all of a brand's rules. Each rule has:
|
|
57
|
+
|
|
58
|
+
- `name`: short and unique within the card.
|
|
59
|
+
- `applies_to`: the kind of photo the rule is about, in plain words, or `None` for every photo.
|
|
60
|
+
- `meets`: one or more lines saying what a photo that follows the rule visibly shows.
|
|
61
|
+
- `misses`: one or more lines naming the visible signs that a photo breaks it.
|
|
62
|
+
- `mixed` (optional): when the photo is in between.
|
|
63
|
+
- `not_a_fault` (optional): things that look like a fault but are fine.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# card.py
|
|
67
|
+
from alignlyphotos import Card, Rule
|
|
68
|
+
|
|
69
|
+
card = Card(
|
|
70
|
+
name="Capital One photography",
|
|
71
|
+
rules=[
|
|
72
|
+
Rule(
|
|
73
|
+
name="Bright, natural light",
|
|
74
|
+
applies_to=None,
|
|
75
|
+
meets=["The scene is bright and evenly lit, like daylight or soft window light."],
|
|
76
|
+
misses=[
|
|
77
|
+
"Shadows across faces or the main subject are dark and hard-edged.",
|
|
78
|
+
"Large parts of the photo are dark or murky.",
|
|
79
|
+
],
|
|
80
|
+
mixed=["The light is mostly natural, but a small area has hard shadows."],
|
|
81
|
+
not_a_fault=["Soft, gradual shadows that give faces and objects shape are fine."],
|
|
82
|
+
),
|
|
83
|
+
Rule(
|
|
84
|
+
name="Real, unposed moments",
|
|
85
|
+
applies_to="lifestyle photos of people in an everyday situation",
|
|
86
|
+
meets=["People are caught in the middle of a real activity."],
|
|
87
|
+
misses=["People have stopped what they are doing to pose for the camera."],
|
|
88
|
+
),
|
|
89
|
+
],
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The model reads each rule exactly as written, one line per sentence. Write lines about what can
|
|
94
|
+
be seen in the photo. A rule without a `meets` or `misses` line, an empty line, or two rules with
|
|
95
|
+
the same name are refused when the card is made.
|
|
96
|
+
|
|
97
|
+
## 2. Check photos
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from alignlyphotos import OpenAICompatibleModel, check_photo
|
|
101
|
+
from card import card
|
|
102
|
+
|
|
103
|
+
model = OpenAICompatibleModel.from_env()
|
|
104
|
+
result = check_photo("photo.jpg", card, model)
|
|
105
|
+
for r in result.rules:
|
|
106
|
+
print(r.name, r.level, r.justification)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
By default each rule is asked in its own model call, and all of a photo's calls are sent at
|
|
110
|
+
once. When some rules apply only to a kind of photo, one more call asks which of those kinds the
|
|
111
|
+
photo is; a rule whose kind the photo is not comes back `not_applicable`, decided by that check.
|
|
112
|
+
You can pack rules into fewer calls; the result has the same shape either way:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
check_photo("photo.jpg", card, model, calls="one") # every rule in one call
|
|
116
|
+
check_photo("photo.jpg", card, model, calls=[["Rule A", "Rule B"], ["Rule C"]])
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Rules left out of a `calls` list get a call of their own. One rule per call caught the most
|
|
120
|
+
faults in testing; packing saves tokens.
|
|
121
|
+
|
|
122
|
+
A result has:
|
|
123
|
+
|
|
124
|
+
- `rules`: one `RuleResult` per rule, in card order: `name`, `level`, `justification`,
|
|
125
|
+
`applies_to` and `decided_by` (`model` or `picture_kind_check`).
|
|
126
|
+
- `card`, `card_fingerprint`, `prompt_version` and `model`: what produced it.
|
|
127
|
+
- `calls`: each call's rules, seconds, tries and token counts; `seconds`, `prompt_tokens` and
|
|
128
|
+
`output_tokens` for the photo; `picture_kinds`, the kind check's answers.
|
|
129
|
+
- `to_dict()` for JSON, `count("misses")`, `rule("Rule A")`.
|
|
130
|
+
|
|
131
|
+
Other options: `user_context="live event"` (background for the model), `retries=2` (extra tries
|
|
132
|
+
when a call times out, the server is busy or a reply is broken), `max_calls=8` (calls at once),
|
|
133
|
+
`cache_dir=".alignlyphotos-cache"` (a photo checked with the same card, settings, prompt version
|
|
134
|
+
and model is read back instead of sent again). `photo` can be a path or the file's bytes.
|
|
135
|
+
|
|
136
|
+
Many photos:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from alignlyphotos import check_many, write_csv, write_html
|
|
140
|
+
|
|
141
|
+
rows = check_many(["a.jpg", "b.jpg"], card, model, workers=4, max_calls=16)
|
|
142
|
+
write_csv(rows, "results.csv", card) # one row per photo, a level column per rule
|
|
143
|
+
write_html(rows, "report.html") # thumbnails, levels and justifications
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`workers` photos run at once, and at most `max_calls` model calls are in flight over all of
|
|
147
|
+
them. A photo that fails gets an error in its row and the rest carry on.
|
|
148
|
+
|
|
149
|
+
## Command line
|
|
150
|
+
|
|
151
|
+
The card comes from a Python file that defines `card`:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
alignlyphotos check photo.jpg --card card.py
|
|
155
|
+
alignlyphotos check photos/ --card card.py --csv results.csv --html report.html
|
|
156
|
+
alignlyphotos check photos/ --card card.py --calls one
|
|
157
|
+
alignlyphotos check photos/ --card card.py --calls "Rule A|Rule B;Rule C"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Options: `--context`, `--workers 4`, `--max-calls 16`, `--retries 2`, `--cache DIR`, `--json`,
|
|
161
|
+
`-q`. Exit codes: 0 all good, 1 something failed.
|
|
162
|
+
|
|
163
|
+
Only load card files you trust: loading one runs its code.
|
|
164
|
+
|
|
165
|
+
## Check accuracy against people's labels
|
|
166
|
+
|
|
167
|
+
Make a CSV with a `photo` column (path relative to the CSV) and one column per rule, named
|
|
168
|
+
exactly as the rule, holding `meets`, `mixed`, `misses`, `cannot_assess` or `not_applicable`.
|
|
169
|
+
Blank cells are skipped.
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
photo,"Bright, natural light","Real, unposed moments"
|
|
173
|
+
shoot1/a.jpg,meets,meets
|
|
174
|
+
shoot1/b.jpg,misses,
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
alignlyphotos evaluate labels.csv --card card.py
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The report shows how often alignlyPhotos gave the label's level, a label-against-alignlyPhotos
|
|
182
|
+
table, per rule agreement with the misses caught and the misses given wrongly, and the
|
|
183
|
+
disagreements with alignlyPhotos's justification. In Python: `read_labels` and `evaluate`.
|
|
184
|
+
|
|
185
|
+
## Using a different model
|
|
186
|
+
|
|
187
|
+
Anything with a matching `complete` method works. Pass it in place of `OpenAICompatibleModel`:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from alignlyphotos import ModelReply
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class MyModel:
|
|
194
|
+
def complete(
|
|
195
|
+
self,
|
|
196
|
+
messages,
|
|
197
|
+
schema,
|
|
198
|
+
*,
|
|
199
|
+
name="",
|
|
200
|
+
max_tokens=2048,
|
|
201
|
+
timeout=None,
|
|
202
|
+
logprobs=False,
|
|
203
|
+
require_stop=True,
|
|
204
|
+
):
|
|
205
|
+
# call your model with the OpenAI-style messages, ask for JSON matching `schema`
|
|
206
|
+
return ModelReply(
|
|
207
|
+
content=json_text,
|
|
208
|
+
requested_model="mine",
|
|
209
|
+
returned_model="mine",
|
|
210
|
+
finish_reason="stop",
|
|
211
|
+
usage={"prompt_tokens": 1200, "output_tokens": 90},
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The model has to accept an image with text and return JSON in the requested shape. Return
|
|
216
|
+
`finish_reason="length"` when the reply was cut off. `usage` is optional. The prompts were
|
|
217
|
+
tuned on Qwen3-VL, so check a new model with `alignlyphotos evaluate` first.
|
|
218
|
+
|
|
219
|
+
## Building on top
|
|
220
|
+
|
|
221
|
+
`alignlyphotos.scorer` holds the parts the Alignly app and `check_photo` both use, as plain
|
|
222
|
+
functions on the card's dictionary form (`card.to_dict()`):
|
|
223
|
+
|
|
224
|
+
- `requests_for(card_dict, image_data_url, groups=..., ...)`: every model call of one photo as
|
|
225
|
+
data (`CallRequest`: messages, JSON schema, output budget), the picture-kind check first.
|
|
226
|
+
- `read_reply(request, content, finish_reason)`: checks one reply against its schema and
|
|
227
|
+
returns it, or raises `AnswerFailed` / `AnswerCutOff`.
|
|
228
|
+
- `answers_from(card_dict, replies_by_call_key)`: one answer per rule, applying the kind check.
|
|
229
|
+
- `call_ids(card_dict)`: the id each rule goes by inside the calls, made from its current name,
|
|
230
|
+
so a card with other stored ids (the app keeps them on rename) sends the same calls.
|
|
231
|
+
- `kinds_of`, `rule_block`, `rules_schema`, `SYSTEM`, `INSTRUCTION`, `KINDS_PROMPT`,
|
|
232
|
+
`PROMPT_VERSION`.
|
|
233
|
+
|
|
234
|
+
`alignlyphotos.images.prepare(data).data_url()` makes the photo copy the model sees (upright,
|
|
235
|
+
sRGB, at most 1024 px, JPEG without metadata).
|
|
236
|
+
|
|
237
|
+
## Use it from a chatbot (MCP)
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
pip install alignlyPhotos[mcp]
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Put your card files in `~/.alignlyphotos/cards` (change with `ALIGNLYPHOTOS_HOME`), for example
|
|
244
|
+
`~/.alignlyphotos/cards/capital-one.py`. Then add alignlyPhotos to Claude Desktop's config
|
|
245
|
+
(`claude_desktop_config.json`):
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"mcpServers": {
|
|
250
|
+
"alignlyphotos": {
|
|
251
|
+
"command": "alignlyphotos-mcp",
|
|
252
|
+
"env": {
|
|
253
|
+
"VISION_MODEL_BASE_URL": "https://your-server/v1",
|
|
254
|
+
"VISION_MODEL_API_KEY": "your-key",
|
|
255
|
+
"VISION_MODEL_NAME": "your-model-name"
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
If Claude Desktop can't find `alignlyphotos-mcp`, use its full path instead (run
|
|
263
|
+
`which alignlyphotos-mcp` on Mac/Linux or `where alignlyphotos-mcp` on Windows to get it).
|
|
264
|
+
|
|
265
|
+
Then ask things like "check the photos in ~/shoot1 against capital-one". The chatbot can list
|
|
266
|
+
cards and check photos and folders. It picks cards by name from the cards folder only and cannot
|
|
267
|
+
make or change them.
|
|
268
|
+
|
|
269
|
+
## Moving from 0.2 to 0.3
|
|
270
|
+
|
|
271
|
+
The package was called `brandcheck` up to 0.2. Uninstall it and install `alignlyPhotos`, then
|
|
272
|
+
change `import brandcheck` to `import alignlyphotos`.
|
|
273
|
+
|
|
274
|
+
0.3 breaks 0.2 code and cards. It removes `make_card` (AI guideline-to-card), JSON and
|
|
275
|
+
Markdown cards, 0-100 scores, weights, must-pass, the brand score, confidence, mood words, the
|
|
276
|
+
photo summary, `show-card`, `edit-card` and `--min-score`.
|
|
277
|
+
|
|
278
|
+
- Rewrite the card in Python as `card = Card(...)`. For each old criterion write a `Rule`:
|
|
279
|
+
what the 100 anchor described goes in `meets`, what the 0 or 25 anchors described goes in
|
|
280
|
+
`misses` (one visible sign per line), and drop weights and must-pass. Rule names must be
|
|
281
|
+
unique.
|
|
282
|
+
- `check_photo(photo, card, model)` returns a `PhotoResult`: read `result.rules` (each with
|
|
283
|
+
`level` and `justification`) instead of `result["brand_score"]` and `result["answers"]`.
|
|
284
|
+
Drop `summary=` and `logprobs=`.
|
|
285
|
+
- Command line: `alignlyphotos score photos/ --card card.json` is now
|
|
286
|
+
`alignlyphotos check photos/ --card card.py`. Labels for `evaluate` hold a level per rule name
|
|
287
|
+
instead of scores and `on_brand`.
|
|
288
|
+
- MCP cards are Python files in `~/.alignlyphotos/cards`; the chatbot no longer makes or edits
|
|
289
|
+
them.
|
|
290
|
+
|
|
291
|
+
## Run the tests
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
pip install -e ".[test,mcp,anthropic]"
|
|
295
|
+
pytest
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
The tests use a fake model, so they need no network or API key.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# alignlyPhotos
|
|
2
|
+
|
|
3
|
+
Check brand photos against your brand's photo rules with a vision model.
|
|
4
|
+
|
|
5
|
+
You write the rules in Python. For each photo, alignlyPhotos asks the model about every rule and
|
|
6
|
+
gives you, per rule, a level (**meets**, **mixed** or **misses**, or **cannot_assess** /
|
|
7
|
+
**not_applicable**) and a short justification saying what in the photo led to it. It is the
|
|
8
|
+
same scorer the Alignly app uses, so a card gives the same calls and answers in both.
|
|
9
|
+
|
|
10
|
+
Every answer is a suggestion for a person to review, not an approval.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
pip install alignlyPhotos
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Needs Python 3.10 or newer. Extras: `alignlyPhotos[anthropic]` to run on Claude,
|
|
19
|
+
`alignlyPhotos[mcp]` to use it from a chatbot.
|
|
20
|
+
|
|
21
|
+
## Set up the model
|
|
22
|
+
|
|
23
|
+
alignlyPhotos works with any OpenAI-compatible vision model (for example Qwen3-VL served by vLLM,
|
|
24
|
+
Ollama, or OpenAI itself). Set three environment variables, with no quotes inside the values:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
export VISION_MODEL_BASE_URL=https://your-server/v1
|
|
28
|
+
export VISION_MODEL_API_KEY=your-key
|
|
29
|
+
export VISION_MODEL_NAME=your-model-name
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
On Windows PowerShell use `$env:VISION_MODEL_BASE_URL="https://your-server/v1"` and so on.
|
|
33
|
+
|
|
34
|
+
To use Claude instead: `pip install alignlyPhotos[anthropic]`, then set
|
|
35
|
+
`VISION_MODEL_PROVIDER=anthropic`, `ANTHROPIC_API_KEY` and `VISION_MODEL_NAME` (a Claude model
|
|
36
|
+
name).
|
|
37
|
+
|
|
38
|
+
## 1. Write the card
|
|
39
|
+
|
|
40
|
+
A card is a name and all of a brand's rules. Each rule has:
|
|
41
|
+
|
|
42
|
+
- `name`: short and unique within the card.
|
|
43
|
+
- `applies_to`: the kind of photo the rule is about, in plain words, or `None` for every photo.
|
|
44
|
+
- `meets`: one or more lines saying what a photo that follows the rule visibly shows.
|
|
45
|
+
- `misses`: one or more lines naming the visible signs that a photo breaks it.
|
|
46
|
+
- `mixed` (optional): when the photo is in between.
|
|
47
|
+
- `not_a_fault` (optional): things that look like a fault but are fine.
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# card.py
|
|
51
|
+
from alignlyphotos import Card, Rule
|
|
52
|
+
|
|
53
|
+
card = Card(
|
|
54
|
+
name="Capital One photography",
|
|
55
|
+
rules=[
|
|
56
|
+
Rule(
|
|
57
|
+
name="Bright, natural light",
|
|
58
|
+
applies_to=None,
|
|
59
|
+
meets=["The scene is bright and evenly lit, like daylight or soft window light."],
|
|
60
|
+
misses=[
|
|
61
|
+
"Shadows across faces or the main subject are dark and hard-edged.",
|
|
62
|
+
"Large parts of the photo are dark or murky.",
|
|
63
|
+
],
|
|
64
|
+
mixed=["The light is mostly natural, but a small area has hard shadows."],
|
|
65
|
+
not_a_fault=["Soft, gradual shadows that give faces and objects shape are fine."],
|
|
66
|
+
),
|
|
67
|
+
Rule(
|
|
68
|
+
name="Real, unposed moments",
|
|
69
|
+
applies_to="lifestyle photos of people in an everyday situation",
|
|
70
|
+
meets=["People are caught in the middle of a real activity."],
|
|
71
|
+
misses=["People have stopped what they are doing to pose for the camera."],
|
|
72
|
+
),
|
|
73
|
+
],
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The model reads each rule exactly as written, one line per sentence. Write lines about what can
|
|
78
|
+
be seen in the photo. A rule without a `meets` or `misses` line, an empty line, or two rules with
|
|
79
|
+
the same name are refused when the card is made.
|
|
80
|
+
|
|
81
|
+
## 2. Check photos
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from alignlyphotos import OpenAICompatibleModel, check_photo
|
|
85
|
+
from card import card
|
|
86
|
+
|
|
87
|
+
model = OpenAICompatibleModel.from_env()
|
|
88
|
+
result = check_photo("photo.jpg", card, model)
|
|
89
|
+
for r in result.rules:
|
|
90
|
+
print(r.name, r.level, r.justification)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
By default each rule is asked in its own model call, and all of a photo's calls are sent at
|
|
94
|
+
once. When some rules apply only to a kind of photo, one more call asks which of those kinds the
|
|
95
|
+
photo is; a rule whose kind the photo is not comes back `not_applicable`, decided by that check.
|
|
96
|
+
You can pack rules into fewer calls; the result has the same shape either way:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
check_photo("photo.jpg", card, model, calls="one") # every rule in one call
|
|
100
|
+
check_photo("photo.jpg", card, model, calls=[["Rule A", "Rule B"], ["Rule C"]])
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Rules left out of a `calls` list get a call of their own. One rule per call caught the most
|
|
104
|
+
faults in testing; packing saves tokens.
|
|
105
|
+
|
|
106
|
+
A result has:
|
|
107
|
+
|
|
108
|
+
- `rules`: one `RuleResult` per rule, in card order: `name`, `level`, `justification`,
|
|
109
|
+
`applies_to` and `decided_by` (`model` or `picture_kind_check`).
|
|
110
|
+
- `card`, `card_fingerprint`, `prompt_version` and `model`: what produced it.
|
|
111
|
+
- `calls`: each call's rules, seconds, tries and token counts; `seconds`, `prompt_tokens` and
|
|
112
|
+
`output_tokens` for the photo; `picture_kinds`, the kind check's answers.
|
|
113
|
+
- `to_dict()` for JSON, `count("misses")`, `rule("Rule A")`.
|
|
114
|
+
|
|
115
|
+
Other options: `user_context="live event"` (background for the model), `retries=2` (extra tries
|
|
116
|
+
when a call times out, the server is busy or a reply is broken), `max_calls=8` (calls at once),
|
|
117
|
+
`cache_dir=".alignlyphotos-cache"` (a photo checked with the same card, settings, prompt version
|
|
118
|
+
and model is read back instead of sent again). `photo` can be a path or the file's bytes.
|
|
119
|
+
|
|
120
|
+
Many photos:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from alignlyphotos import check_many, write_csv, write_html
|
|
124
|
+
|
|
125
|
+
rows = check_many(["a.jpg", "b.jpg"], card, model, workers=4, max_calls=16)
|
|
126
|
+
write_csv(rows, "results.csv", card) # one row per photo, a level column per rule
|
|
127
|
+
write_html(rows, "report.html") # thumbnails, levels and justifications
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`workers` photos run at once, and at most `max_calls` model calls are in flight over all of
|
|
131
|
+
them. A photo that fails gets an error in its row and the rest carry on.
|
|
132
|
+
|
|
133
|
+
## Command line
|
|
134
|
+
|
|
135
|
+
The card comes from a Python file that defines `card`:
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
alignlyphotos check photo.jpg --card card.py
|
|
139
|
+
alignlyphotos check photos/ --card card.py --csv results.csv --html report.html
|
|
140
|
+
alignlyphotos check photos/ --card card.py --calls one
|
|
141
|
+
alignlyphotos check photos/ --card card.py --calls "Rule A|Rule B;Rule C"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Options: `--context`, `--workers 4`, `--max-calls 16`, `--retries 2`, `--cache DIR`, `--json`,
|
|
145
|
+
`-q`. Exit codes: 0 all good, 1 something failed.
|
|
146
|
+
|
|
147
|
+
Only load card files you trust: loading one runs its code.
|
|
148
|
+
|
|
149
|
+
## Check accuracy against people's labels
|
|
150
|
+
|
|
151
|
+
Make a CSV with a `photo` column (path relative to the CSV) and one column per rule, named
|
|
152
|
+
exactly as the rule, holding `meets`, `mixed`, `misses`, `cannot_assess` or `not_applicable`.
|
|
153
|
+
Blank cells are skipped.
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
photo,"Bright, natural light","Real, unposed moments"
|
|
157
|
+
shoot1/a.jpg,meets,meets
|
|
158
|
+
shoot1/b.jpg,misses,
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
alignlyphotos evaluate labels.csv --card card.py
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The report shows how often alignlyPhotos gave the label's level, a label-against-alignlyPhotos
|
|
166
|
+
table, per rule agreement with the misses caught and the misses given wrongly, and the
|
|
167
|
+
disagreements with alignlyPhotos's justification. In Python: `read_labels` and `evaluate`.
|
|
168
|
+
|
|
169
|
+
## Using a different model
|
|
170
|
+
|
|
171
|
+
Anything with a matching `complete` method works. Pass it in place of `OpenAICompatibleModel`:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from alignlyphotos import ModelReply
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class MyModel:
|
|
178
|
+
def complete(
|
|
179
|
+
self,
|
|
180
|
+
messages,
|
|
181
|
+
schema,
|
|
182
|
+
*,
|
|
183
|
+
name="",
|
|
184
|
+
max_tokens=2048,
|
|
185
|
+
timeout=None,
|
|
186
|
+
logprobs=False,
|
|
187
|
+
require_stop=True,
|
|
188
|
+
):
|
|
189
|
+
# call your model with the OpenAI-style messages, ask for JSON matching `schema`
|
|
190
|
+
return ModelReply(
|
|
191
|
+
content=json_text,
|
|
192
|
+
requested_model="mine",
|
|
193
|
+
returned_model="mine",
|
|
194
|
+
finish_reason="stop",
|
|
195
|
+
usage={"prompt_tokens": 1200, "output_tokens": 90},
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The model has to accept an image with text and return JSON in the requested shape. Return
|
|
200
|
+
`finish_reason="length"` when the reply was cut off. `usage` is optional. The prompts were
|
|
201
|
+
tuned on Qwen3-VL, so check a new model with `alignlyphotos evaluate` first.
|
|
202
|
+
|
|
203
|
+
## Building on top
|
|
204
|
+
|
|
205
|
+
`alignlyphotos.scorer` holds the parts the Alignly app and `check_photo` both use, as plain
|
|
206
|
+
functions on the card's dictionary form (`card.to_dict()`):
|
|
207
|
+
|
|
208
|
+
- `requests_for(card_dict, image_data_url, groups=..., ...)`: every model call of one photo as
|
|
209
|
+
data (`CallRequest`: messages, JSON schema, output budget), the picture-kind check first.
|
|
210
|
+
- `read_reply(request, content, finish_reason)`: checks one reply against its schema and
|
|
211
|
+
returns it, or raises `AnswerFailed` / `AnswerCutOff`.
|
|
212
|
+
- `answers_from(card_dict, replies_by_call_key)`: one answer per rule, applying the kind check.
|
|
213
|
+
- `call_ids(card_dict)`: the id each rule goes by inside the calls, made from its current name,
|
|
214
|
+
so a card with other stored ids (the app keeps them on rename) sends the same calls.
|
|
215
|
+
- `kinds_of`, `rule_block`, `rules_schema`, `SYSTEM`, `INSTRUCTION`, `KINDS_PROMPT`,
|
|
216
|
+
`PROMPT_VERSION`.
|
|
217
|
+
|
|
218
|
+
`alignlyphotos.images.prepare(data).data_url()` makes the photo copy the model sees (upright,
|
|
219
|
+
sRGB, at most 1024 px, JPEG without metadata).
|
|
220
|
+
|
|
221
|
+
## Use it from a chatbot (MCP)
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
pip install alignlyPhotos[mcp]
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Put your card files in `~/.alignlyphotos/cards` (change with `ALIGNLYPHOTOS_HOME`), for example
|
|
228
|
+
`~/.alignlyphotos/cards/capital-one.py`. Then add alignlyPhotos to Claude Desktop's config
|
|
229
|
+
(`claude_desktop_config.json`):
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"mcpServers": {
|
|
234
|
+
"alignlyphotos": {
|
|
235
|
+
"command": "alignlyphotos-mcp",
|
|
236
|
+
"env": {
|
|
237
|
+
"VISION_MODEL_BASE_URL": "https://your-server/v1",
|
|
238
|
+
"VISION_MODEL_API_KEY": "your-key",
|
|
239
|
+
"VISION_MODEL_NAME": "your-model-name"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
If Claude Desktop can't find `alignlyphotos-mcp`, use its full path instead (run
|
|
247
|
+
`which alignlyphotos-mcp` on Mac/Linux or `where alignlyphotos-mcp` on Windows to get it).
|
|
248
|
+
|
|
249
|
+
Then ask things like "check the photos in ~/shoot1 against capital-one". The chatbot can list
|
|
250
|
+
cards and check photos and folders. It picks cards by name from the cards folder only and cannot
|
|
251
|
+
make or change them.
|
|
252
|
+
|
|
253
|
+
## Moving from 0.2 to 0.3
|
|
254
|
+
|
|
255
|
+
The package was called `brandcheck` up to 0.2. Uninstall it and install `alignlyPhotos`, then
|
|
256
|
+
change `import brandcheck` to `import alignlyphotos`.
|
|
257
|
+
|
|
258
|
+
0.3 breaks 0.2 code and cards. It removes `make_card` (AI guideline-to-card), JSON and
|
|
259
|
+
Markdown cards, 0-100 scores, weights, must-pass, the brand score, confidence, mood words, the
|
|
260
|
+
photo summary, `show-card`, `edit-card` and `--min-score`.
|
|
261
|
+
|
|
262
|
+
- Rewrite the card in Python as `card = Card(...)`. For each old criterion write a `Rule`:
|
|
263
|
+
what the 100 anchor described goes in `meets`, what the 0 or 25 anchors described goes in
|
|
264
|
+
`misses` (one visible sign per line), and drop weights and must-pass. Rule names must be
|
|
265
|
+
unique.
|
|
266
|
+
- `check_photo(photo, card, model)` returns a `PhotoResult`: read `result.rules` (each with
|
|
267
|
+
`level` and `justification`) instead of `result["brand_score"]` and `result["answers"]`.
|
|
268
|
+
Drop `summary=` and `logprobs=`.
|
|
269
|
+
- Command line: `alignlyphotos score photos/ --card card.json` is now
|
|
270
|
+
`alignlyphotos check photos/ --card card.py`. Labels for `evaluate` hold a level per rule name
|
|
271
|
+
instead of scores and `on_brand`.
|
|
272
|
+
- MCP cards are Python files in `~/.alignlyphotos/cards`; the chatbot no longer makes or edits
|
|
273
|
+
them.
|
|
274
|
+
|
|
275
|
+
## Run the tests
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
pip install -e ".[test,mcp,anthropic]"
|
|
279
|
+
pytest
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The tests use a fake model, so they need no network or API key.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "alignlyPhotos"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Check brand photos against photo rules written in code, with a vision model"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"jsonschema>=4.23",
|
|
13
|
+
"openai>=2,<3",
|
|
14
|
+
"pillow>=11,<13",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
anthropic = ["anthropic>=0.40"]
|
|
19
|
+
mcp = ["mcp>=1.23"]
|
|
20
|
+
test = ["pytest>=8"]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
alignlyphotos = "alignlyphotos.cli:main"
|
|
24
|
+
alignlyphotos-mcp = "alignlyphotos.mcp_server:main"
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/alignlyphotos"]
|
|
28
|
+
|
|
29
|
+
[tool.uv]
|
|
30
|
+
# The Alignly backend installs this package from its folder; rebuild it there when code changes.
|
|
31
|
+
cache-keys = [{ file = "pyproject.toml" }, { file = "src/**/*.py" }]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
testpaths = ["tests"]
|
|
35
|
+
|
|
36
|
+
[tool.ruff]
|
|
37
|
+
line-length = 100
|
|
38
|
+
target-version = "py310"
|
|
39
|
+
|
|
40
|
+
[tool.ruff.lint]
|
|
41
|
+
select = ["E", "F", "I", "B", "UP"]
|
|
42
|
+
|
|
43
|
+
[tool.ruff.lint.isort]
|
|
44
|
+
known-first-party = ["alignlyphotos", "conftest"]
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint.per-file-ignores]
|
|
47
|
+
# Shared with the Alignly backend; kept as the backend wrote it.
|
|
48
|
+
"src/alignlyphotos/scorer.py" = ["E501"]
|