# Project export: Arogyam-2.0

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: OpenAI Build Week
- Tagline: AI-powered emergency response system that analyzes injuries, provides first aid, and instantly connects patients with nearby hospitals and ambulances.
- Devpost: https://devpost.com/software/arogyam-2-0
- GitHub: https://github.com/Dhruvtara108/Arogyam-2.0
- Video: https://www.youtube.com/embed/G21vyl_xf0Y?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Team: 1 GitHub contributor(s) — Dhruv Mishra (13 commits)

## Devpost submission (written by the team)

### Inspiration

Every minute matters during a medical emergency, yet many people struggle to quickly determine the seriousness of an injury or reach the right medical help in time. We wanted to explore how AI could bridge that gap by providing instant injury assessment, first-aid guidance, and simulated emergency dispatch—all through a simple chat interface. Our goal was to build an intelligent first responder that demonstrates how AI can support faster decision-making in emergency situations.

### What it does

Arogyam AI allows a user to upload an image of an injury through a Telegram bot. The system uses AI to: 🩺 Analyze the injury image 🚨 Classify the emergency severity (Low, Medium, High) 💊 Generate first-aid recommendations 🏥 Find the nearest suitable hospital 👨‍⚕️ Assign an available doctor 🚑 Dispatch the nearest available ambulance (simulated) 📊 Display everything live on an emergency dashboard The dashboard provides emergency responders with real-time information about the patient, AI reasoning, hospital availability, ambulance status, confidence score, and estimated response time.

### How we built it

The project consists of four major components: Telegram Bot for user interaction FastAPI backend to process requests Google Gemini Vision for AI-powered injury analysis React Dashboard for live emergency monitoring The backend stores emergency information and updates a live dashboard every few seconds. Mock hospital, ambulance, and doctor datasets simulate a real emergency response network.

### Challenges we ran into

During development we faced several technical challenges: Integrating AI vision with a reliable structured JSON response Building a complete end-to-end workflow between Telegram, FastAPI, and React Handling image uploads and different MIME types Managing API quotas while testing Gemini Vision Designing a dashboard that clearly communicates emergency information in real time Each challenge helped us improve both the system architecture and the overall user experience.

### What we learned

Throughout this project we gained hands-on experience with: AI Vision APIs Prompt engineering for structured medical outputs FastAPI backend development React dashboard development Telegram Bot development API integration Full-stack system architecture Real-time data flow between multiple services Most importantly, we learned how multiple technologies can work together to create meaningful real-world solutions.

### What's next

for Arogyam AI We plan to expand Arogyam AI with: 📍 Live GPS tracking 🚑 Real ambulance APIs 🏥 Real hospital integration 👨‍⚕️ Doctor availability APIs 📞 Automatic emergency calling 📱 Mobile application 🌍 Multi-language support ❤️ Electronic Health Record (EHR) integration Our long-term vision is to build an AI-powered emergency assistance platform that can support patients and healthcare providers during the critical first few minutes of an emergency.

## README (from the GitHub repository)

<div align="center">

# 🩺 Arogyam AI
### *(v2.0 — "Arogyam 2.0")*

### AI-Powered Emergency Injury Assessment & Smart Hospital Dispatch System

*Turning a photo into a life-saving decision — in seconds.*

[![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.110-009688?style=for-the-badge&logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com/)
[![React](https://img.shields.io/badge/React-18-61DAFB?style=for-the-badge&logo=react&logoColor=black)](https://react.dev/)
[![Gemini](https://img.shields.io/badge/Gemini-2.5%20Flash%20Vision-8E75B2?style=for-the-badge&logo=googlegemini&logoColor=white)](https://ai.google.dev/)
[![Telegram](https://img.shields.io/badge/Telegram-Bot%20API-26A5E4?style=for-the-badge&logo=telegram&logoColor=white)](https://core.telegram.org/bots/api)
[![Built with Codex](https://img.shields.io/badge/Built%20with-Codex-412991?style=for-the-badge&logo=openai&logoColor=white)](https://openai.com/codex)

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](CONTRIBUTING.md)
[![Made with ❤️](https://img.shields.io/badge/Made%20with-%E2%9D%A4%EF%B8%8F-red.svg?style=flat-square)]()
[![Open Source](https://img.shields.io/badge/Open%20Source-Yes-success.svg?style=flat-square)]()

<br/>

<img src="./docs/assets/banner.svg" alt="Arogyam AI Banner" width="100%"/>

<br/>

<img src="https://readme-typing-svg.demolab.com?font=Fira+Code&size=20&pause=1000&color=4A90D9&center=true&vCenter=true&width=650&lines=Upload+a+photo.+Get+a+medical+decision.;Powered+by+Gemini+2.5+Flash+Vision;Built+for+OpenAI+Build+Week+with+Codex+%26+GPT-5.6" alt="Typing SVG" />

<br/>

**[▶ Watch the Live Demo](https://www.youtube.com/watch?v=G21vyl_xf0Y)** · **[Report Bug](../../issues)** · **[Request Feature](../../issues)** · **[Documentation](#-api-documentation)**

</div>

---

## 📖 Table of Contents

- [The Problem](#-the-problem)
- [The Solution](#-the-solution)
- [Features](#-features)
- [Tech Stack](#-tech-stack)
- [Architecture](#-architecture)
- [How It Works](#-how-it-works)
- [Live Demo](#-live-demo)
- [Screenshots](#-screenshots)
- [Folder Structure](#-folder-structure)
- [Getting Started](#-getting-started)
  - [Prerequisites](#prerequisites)
  - [Backend Setup](#1-backend-setup)
  - [Frontend Setup](#2-frontend-setup)
  - [Telegram Bot Setup](#3-telegram-bot-setup)
- [Environment Variables](#-environment-variables)
- [API Documentation](#-api-documentation)
- [Why Gemini?](#-why-gemini-25-flash-vision)
- [Built With Codex & GPT-5.6](#-built-with-codex--gpt-56)
- [Security Considerations](#-security-considerations)
- [Scalability](#-scalability)
- [Challenges Faced](#-challenges-faced)
- [Learnings](#-learnings)
- [Roadmap](#-roadmap--future-scope)
- [Contributing](#-contributing)
- [License](#-license)
- [Acknowledgements](#-acknowledgements)

---

## 🚨 The Problem

In the critical minutes after an injury, two things routinely go wrong:

- **Under-reaction** — people underestimate a serious injury and delay getting real medical help.
- **Over-reaction** — minor injuries trigger unnecessary emergency calls, tying up ambulances and hospital beds that someone else may need urgently.

Both failure modes share a root cause: **nobody at the scene is qualified to triage the injury in real time.** Arogyam AI puts a triage-trained "second opinion" in everyone's pocket.

## 💡 The Solution

Arogyam AI lets anyone **send a photo of an injury over Telegram** and get back a structured, medically-reasoned emergency assessment in seconds — including whether they need first aid, a hospital, or an ambulance, dispatched automatically to a live operations dashboard.

```
📸 Photo in  →  🧠 AI reasoning  →  🚑 Dispatch decision  →  📊 Live dashboard
```

No app to install. No form to fill. Just a photo and an answer.

---

## ✨ Features

| Category | Capability |
|---|---|
| 🧠 **AI Analysis** | Injury classification, severity scoring, and confidence estimation via Gemini 2.5 Flash Vision |
| 🤖 **Telegram Bot** | Zero-friction image intake — no app install required |
| ⚡ **FastAPI Backend** | Modular, async-first REST API for analysis and dispatch |
| 📊 **Live Dashboard** | Real-time polling dashboard built in React |
| 🏥 **Hospital Allocation** | Mock hospital resource matching based on severity and proximity |
| 👨‍⚕️ **Doctor Allocation** | Automatic assignment of on-call medical staff |
| 🚑 **Ambulance Dispatch** | Decision engine flags ambulance requirement + ETA |
| 🩹 **First Aid Engine** | Instant, actionable first-aid guidance while help is en route |
| 🎯 **Priority Classification** | Emergencies ranked and queued by urgency |
| 🗃️ **SQLite Storage** | Lightweight, dependency-free persistence layer |
| 🔌 **REST API** | Clean, documented endpoints for integration |

---

## 🛠 Tech Stack

<table>
<tr>
<td valign="top" width="25%">

**Frontend**
- React
- Vite
- JavaScript (ES6+)
- CSS3

</td>
<td valign="top" width="25%">

**Backend**
- FastAPI
- Python 3.10+
- Uvicorn (ASGI)

</td>
<td valign="top" width="25%">

**AI / ML**
- Gemini 2.5 Flash Vision
- Prompt-based structured extraction

</td>
<td valign="top" width="25%">

**Messaging & Data**
- Telegram Bot API
- SQLite
- Git & GitHub

</td>
</tr>
</table>

---

## 🏗 Architecture

```mermaid
flowchart TD
    A[👤 Telegram User] -->|Uploads injury photo| B[🤖 Telegram Bot]
    B -->|Forwards image| C[⚡ FastAPI Backend]
    C -->|Sends image + prompt| D[🧠 Gemini 2.5 Flash Vision]
    D -->|Structured JSON response| E{🎯 Emergency Decision Engine}
    E -->|High severity| F[🚑 Ambulance Dispatch]
    E -->|Moderate severity| G[🏥 Hospital Allocation]
    E -->|Low severity| H[🩹 First Aid Card]
    F --> I[(🗃️ SQLite DB)]
    G --> I
    H --> I
    I -->|Live polling| J[📊 React Dashboard]
    B -.->|Instant reply| A

    style A fill:#4A90D9,color:#fff
    style D fill:#8E75B2,color:#fff
    style E fill:#E8734A,color:#fff
    style J fill:#61DAFB,color:#000
```

### Sequence of a Single Emergency

```mermaid
sequenceDiagram
    participant U as User
    participant T as Telegram Bot
    participant API as FastAPI Backend
    participant G as Gemini Vision
    participant DB as SQLite
    participant D as Dashboard

    U->>T: Upload injury image
    T->>API: POST /analyze-image
    API->>G: Image + structured prompt
    G-->>API: Injury type, severity, priority, first aid
    API->>API: Run decision engine
    API->>DB: Persist emergency record
    API-->>T: Assessment + instructions
    T-->>U: First aid + dispatch status
    D->>API: GET /latest-emergency (poll)
    API-->>D: Latest emergency state
```

---

## ⚙️ How It Works

| Step | Action |
|:---:|---|
| 1️⃣ | User uploads an injury image via Telegram |
| 2️⃣ | Telegram Bot forwards it to the backend |
| 3️⃣ | FastAPI backend receives and preprocesses the request |
| 4️⃣ | Gemini 2.5 Flash Vision analyzes the image |
| 5️⃣ | AI returns a structured emergency assessment |
| 6️⃣ | Decision engine determines ambulance/hospital need |
| 7️⃣ | Dashboard updates in real time |
| 8️⃣ | First aid recommendations are shown to the user |

---

## 🎬 Live Demo

<img src="./docs/assets/status-live.svg" alt="Dashboard live status" height="36"/>

<div align="center">

[![Watch the Arogyam AI demo](https://img.youtube.com/vi/G21vyl_xf0Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=G21vyl_xf0Y)

**▲ Click to watch on YouTube**

</div>

The demo walks through the full pipeline end-to-end: a real injury photo sent on Telegram, Gemini's structured analysis coming back with first aid instructions, and the dashboard updating live with priority, ambulance dispatch, and hospital assignment — with a voiceover covering **how Codex and GPT-5.6 were used to build the repo.**

---
## 📸 Screensh

[README truncated for size]

## Detected evidence (automated analysis)

Indexed codebase: 38 recognized source files, 78 KB.
- CSS (language) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- Tailwind CSS (technology) — detected in the code
- FastAPI (technology) — claimed on Devpost, not found in the code
- Google Gemini (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (49 of 49)

```
.gitignore
backend/.env.example
backend/app/data/ambulances.json
backend/app/data/doctors.json
backend/app/data/hospitals.json
backend/app/main.py
backend/app/models/emergency.py
backend/app/routes/analyze.py
backend/app/services/ambulance_service.py
backend/app/services/dispatch_service.py
backend/app/services/doctor_service.py
backend/app/services/hospital_service.py
backend/app/services/mock_ai_service.py
backend/app/services/notification_service.py
backend/app/services/user_service.py
backend/app/services/vision_service.py
backend/app/state.py
backend/README.md
backend/requirements.txt
backend/test_ambulance.py
backend/test_dispatch.py
backend/test_doctor.py
backend/test_hospital.py
frontend/.gitignore
frontend/eslint.config.js
frontend/index.html
frontend/package.json
frontend/README.md
frontend/src/App.css
frontend/src/App.jsx
frontend/src/components/cards/AmbulanceCard.jsx
frontend/src/components/cards/DoctorCard.jsx
frontend/src/components/cards/HospitalCard.jsx
frontend/src/components/cards/PatientCard.jsx
frontend/src/components/layout/Header.jsx
frontend/src/index.css
frontend/src/main.jsx
frontend/src/pages/EmergencyDashboard.jsx
frontend/src/services/api.js
frontend/vite.config.js
LICENSE
README.md
telegram-bot/.env.example
telegram-bot/bot.py
telegram-bot/db.py
telegram-bot/handlers.py
telegram-bot/keyboards.py
telegram-bot/README.md
telegram-bot/requirements.txt
```

### Dependencies

- frontend/package.json: @eslint/js@^10.0.1, @tailwindcss/vite@^4.3.3, @types/react@^19.2.17, @types/react-dom@^19.2.3, @vitejs/plugin-react@^6.0.3, axios@^1.18.1, eslint@^10.6.0, eslint-plugin-react-hooks@^7.1.1, eslint-plugin-react-refresh@^0.5.3, framer-motion@^12.42.2, globals@^17.7.0, lucide-react@^1.25.0, react@^19.2.7, react-dom@^19.2.7, tailwindcss@^4.3.3, vite@^8.1.1

### Recent commits (newest first)

- docs: add SVG banner
- docs: add project screenshots
- feat: integrate Gemini Vision emergency triage workflow
- feat: integrate emergency dashboard with backend
- feat: build AI emergency dispatch pipeline with React dashboard
- feat: connect Telegram bot to FastAPI analysis endpoint
- feat: add image analysis endpoint
- feat: add Telegram image upload and local storage
- feat: add Telegram interactive keyboard and message handlers
- feat: add Telegram bot with /start command
- feat: add emergency request endpoint
- chore: ignore Python cache files
- feat: initialize Arogyam 2.0 backend with FastAPI

## Key source files (fetched from GitHub, selected and truncated for size)

### frontend/package.json

```
{
  "name": "frontend",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint .",
    "preview": "vite preview"
  },
  "dependencies": {
    "@tailwindcss/vite": "^4.3.3",
    "axios": "^1.18.1",
    "framer-motion": "^12.42.2",
    "lucide-react": "^1.25.0",
    "react": "^19.2.7",
    "react-dom": "^19.2.7",
    "tailwindcss": "^4.3.3"
  },
  "devDependencies": {
    "@eslint/js": "^10.0.1",
    "@types/react": "^19.2.17",
    "@types/react-dom": "^19.2.3",
    "@vitejs/plugin-react": "^6.0.3",
    "eslint": "^10.6.0",
    "eslint-plugin-react-hooks": "^7.1.1",
    "eslint-plugin-react-refresh": "^0.5.3",
    "globals": "^17.7.0",
    "vite": "^8.1.1"
  }
}

```

### backend/requirements.txt

```
��a n n o t a t e d - d o c = = 0 . 0 . 4  
 a n n o t a t e d - t y p e s = = 0 . 7 . 0  
 a n y i o = = 4 . 1 4 . 2  
 c e r t i f i = = 2 0 2 6 . 6 . 1 7  
 c h a r s e t - n o r m a l i z e r = = 3 . 4 . 9  
 c l i c k = = 8 . 4 . 2  
 c o l o r a m a = = 0 . 4 . 6  
 d i s t r o = = 1 . 9 . 0  
 f a s t a p i = = 0 . 1 3 9 . 2  
 h 1 1 = = 0 . 1 6 . 0  
 h t t p c o r e = = 1 . 0 . 9  
 h t t p x = = 0 . 2 8 . 1  
 i d n a = = 3 . 1 8  
 j i t e r = = 0 . 1 6 . 0  
 o p e n a i = = 2 . 4 6 . 0  
 p i l l o w = = 1 2 . 3 . 0  
 p y d a n t i c = = 2 . 1 3 . 4  
 p y d a n t i c _ c o r e = = 2 . 4 6 . 4  
 p y t h o n - d o t e n v = = 1 . 2 . 2  
 p y t h o n - m u l t i p a r t = = 0 . 0 . 3 2  
 r e q u e s t s = = 2 . 3 4 . 2  
 s n i f f i o = = 1 . 3 . 1  
 s t a r l e t t e = = 1 . 3 . 1  
 t q d m = = 4 . 6 9 . 0  
 t y p i n g - i n s p e c t i o n = = 0 . 4 . 2  
 t y p i n g _ e x t e n s i o n s = = 4 . 1 6 . 0  
 u r l l i b 3 = = 2 . 7 . 0  
 u v i c o r n = = 0 . 5 1 . 0  
 
```

### telegram-bot/requirements.txt

```
��a n n o t a t e d - d o c = = 0 . 0 . 4  
 a n n o t a t e d - t y p e s = = 0 . 7 . 0  
 a n y i o = = 4 . 1 4 . 2  
 c e r t i f i = = 2 0 2 6 . 6 . 1 7  
 c h a r s e t - n o r m a l i z e r = = 3 . 4 . 9  
 c l i c k = = 8 . 4 . 2  
 c o l o r a m a = = 0 . 4 . 6  
 d i s t r o = = 1 . 9 . 0  
 f a s t a p i = = 0 . 1 3 9 . 2  
 h 1 1 = = 0 . 1 6 . 0  
 h t t p c o r e = = 1 . 0 . 9  
 h t t p x = = 0 . 2 8 . 1  
 i d n a = = 3 . 1 8  
 j i t e r = = 0 . 1 6 . 0  
 o p e n a i = = 2 . 4 6 . 0  
 p i l l o w = = 1 2 . 3 . 0  
 p y d a n t i c = = 2 . 1 3 . 4  
 p y d a n t i c _ c o r e = = 2 . 4 6 . 4  
 p y t h o n - d o t e n v = = 1 . 2 . 2  
 p y t h o n - m u l t i p a r t = = 0 . 0 . 3 2  
 p y t h o n - t e l e g r a m - b o t = = 2 2 . 8  
 r e q u e s t s = = 2 . 3 4 . 2  
 s n i f f i o = = 1 . 3 . 1  
 s t a r l e t t e = = 1 . 3 . 1  
 t q d m = = 4 . 6 9 . 0  
 t y p i n g - i n s p e c t i o n = = 0 . 4 . 2  
 t y p i n g _ e x t e n s i o n s = = 4 . 1 6 . 0  
 u r l l i b 3 = = 2 . 7 . 0  
 u v i c o r n = = 0 . 5 1 . 0  
 
```

### frontend/src/App.jsx

```javascript
import EmergencyDashboard from "./pages/EmergencyDashboard";

export default function App() {
  return <EmergencyDashboard />;
}
```

### frontend/src/main.jsx

```javascript
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
```

### backend/app/main.py

```python
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.models.emergency import EmergencyRequest
from app.routes.analyze import router as analyze_router
from app.state import latest_emergency

app = FastAPI(
    title="Arogyam 2.0 API",
    description="AI Emergency Response Coordinator",
    version="1.0.0"
)
app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:5173"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(analyze_router)


@app.get("/")
def home():
    return {
        "message": "Welcome to Arogyam 2.0 🚑",
        "status": "Running"
    }


@app.get("/health")
def health():
    return {
        "status": "Healthy"
    }

@app.get("/latest-emergency")
def get_latest_emergency():
    return latest_emergency

@app.post("/emergency")
def emergency(request: EmergencyRequest):
    return {
        "message": f"Emergency received for {request.patient_name}"
    }
```

### backend/test_hospital.py

```python
from app.services.hospital_service import get_best_hospital

print(get_best_hospital())
```

### backend/test_ambulance.py

```python
from app.services.ambulance_service import get_best_ambulance

print(get_best_ambulance())
```

### backend/test_doctor.py

```python
from app.services.doctor_service import get_available_doctor

print(get_available_doctor(1))
```

### backend/test_dispatch.py

```python
from app.services.dispatch_service import dispatch_emergency

result = dispatch_emergency()

print(result)
```

[27 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]