File size: 4,637 Bytes
8396016
 
60d42dc
8396016
 
 
 
 
2a9b8d1
8396016
 
41d97ca
8db5d82
 
 
8396016
 
60d42dc
 
 
f005306
 
 
60d42dc
2a9b8d1
 
 
 
015fde7
 
2a9b8d1
60d42dc
61641a1
015fde7
61641a1
 
 
 
015fde7
60d42dc
 
 
 
2a9b8d1
60d42dc
 
 
 
 
 
2a9b8d1
60d42dc
 
20905e1
 
 
60d42dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a9b8d1
60d42dc
2a9b8d1
 
 
 
60d42dc
 
 
 
 
 
 
 
 
 
 
70158ca
60d42dc
 
 
 
 
 
 
 
8536e24
 
114ea19
 
 
 
 
 
 
8536e24
f005306
 
 
 
 
 
70158ca
f005306
 
 
 
 
 
 
 
 
 
 
 
 
60d42dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20905e1
60d42dc
2a9b8d1
 
 
 
60d42dc
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
title: Tiny Trigger
emoji: "🔌"
colorFrom: red
colorTo: gray
sdk: gradio
sdk_version: 6.17.3
python_version: '3.13'
app_file: server.py
pinned: false
license: other
short_description: 'Open-vocabulary video automations with YOLOE'
tags:
  - track:backyard
  - achievement:offbrand
---

# Tiny Trigger

Tiny Trigger is a local-first hackathon prototype for open-vocabulary video
automations. It uses YOLOE to detect user-supplied classes plus every label
referenced by enabled rules in a video, then evaluates small structured rules
that can trigger simulated actions or optional webhook POSTs.

The LLM path is intentionally constrained: Replicate, OpenAI, or Claude compile
natural language into JSON/YAML automation rules. The app validates those rules
before evaluating them, and the LLM never emits executable code.

DEMO video: https://youtu.be/BfXir6fonR0

For a quick operator checklist, see [`DEMO.md`](DEMO.md).

## Development Attribution

Tiny Trigger was developed by Javier Montalvo with assistance from AI coding
tools, including Anthropic Claude and OpenAI Codex. Some earlier assisted work
may not consistently include co-author trailers in the commit history; future
assisted commits should include explicit attribution where applicable.

## Run Locally

```bash
pip install -r requirements.txt
python server.py
```

Or with Poetry:

```bash
poetry install
poetry run python server.py
```

The detector defaults to the Small YOLOE model (`yoloe-26s-seg.pt`) at 640px,
which Ultralytics downloads on first use if it is not already cached. Model
weights are not checked into the repo.

For small or background objects, use a larger model such as `yoloe-26l-seg.pt`,
set device to `cuda:0`, lower confidence to `0.05`-`0.15`, and raise image size
to `960` or `1280`.

Run tests with:

```bash
pip install -r requirements-dev.txt
python -m pytest
```

Or:

```bash
poetry run pytest
```

## Cloud Rule Compiler

Choose Replicate, OpenAI, or Claude in Settings and paste the matching API key.
Keys entered in the UI are sent only with compile requests. Hugging Face Space
owners can also set `REPLICATE_API_TOKEN`, `OPENAI_API_KEY`, or
`ANTHROPIC_API_KEY` as Space secrets.

## Rule Shape

Rules can be written directly as YAML or compiled from natural language:

```yaml
rules:
  - name: person-near-steering-wheel
    when:
      all:
        - present: {label: person, min_count: 1}
        - near: {a: person, b: steering wheel, max_gap_percent: 16}
    gate:
      enabled: true
      cooldown: {key: turn-on-pc, minutes: 5}
    then:
      - type: webhook
        name: turn on pc
```

Initial video conditions include presence, count, near, far, and moving. Near/far
use the minimum horizontal/vertical gap between detection boxes in normalized
frame percent. Moving uses detector-provided track IDs across sampled frames;
YOLOE enables Ultralytics ByteTrack only when active rules include a moving
condition, so presence/near/count rules keep the higher-recall prediction path.
Moving tolerates one missed sampled frame by default to avoid repeat alerts from
detector flicker. Gates include enabled state and cooldown. Triggers can fire
while a condition is true, when it becomes true, when it becomes false, or on
either change. Tiny Trigger does not yet support speed, direction, long-gap
re-identification, or trajectory path rules.

```yaml
rules:
  - name: monitor-presence-lights
    when:
      all:
        - near: {a: person, b: monitor, max_gap_percent: 16}
    trigger:
      on: change
    gate:
      enabled: true
    then:
      enter:
        - type: webhook
          name: turn on lights
      exit:
        - type: webhook
          name: turn off lights
```

Home Assistant, live RTSP/webcam monitoring, and trajectory logic are planned
later increments.

## Local State

Private local settings and runtime memory live under `.local/`, which is ignored
by git:

```text
.local/config.yaml       private defaults such as camera/webhook URLs
.local/automations.json  saved editable automation rules
.local/state.json        cooldown memory and last-fired timestamps
.local/events.jsonl      append-only fired action history
```

Example `.local/config.yaml`:

```yaml
webhook_url: "http://127.0.0.1:8123/api/webhook/example"
default_detector_model: "yoloe-26x-seg.pt"
default_device: "cuda:0"
default_image_size: 640
default_max_detections: 300
llm_provider: "anthropic"
replicate_model: "openai/gpt-5.2"
openai_model: "gpt-5.5"
anthropic_model: "claude-sonnet-4-6"
```

## License

This repository is provided under a temporary all-rights-reserved hackathon
prototype license. See `LICENSE`.