How rajatrawal-06/gemma_hack works
Purpose and Operating Model
Project Sentinel is an edge-native public-safety incident-verification MVP. It treats camera and audio detections as timestamped evidence rather than automatic alerts, producing structured assessments for human operators. It explicitly excludes identity resolution, face recognition, and automated enforcement.
Primary entry points are the CLI demo at scripts/run_demo.py and Streamlit operator dashboard at app.py.
Canonical Data Contracts
Pydantic models define the system boundary between perception, fusion, reasoning, and review. Evidence packets carry modality-specific observations and capture timing; downstream stages operate on validated incident candidates and structured risk/review outputs.
• src/sentinel/schemas.py
• src/sentinel/config.py
Validation is a hard gate: model output is not allowed to become an incident report until it conforms to the defined schema.
Multimodal Evidence Fusion
The fusion layer buffers visual and audio evidence and aligns it by capture timestamp, accommodating modality latency/skew. It produces an IncidentCandidate with synchronization state, so missing or stale corroboration remains visible rather than being silently treated as negative evidence.
• src/sentinel/fusion/engine.py
• src/sentinel/schemas.py
Flow: perception/evidence inputs → timestamp-aware fusion buffer → fused candidate or explicitly degraded synchronization status.
Reasoning Boundary: Local Gemma or Offline Fallback
A reasoning adapter converts a fused candidate into strict JSON instructions for a Gemma-compatible OpenAI-style chat endpoint. Responses are schema-validated before report creation. The runtime is optional: a deterministic local/offline reasoner supports reproducible demos without model downloads, credentials, or network access.
• src/sentinel/reasoning/gemma_client.py
• src/sentinel/reasoning/prompt.py
• src/sentinel/config.py
The external model boundary is configured through GEMMA_API_BASE and GEMMA_MODEL; the expected deployment is a local server such as one on localhost:8080/v1.
Human Review and Operator Surface
The application presents evidence-backed assessments to an operator, preserving review as the actionability boundary. A generated assessment can communicate severity, rationale, modality corroboration, and synchronization limitations, but does not independently enforce an outcome.
• app.py
• src/sentinel/schemas.py
Demo and Scenario Harness
Curated scenarios drive the same evidence-to-fusion-to-reasoning path used by the runnable MVP. They demonstrate fall detection without audio corroboration, glass-break corroboration within the fusion window, and benign scenes intended to reduce alarm fatigue.
• scripts/run_demo.py
• src/sentinel/demo/scenarios.py
• src/sentinel/fusion/engine.py
Local Precedent Store
Prior incident reports can be appended to a local JSONL file and queried for similar historical outcomes. This is a lightweight forensic/context layer, not a managed database or remote retrieval service.
• src/sentinel/precedent.py
• scripts/run_demo.py
Runtime and Model Infrastructure
The project runs as Python with Streamlit for the dashboard and Pydantic-backed contracts. Optional model operations use Hugging Face authentication/access checks and download scripts; artifacts are expected under ignored models/ storage. Runtime setup and model acquisition are separated from normal offline operation.
• pyproject.toml
• requirements.txt
• scripts/verify_hf_access.py
• scripts/download_model.py
Main entry points: gemma_client.py Reasoning adapter · schemas.py Structured assessment · run_demo.py CLI demo · engine.py Fusion engine
Components 17
Operator & Demo
- Streamlit dashboard · Presents assessments for human review.
app.py - CLI demo · Runs the end-to-end MVP pipeline.
scripts/run_demo.py - Curated scenarios · Includes corroborated, degraded, and benign cases.
src/sentinel/demo/scenarios.py - Human review · Operators assess evidence; no automated enforcement occurs.
app.py
Evidence Pipeline
- Perception evidence · Timestamped modality observations.
- Pydantic contracts · Defines evidence, candidates, assessments, and review outputs.
src/sentinel/schemas.py - Fusion engine · Builds incident candidates with synchronization state.
src/sentinel/fusion/engine.py - Timestamp fusion buffer · Accommodates modality latency and skew.
src/sentinel/fusion/engine.py - Incident candidate · Retains degraded or missing corroboration explicitly.
src/sentinel/schemas.py
Reasoning
- Strict JSON prompt
src/sentinel/reasoning/prompt.py - Reasoning adapter · Validates model output before report creation.
src/sentinel/reasoning/gemma_client.py - Local Gemma endpoint · OpenAI-style local chat endpoint.
- Offline reasoner · Supports reproducible operation without network or model downloads.
src/sentinel/reasoning/gemma_client.py - Structured assessment · Contains severity, rationale, corroboration, and limitations.
src/sentinel/schemas.py
Local Context & Model Setup
- Precedent store · Appends reports and finds similar prior outcomes.
src/sentinel/precedent.py - Runtime configuration · Configures model endpoint and model selection.
src/sentinel/config.py - Model acquisition · Checks Hugging Face access and downloads local artifacts.
scripts/download_model.py
Connections 18
- Curated scenarios → CLI demo: drives
- CLI demo → Perception evidence: emits
- Perception evidence → Pydantic contracts: validated as evidence
- Pydantic contracts → Fusion engine: evidence packets
- Fusion engine → Timestamp fusion buffer: buffers
- Timestamp fusion buffer → Incident candidate: aligns by capture time
- Incident candidate → Strict JSON prompt: formats
- Strict JSON prompt → Reasoning adapter: strict JSON request
- Runtime configuration → Reasoning adapter: configures
- Reasoning adapter → Local Gemma endpoint: optional inference
- Reasoning adapter → Offline reasoner: fallback
- Local Gemma endpoint → Structured assessment: validated response
- Offline reasoner → Structured assessment: deterministic response
- Structured assessment → Human review: evidence-backed assessment
- Streamlit dashboard → Human review: supports
- CLI demo → Precedent store: append/query reports
- Precedent store → Structured assessment: historical context
- Model acquisition → Local Gemma endpoint: provisions artifacts