Initial commit: frigate-notify application
AI-powered video alert service that bridges Frigate NVR events to Matrix. Listens to MQTT, uses Claude Haiku vision to analyze snapshots, and posts annotated alerts to a Matrix room. - app/main.py: MQTT subscriber and event orchestration loop - app/vision.py: Claude Haiku vision analysis wrapper - app/matrix_client.py: Matrix HTTP client for sending messages/images - app/requirements.txt: Python dependencies - Dockerfile: container image build definition - docker-compose.yml: deployment configuration (host network, NAS mounts) - .env.example: required environment variable template (copy to .env)
This commit is contained in:
Executable
+42
@@ -0,0 +1,42 @@
|
||||
import base64
|
||||
import logging
|
||||
import anthropic
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PROMPT = (
|
||||
"Briefly describe what's happening in this security camera image in 1-2 sentences. "
|
||||
"Focus on the people, vehicles, or animals and their activity. Be concise."
|
||||
)
|
||||
|
||||
|
||||
def analyze_snapshot(client: anthropic.Anthropic, image_bytes: bytes) -> str | None:
|
||||
"""Send a snapshot to Claude Haiku for description. Returns None on failure."""
|
||||
try:
|
||||
b64 = base64.standard_b64encode(image_bytes).decode("utf-8")
|
||||
response = client.messages.create(
|
||||
model="claude-haiku-4-5-20251001",
|
||||
max_tokens=150,
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{
|
||||
"type": "image",
|
||||
"source": {
|
||||
"type": "base64",
|
||||
"media_type": "image/jpeg",
|
||||
"data": b64,
|
||||
},
|
||||
},
|
||||
{"type": "text", "text": PROMPT},
|
||||
],
|
||||
}
|
||||
],
|
||||
)
|
||||
description = response.content[0].text.strip()
|
||||
logger.info("Vision analysis complete: %d chars", len(description))
|
||||
return description
|
||||
except Exception:
|
||||
logger.exception("Claude Vision API failed")
|
||||
return None
|
||||
Reference in New Issue
Block a user