CIVIX-PULSE

๐Ÿ™๏ธ Civix-Pulse: AI-Driven Grievance Triage & Dispatch

Python FastAPI React Supabase Groq

Zero-Touch Civic Maintenance: Replacing manual ticketing with instant, AI-driven triage, deterministic clustering, and automated dispatch. Built for SDG 9 (Infrastructure) and SDG 11 (Sustainable Cities).

Civix-Pulse is an enterprise-grade, multi-agent AI system designed to modernize public infrastructure reporting. It allows citizens to report issues via Telegram (Text, Photo, or Voice), uses Vision AI to verify the claim, clusters duplicate reports mathematically, and dispatches city workers based on an automated Risk Matrix.


๐Ÿ“– Table of Contents

  1. Core Features
  2. Architecture & Tech Stack
  3. Prerequisites & Getting API Keys
  4. Step 1: Database Setup (Supabase)
  5. Step 2: Installation & Setting Up Keys
  6. Step 3: Running the System (The 3 Terminals)
  7. How to Use the System

๐Ÿš€ Core Features


๐Ÿ—๏ธ Architecture & Tech Stack


๐Ÿ”‘ Prerequisites & Getting API Keys

Before writing any code, you must generate the free API keys that power this system.

1. Telegram Bot Token

We need a bot to talk to the citizens.

2. Supabase URL & Key

This handles our PostgreSQL database and Vector math.

3. Groq API Key

This powers our ultra-fast Llama 3 & Vision models.

4. Ngrok Tunneling

This exposes your local code to the internet so Telegram can reach it.


๐Ÿ—„๏ธ Step 1: Database Setup (Supabase)

  1. Log into Supabase and open your project.
  2. Go to the SQL Editor on the left menu.
  3. Run this command to enable vector math: CREATE EXTENSION vector;
  4. Create your grievances, workers, and locations tables according to your schema.
  5. CRITICAL: Run this custom RPC function to enable the 3-Layer Clustering Engine inside the database:
Click to view the SQL Clustering Function ```sql CREATE OR REPLACE FUNCTION find_nearby_similar_tickets( query_lat float, query_lng float, query_embedding vector(384) ) RETURNS TABLE ( id uuid, original_complaint text, image_hash text, created_at timestamptz, priority_level text, assigned_worker uuid, workers json, distance_km float, similarity float ) LANGUAGE sql STABLE AS $$ SELECT g.id, g.original_complaint, g.image_hash, g.created_at, g.priority_level, g.assigned_worker, json_build_object('name', w.name) as workers, ( 6371 * acos( least(1.0, cos( radians(query_lat) ) * cos( radians( g.lat ) ) * cos( radians( g.lng ) - radians(query_lng) ) + sin( radians(query_lat) ) * sin( radians( g.lat ) ) ) ) ) as distance_km, 1 - (g.text_embedding <=> query_embedding) as similarity FROM grievances g LEFT JOIN workers w ON g.assigned_worker = w.id WHERE g.status IN ('Open', 'Merged') AND g.text_embedding IS NOT NULL AND ( 6371 * acos( least(1.0, cos( radians(query_lat) ) * cos( radians( g.lat ) ) * cos( radians( g.lng ) - radians(query_lng) ) + sin( radians(query_lat) ) * sin( radians( g.lat ) ) ) ) ) <= 0.3 AND 1 - (g.text_embedding <=> query_embedding) > 0.60 ORDER BY similarity DESC; $$; ```

๐Ÿ’ป Step 2: Installation & Setting Up Keys

First, clone the repository to your local machine:

git clone https://github.com/Visionstack-404/CIVIX-PULSE.git
cd CIVIX-PULSE

๐Ÿ›‘ CRITICAL: Add Your API Keys Here

You must place the keys you generated earlier into a hidden environment file. Never push this file to GitHub.

  1. In the root folder of the project (right next to main.py), create a new text file named exactly .env.
  2. Open the .env file and paste your keys inside exactly like this (no quotes):
TELEGRAM_TOKEN=your_botfather_token_here
SUPABASE_URL=[https://your-project-url.supabase.co](https://your-project-url.supabase.co)
SUPABASE_KEY=your_supabase_anon_public_key_here
GROQ_API_KEY=your_groq_api_key_here

๐Ÿƒ Step 3: Running the System (The 3 Terminals)

To run the full stack locally, you need to open three separate terminal windows.

๐ŸŸข Terminal 1: The AI Backend

This runs the FastAPI Python server that handles the AI logic.

# 1. Create a virtual environment
python -m venv venv

# 2. Activate it (Windows)
venv\Scripts\activate
# (On Mac/Linux, use: source venv/bin/activate)

# 3. Install Python dependencies
pip install fastapi uvicorn httpx sentence_transformers imagehash Pillow groq pydantic python-dotenv

# 4. Start the server
uvicorn main:app --host 0.0.0.0 --port 8000

(Leave this terminal running!)

๐Ÿ”ต Terminal 2: The Ngrok Webhook Tunnel

Telegram is on the internet, but your Python server is stuck on your local laptop. Ngrok creates a secure bridge to connect them.

  1. Open a new terminal.
  2. Run this command:
    ngrok http 8000
    
  3. Ngrok will give you a โ€œForwardingโ€ URL that looks like https://random-words.ngrok-free.app. Copy this URL.
  4. Open your web browser (Chrome/Edge) and paste this link, replacing the brackets with your actual Telegram Token and Ngrok URL:
    [https://api.telegram.org/bot](https://api.telegram.org/bot)<YOUR_TELEGRAM_TOKEN>/setWebhook?url=<YOUR_NGROK_URL>/webhook
    

    Hit Enter. If the browser says {"ok":true,"description":"Webhook was set"}, Telegram is successfully connected to your Python code!

๐ŸŸก Terminal 3: The React Frontend

This runs the web portal for city admins and workers.

  1. Open a third terminal and navigate to the frontend folder:
    cd frontend
    
  2. Install the Node packages and start the Vite development server:
    npm install
    npm run dev
    
  3. Click the local host link (usually http://localhost:5173) to view the frontend dashboards.

๐Ÿ“ฑ How to Use the System

  1. Citizen Reporting: Open Telegram on your phone and search for the bot you created. Type /start.
  2. Ingestion: Send a text description or a voice note of a civic issue (e.g., โ€œThere is a massive pothole on Main Streetโ€).
  3. Verification: Upload an image of the issue using the paperclip icon. Agent 4 will audit it.
  4. Location: Send your Live Location pin via Telegramโ€™s attachment menu.
  5. Resolution: The AI Triage Engine will calculate the priority, mathematically check for duplicates, and auto-dispatch the nearest available city worker. Workers can view tasks on the React portal and resolve them, triggering an automatic photographic broadcast back to the citizens.

๐Ÿ‘จโ€๐Ÿ’ป Built By

Developer Email
VisionStack-404 ๐Ÿ“ง varunvadlakonda4@gmail.com
ScriptOrbit-132 ๐Ÿ“ง srivarshiniyadav30@gmail.com

Built with โค๏ธ for a better, automated future. (SDG 9 & SDG 11)