Spaces:
Runtime error
Runtime error
Download src/backend/models/signal.py from HAK-Tech/ciro-backend: direct link, hf CLI and curl.
- Browser
- Download file 3.13 kB
-
https://huggingface.co/spaces/HAK-Tech/ciro-backend/resolve/main/src/backend/models/signal.py
- Command line
-
hf download hf://spaces/HAK-Tech/ciro-backend/src/backend/models/signal.py
-
curl -L -o signal.py https://huggingface.co/spaces/HAK-Tech/ciro-backend/resolve/main/src/backend/models/signal.py
3.13 kB
| """ | |
| CrisisSignal — the canonical input shape every downstream agent reads. | |
| Why this exists | |
| --------------- | |
| CIRO ingests evidence from three very different sources (weather APIs, | |
| simulated social media posts, CNIC-verified in-app reports). The detection | |
| agent in Phase 5 cannot afford to grow source-specific branches; it needs a | |
| single Pydantic shape it can iterate over. | |
| Trust weights are deliberately fixed constants set at the source level, not | |
| computed dynamically. The detection agent uses `trust_weight` directly when | |
| folding multi-source signals into a confidence score. | |
| CrisisSignal instances are **immutable** after creation (frozen=True). | |
| Downstream agents read signals; they never mutate them — the aggregator is | |
| the only place a signal is allowed to come into existence. | |
| """ | |
| from datetime import datetime, timezone | |
| from typing import Literal | |
| from pydantic import BaseModel, ConfigDict, Field | |
| SignalSource = Literal["weather", "social_media", "app_report"] | |
| SignalType = Literal["rainfall", "flood", "fire", "traffic", "report"] | |
| SeverityHint = Literal["heavy", "moderate", "light"] | |
| # Trust weights are intentionally part of the model module so every consumer | |
| # imports the same constants. Do not redefine these elsewhere. | |
| TRUST_WEIGHT_APP_REPORT = 1.0 # CNIC-verified, accountable | |
| TRUST_WEIGHT_WEATHER = 0.7 # authoritative but indirect (atmospheric) | |
| TRUST_WEIGHT_SOCIAL_MEDIA = 0.5 # eyewitness but unverified | |
| class CrisisSignal(BaseModel): | |
| """A single piece of evidence about a possibly-emerging crisis. | |
| Attributes: | |
| source: Which ingestion channel produced this signal. | |
| trust_weight: How much downstream reasoning should weight this signal, | |
| in [0.0, 1.0]. Set per-source (see constants above); do not invent | |
| new values per signal. | |
| raw_text: Original natural-language content (post body, report | |
| description). `None` for pure sensor signals like weather where | |
| there is no human-authored text. | |
| location_label: Human-readable area name, e.g. "G-10, Islamabad". | |
| Used in the UI trace + by the analysis agent for spatial reasoning. | |
| coordinates: (lat, lon) in WGS84. Used by the crowd-verification | |
| radius query in Phase 10. | |
| signal_type: Coarse category for downstream routing. Limited to the | |
| crisis taxonomy CIRO actually responds to. | |
| severity_hint: Optional source-level hint at intensity. Detection | |
| agent treats it as input, not as ground truth. | |
| timestamp: When the signal was observed (UTC). | |
| """ | |
| # frozen=True → CrisisSignal acts as a value object; agents can't mutate | |
| # them mid-pipeline. Enforces the "read-only after aggregation" rule. | |
| model_config = ConfigDict(frozen=True) | |
| source: SignalSource | |
| trust_weight: float = Field(ge=0.0, le=1.0) | |
| raw_text: str | None = None | |
| location_label: str | |
| coordinates: tuple[float, float] | |
| signal_type: SignalType | |
| severity_hint: SeverityHint | None = None | |
| timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) | |