Metadata-Version: 2.5
Name: vigie-claims-extract
Version: 0.1.0
Summary: Extract checkable claims from short videos and video-to-context records, for fact-checking.
Project-URL: Homepage, https://github.com/wani-ham/youtube-shorts-to-claims
Project-URL: Repository, https://github.com/wani-ham/youtube-shorts-to-claims
Project-URL: Issues, https://github.com/wani-ham/youtube-shorts-to-claims/issues
Author: Taewan Ham
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: claim-extraction,claims,fact-checking,llm,misinformation,video-to-text,youtube-shorts
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: <3.15,>=3.12
Requires-Dist: anthropic<3,>=2.12
Requires-Dist: openai<4,>=3.57
Requires-Dist: pydantic<3,>=2.14
Requires-Dist: python-dotenv<2,>=1.2
Requires-Dist: rapidfuzz<4,>=3.14
Provides-Extra: dev
Requires-Dist: pytest<10,>=9; extra == 'dev'
Provides-Extra: video
Requires-Dist: video-to-context<0.6,>=0.5.1; extra == 'video'
Description-Content-Type: text/markdown

# vigie-claims-extract: Extract Claims from Youtube Shorts

Extract checkable claims from a [video-to-context](https://github.com/wani-ham/youtube-shorts-to-text-context) record (`record.json` or `record.md`). Part of Vigie's fact-checking pipeline: this step finds claims; it never decides whether they are true.

## Install

You need Python 3.12–3.14. [uv](https://docs.astral.sh/uv/) is the easiest way:

```bash
uv tool install --python 3.12 vigie-claims-extract            # claims from record files
uv tool install --python 3.12 "vigie-claims-extract[video]"   # also from YouTube links (needs ffmpeg)
```

Or with pip, inside a Python 3.12+ environment:

```bash
pip install vigie-claims-extract
pip install "vigie-claims-extract[video]"
```

The `video` extra brings in [video-to-context](https://github.com/wani-ham/youtube-shorts-to-text-context), which needs **ffmpeg** (`brew install ffmpeg` on macOS) and about 5 GB of disk for Whisper and the video tools.

## Choose a model

Download the settings template and pick one option in it: Claude, Gemini, OpenAI, Mistral, OpenRouter, or Ollama on your own machine.

```bash
mkdir -p ~/.vigie-claims-extract
curl -o ~/.vigie-claims-extract/.env https://raw.githubusercontent.com/wani-ham/youtube-shorts-to-claims/main/.env.example
```

Settings are read from `./.env` first, then `~/.vigie-claims-extract/.env`. Real environment variables always win.

## Usage

```bash
# A YouTube video or Short (with the video extra)
vigie-claims-extract "https://www.youtube.com/shorts/VIDEO_ID"

# A record you already have from video-to-context
vigie-claims-extract store/<media_id>/record.json

# Segmentation only, no model call
vigie-claims-extract record.md --units-only

# Keep records somewhere else, or process a link again
vigie-claims-extract "https://youtu.be/VIDEO_ID" --store records --force
```

From a link, the video record is saved in `store/<media_id>/` and reused next time. `claims.json` and `claim_list.md` are written next to the record. Vision settings (`VISION_*`) for the video step are read from `./.env` or `~/.video-to-context/.env`, as in video-to-context itself. Model settings are checked before any download starts.

The command exits with `0` when every step succeeded, `1` when a model step failed but a partial result was written, and `2` for bad settings or input.

## How it works

| Step | Code or LLM | What it does |
| --- | --- | --- |
| 1. Load | code | Reads JSON or MD into one shape. |
| 2. Segment | code | Re-cuts speech into sentences (Whisper segments break at pauses). Drops burned-in captions that repeat the speech, keeps headlines and other on-screen text, keeps the lead of the post caption and sets channel boilerplate aside. Logos are context; `VISUAL` lines are never quotable. |
| 3. Select and type | LLM, low effort | Labels every unit: `factual_claim`, `mixed`, `opinion`, `call_to_action`, `other`. |
| 4. Decompose | LLM | For selected units only: resolves references, splits into atomic claims, writes each in the source language and English, with an exact quote, claim type, entities and claimant. Ambiguous units are returned as `cannot_disambiguate` instead of guessed. |
| 5. Implicit claims | LLM | What the video presents through framing: outlet branding, endorsements, setting. Each needs an observed basis (a unit, a logo, the uploader or sponsor); claims resting only on the vision model's interpretation are rejected. |
| 6. Validate | code | Rejects any claim whose quote is not in its source text, repairs wrong unit ids, flags entities not found in the record, merges duplicates (speech and caption saying the same thing), ranks by claim type and caps at 10. |

A failed LLM step is recorded in `errors` and the rest of the result is kept.

## Output: `claims.json`

`units` (what can be quoted), `dropped_text` (what was set aside and why), `unit_labels`, `claims`, `rejected` (with reasons) and `errors`. Each claim has `text`, `text_en`, `quote`, `unit_ids`, `source`, `start`/`end`, `explicit`, `claim_type`, `entities`, `claimant`, `checkable`, `priority`, `notes` and `warnings`. `claim_type` routes the claim to a verification method later.

A readable `claim_list.md` is written next to it, with each claim, its quote, type, claimant and time, then the rejected claims and errors.

## Model

Default `claude-haiku-5-5` through the Anthropic SDK, with structured outputs and the server-side refusal fallback enabled. Set `CLAIMS_BASE_URL` and `CLAIMS_MODEL` (and `CLAIMS_API_KEY` if needed) for any OpenAI-compatible server: Gemini, OpenAI, Mistral, OpenRouter, or Ollama on your own machine. `.env.example` has a preset for each. `CLAIMS_TIMEOUT_S` (default 180) sets how long to wait for each call, and `CLAIMS_REASONING_EFFORT` is passed through to OpenAI-compatible servers; slow local models usually need both.

## Development

```bash
git clone https://github.com/wani-ham/youtube-shorts-to-claims.git && cd youtube-shorts-to-claims
uv sync --extra dev --extra video
uv run pytest
```

To release: raise `__version__` in `vigie_claims_extract/__init__.py`, then `uv build` and `uv publish`.

Tests run on a real record (`tests/samples/fox_canon_law.*`) with a fake model, so they need no API key.
