ai newsFr., 30. Okt.
EilmeldungOpenAI Launches Intelligence Age, Its Strategic Futures Forum on AI Governance

SmogShield-LHR: Banishing Lahore's "Gray Ghost" with Open-Weight AI & Deterministic Health Telemetry

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine What I Built Every winter in Lahore, Pakistan, the city is haunted by what locals call the "Fifth Season" —or the "Gray Ghost" . Starting late October, a severe meteorological phenomenon known as atmosp

dev.toFreitag 21:25 · 30.10.4 Min. Lesezeit
Bild: dev.to

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission 👻🌼

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

Every winter in Lahore, Pakistan, the city is haunted by what locals call the "Fifth Season" —or the "Gray Ghost".

Starting late October, a severe meteorological phenomenon known as atmospheric thermal inversion traps industrial emissions, vehicular exhaust, brick kiln smoke, and agricultural stubble burning close to the ground. Cold air blankets the city from above, acting like a lid on a pot. The resulting toxic smog ($\text{PM} {2.5}$ and $\text{PM} {10}$) turns Lahore into one of the most polluted cities on Earth, with AQI levels routinely spiking beyond 400.

Lahore's centuries-old Mughal minarets, parks, and streets dissolve into eerie, ghostly silhouettes. But the real horror is invisible: citizens breathing air so toxic that a standard daily routine equals smoking dozens of cigarettes.

Conventional weather services provide abstract indices like "AQI 295". But for an everyday citizen, numbers like "295" fail to answer critical life questions:

SmogShield-LHR is an open-source command center and AI-powered decision-support system designed to solve this crisis. It bridges live open telemetry from the Open-Meteo Air Quality API with deterministic mathematical health engines and a fast, open-weight AI intelligence layer ( Llama 3.1 8B via Groq) to convert raw atmospheric sensor data into actionable human terms:

To test real-world scenarios instantly, the dashboard includes three pre-configured judge presets:

The entire codebase is open-source under the MIT License:

flowchart TD User["User Profile: Zone + Mode + Hours + Routine"] --> Client["Single-Viewport Command Center<br/>(app/page.tsx)"] Client -->|"POST /api/smog (JSON)"| RouteHandler["Route Handler<br/>(app/api/smog/route.ts)"] RouteHandler -->|"Validate with Zod"| ZodValidation{"Valid Input?"} ZodValidation -->|No| ErrResponse["400 Bad Request<br/>(Formatted Error List)"] ZodValidation -->|Yes| OpenMeteoAPI[("Open-Meteo Air Quality REST API<br/>(5s Timeout)")] OpenMeteoAPI -.->|"On Timeout / Network Drop"| BundledSample["Bundled Realistic Sample<br/>(lib/offlineSample.ts)"] OpenMeteoAPI --> CalcEngine["Deterministic Calculation Engine<br/>(lib/calc.ts)<br/>- Berkeley Earth Cigarettes<br/>- WHO Safety Multiples<br/>- Safe 06:00-21:00 Windows"] BundledSample --> CalcEngine CalcEngine --> GroqLLM[("Open-Weight AI Inference<br/>llama-3.1-8b-instant on Groq Cloud")] GroqLLM --> Normalizer["Post-Processing & Normalization<br/>- Deterministic Risk Band Override<br/>- Math Hallucination Strip<br/>- WhatsApp Single-Asterisk Normalizer"] Normalizer -->|"HTTP 200 (SmogResponse)"| Client How I Built It 1. The Open-Weight AI Intelligence Layer (<8B Parameters) We wanted an AI engine that was blazing-fast, lightweight, and cost-effective. We integrated Llama 3.1 8B ( llama-3.1-8b-instant ) via the Groq Cloud API, delivering sub-second inference latencies (~350ms).

The AI layer generates four distinct artifacts:

One core engineering rule guided this project: Never let an LLM do arithmetic or diagnose medical risk. LLMs are notorious for hallucinating percentages and severity bands.

In SmogShield-LHR, all health calculations are computed deterministically in lib/calc.ts before the AI is invoked:

Berkeley Earth Cigarette Equivalence Standard: $$\text{Cigarettes Inhaled} = \left(\frac{\text{Mean PM} {2.5}}{22}\right) \times \left(\frac{\text{Hours Outside}}{24}\right) \times \text{Intake Multiplier}$$ *(Translates $22\ \mu\text{g/m}^3$ of $\text{PM} {2.5}$ exposure over 24 hours into the toxic particulate equivalent of smoking 1 cigarette).*

Algorithmic Safe Window Detection: The system scans 24-hour CAMS hourly telemetry between 06:00 and 21:00 PKT, sorting the hours to find the 3 cleanest windows (when solar heating breaks the surface inversion) and the 3 peak hazard spikes (morning and evening traffic + cold ground air).

// Deterministic Cigarette Equivalence Calculation (lib/calc.ts) export function calcCigarettes ( pm25: number, hoursOutside: number, multiplier: number ): number { if ( hoursOutside <= 0 || pm25 <= 0 ) return 0; const raw = ( pm25 / 22 ) * ( hoursOutside / 24 ) * multiplier; return Number ( raw. toFixed ( 1 )); } Enter fullscreen mode Exit fullscreen mode 3. Resilient Offline Fallback During intense winter smog, Lahore frequently experiences telecom drops, ISP degradation, or power cuts. If Open-Meteo fails or takes longer than 5 seconds, SmogShield-LHR automatically falls back to a verified, bundled Lahore hourly telemetry dataset ( lib/offlineSample.ts ), clearly displaying an OFFLINE SAMPLE badge to the user.

This project was developed and refined using modern AI agent workflows with Antigravity and DevRelay, following spec-driven development and test-first engineering:

Lahore is a city of rich memories—of historic gardens, street chai at dawn, and vibrant open-air bazaars. But each winter, the "Gray Ghost" creeps in like a phantom in the night, stealing visibility, canceling schools, and sending elders and children to respiratory clinics.

In the spirit of Ghost in the Machine and Día de los Muertos, SmogShield-LHR is built to confront that specter. It turns invisible, phantom atmospheric threats into concrete, understandable numbers—empowering everyday students, commuters, and families to protect their health and reclaim their city from the fog.

Quelle: dev.to (dev.to). Original öffnen