Metadata-Version: 2.5
Name: brandcheck
Version: 0.2.0
Summary: Score brand photos against a photography guideline with a vision model
Requires-Python: >=3.10
Requires-Dist: jsonschema>=4.23
Requires-Dist: openai<3,>=2
Requires-Dist: pillow<13,>=11
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.40; extra == 'anthropic'
Provides-Extra: mcp
Requires-Dist: mcp>=1.23; extra == 'mcp'
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# brandcheck

Score brand photos against a photography guideline with a vision model.

You write the guideline in Markdown. brandcheck turns it into an **answer card** (a list of
criteria with weights and must-pass rules), then scores each photo against that card. For each
criterion you get a score (100, 75, 50, 25 or 0), the model's confidence and a short piece of
evidence. All of it is combined into one **brand match score**.

Every result is a suggestion for a person to review, not an approval.

## Install

```
pip install brandcheck
```

Needs Python 3.10 or newer. Extras: `brandcheck[anthropic]` to run on Claude,
`brandcheck[mcp]` to use it from a chatbot.

## Set up the model

brandcheck works with any OpenAI-compatible vision model (for example Qwen3-VL served by vLLM,
Ollama, or OpenAI itself). Set three environment variables, with no quotes inside the values:

```
export VISION_MODEL_BASE_URL=https://your-server/v1
export VISION_MODEL_API_KEY=your-key
export VISION_MODEL_NAME=your-model-name
```

On Windows PowerShell use `$env:VISION_MODEL_BASE_URL="https://your-server/v1"` and so on.

To use Claude instead: `pip install brandcheck[anthropic]`, then set
`VISION_MODEL_PROVIDER=anthropic`, `ANTHROPIC_API_KEY` and `VISION_MODEL_NAME` (a Claude model
name). Claude gives no token probabilities, so confidence shows as n/a.

## 1. Make a card and review it

```
brandcheck make-card guideline.md -o card.json      # takes a few minutes
brandcheck show-card card.json                      # every rule, weight and must-pass
brandcheck show-card card.json --rule clear_focal_point   # what each score means
```

Change anything that is not right before scoring:

```
brandcheck edit-card card.json --must-pass brand_palette_compatibility=no --weight product_presentation=low
```

## 2. Score photos

```
brandcheck score photo.jpg --card card.json                 # one photo, full detail
brandcheck score photos/ --card card.json                   # a whole folder, 4 at a time
brandcheck score photos/ --card card.json --csv results.csv --html report.html
```

Options:

- `--context "live event"` gives the model background about the photos
- `--no-summary` skips the photo description (one model call per photo instead of two)
- `--workers 4` photos scored at the same time
- `--retries 2` extra tries when the model times out or sends a broken reply
- `--cache .brandcheck-cache` skips photos already scored with the same card and model
- `--min-score 70` exits with code 3 if any photo scores below 70
- `--json` prints the full results

Exit codes: 0 all good, 1 something failed, 3 a photo was below `--min-score`.

## 3. Check accuracy against people's labels

Make a CSV with a `photo` column (path relative to the CSV), and an `on_brand` column (yes/no)
and/or one column per rule id (100, 75, 50, 25, 0 or na). Blank cells are skipped.

```
photo,on_brand,clear_focal_point,bright_readable_lighting
shoot1/a.jpg,yes,100,100
shoot1/b.jpg,no,50,25
```

```
brandcheck evaluate labels.csv --card card.json --save scores.json
brandcheck evaluate labels.csv --card edited-card.json            # try a changed card
brandcheck evaluate labels.csv --card card.json --results scores.json   # no model calls
```

The report shows how often brandcheck agreed with the labels, how many off-brand photos it
caught, the best cut-off score for this data, agreement per rule (worst first) and the biggest
disagreements with the model's evidence.

## Python

```python
from brandcheck import OpenAICompatibleModel, make_card, check_photo, check_many, write_csv

model = OpenAICompatibleModel.from_env()

card = make_card(open("guideline.md").read(), model)["card"]
result = check_photo("photo.jpg", card, model)
print(result["brand_score"]["score"])  # e.g. 80

rows = check_many(["a.jpg", "b.jpg"], card, model, workers=4)
write_csv(rows, "results.csv", card)
```

`check_photo` also takes the photo's bytes, so it works on uploads that were never saved.

## Using a different model

Anything with a matching `complete` method works. Pass it in place of `OpenAICompatibleModel`:

```python
from brandcheck import ModelReply

class MyModel:
    def complete(self, messages, schema, *, name="", max_tokens=2048, timeout=None,
                 logprobs=False, require_stop=True):
        # call your model with the messages, ask for JSON matching `schema`
        return ModelReply(content=json_text, requested_model="mine", returned_model="mine")
```

The model has to accept an image with text and return JSON in the requested shape. Confidence
needs token log-probabilities. Without them, `confidence` is `None` and everything else works.
The prompts were tuned on Qwen3-VL, so check a new model with `brandcheck evaluate` first.

## Use it from a chatbot (MCP)

```
pip install brandcheck[mcp]
```

Add it to Claude Desktop's config (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "brandcheck": {
      "command": "brandcheck-mcp",
      "env": {
        "VISION_MODEL_BASE_URL": "https://your-server/v1",
        "VISION_MODEL_API_KEY": "your-key",
        "VISION_MODEL_NAME": "your-model-name"
      }
    }
  }
}
```

If Claude Desktop can't find `brandcheck-mcp`, use its full path instead (run
`which brandcheck-mcp` on Mac/Linux or `where brandcheck-mcp` on Windows to get it).

Then ask things like "make a card from ~/guidelines/brand.md called capital-one" or "check the
photos in ~/shoot1 against capital-one". The chatbot shows the card and asks you to confirm it
before scoring. Photos are file paths on your computer. Cards are saved in `~/.brandcheck/cards`
(change with `BRANDCHECK_HOME`).

## How the brand match score works

- Each criterion counts by its weight: high 3, medium 2, low 1
- `cannot_assess` and `not_applicable` answers are left out, not counted as 0
- If a must-pass criterion scores below 100, the score is capped: 75 caps it at 80%,
  50 at 60%, 25 or 0 at 40%. The worst miss sets the cap

## Run the tests

```
pip install -e ".[test,mcp,anthropic]"
pytest
```

The tests use a fake model, so they need no network or API key.
