File size: 6,771 Bytes
9ce3455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# RAG Document Analysis System

![NDMA Logo](https://img.shields.io/badge/NDMA-Government%20of%20India-blue)
![SIH 2025](https://img.shields.io/badge/SIH-2025-green)
![Team](https://img.shields.io/badge/Team-JARVIS%20GGV-purple)

A comprehensive RAG (Retrieval-Augmented Generation) based document analysis system for analyzing disaster management training data. Built for the National Disaster Management Authority (NDMA) as part of Smart India Hackathon 2025.

## 🌟 Features

- **πŸ“€ Multi-Format Upload**: Support for PDF, Excel (.xlsx, .xls), and CSV files
- **πŸ€– AI-Powered Analysis**: Uses Google Gemini AI for intelligent data analysis
- **πŸ“Š Interactive Dashboard**: Beautiful visualizations with charts and metrics
- **πŸ“„ Government Reports**: Auto-generate professional PDF reports in government format
- **πŸ” RAG-based Q&A**: Ask questions about your uploaded documents
- **πŸ’Ύ Data Persistence**: MongoDB storage for analysis history
- **🎨 Modern UI**: Glassmorphism design with smooth animations

## πŸ—οΈ Architecture

```

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚  React Frontend β”‚

β”‚   (Vite + UI)   β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜

         β”‚

         β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚  Express API    β”‚

β”‚  (Node.js)      β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜

         β”‚

    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”

    β–Ό         β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚MongoDB β”‚ β”‚Gemini AI β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

```

## πŸš€ Quick Start

### Prerequisites

- Node.js (v18 or higher)
- MongoDB (local or Atlas)
- Google Gemini API Key

### Installation

1. **Clone the repository**
```bash

cd "c:\Users\91979\OneDrive\Desktop\Rag Model"

```

2. **Setup Backend**
```bash

cd backend

npm install

```

3. **Configure Environment Variables**

Edit `backend/.env` and add your credentials:
```env

GEMINI_API_KEY=your_gemini_api_key_here

MONGODB_URI=mongodb://localhost:27017/rag-document-analysis

```

4. **Setup Frontend**
```bash

cd ../frontend

npm install

```

### Running the Application

1. **Start MongoDB** (if running locally)
```bash

mongod

```

2. **Start Backend Server**
```bash

cd backend

npm run dev

```
Backend will run on `http://localhost:5000`

3. **Start Frontend** (in a new terminal)
```bash

cd frontend

npm run dev

```
Frontend will run on `http://localhost:5173`

4. **Open in Browser**
Navigate to `http://localhost:5173`

## πŸ“– Usage Guide

### 1. Upload Training Data

- Click on the upload area or drag & drop your file
- Supported formats: PDF, Excel, CSV
- Maximum file size: 10MB
- Click "Upload & Analyze"

### 2. View Analysis Dashboard

- Automatic analysis using AI
- View key metrics (trainings, participants, completion rates)
- Interactive charts for theme and state distribution
- Gap analysis showing underserved areas
- Key insights and recommendations

### 3. Download Report

- Click on "Report" tab
- Preview the government-format report
- Download as PDF
- Share with stakeholders

## πŸ“ Project Structure

```

Rag Model/

β”œβ”€β”€ backend/

β”‚   β”œβ”€β”€ models/

β”‚   β”‚   └── Document.js          # MongoDB schema

β”‚   β”œβ”€β”€ routes/

β”‚   β”‚   β”œβ”€β”€ upload.js            # Upload endpoints

β”‚   β”‚   └── analysis.js          # Analysis endpoints

β”‚   β”œβ”€β”€ services/

β”‚   β”‚   β”œβ”€β”€ documentParser.js    # PDF/Excel/CSV parser

β”‚   β”‚   β”œβ”€β”€ ragEngine.js         # RAG implementation

β”‚   β”‚   β”œβ”€β”€ analysisService.js   # AI analysis logic

β”‚   β”‚   └── reportGenerator.js   # PDF report generation

β”‚   β”œβ”€β”€ server.js                # Express server

β”‚   └── package.json

β”‚

β”œβ”€β”€ frontend/

β”‚   β”œβ”€β”€ src/

β”‚   β”‚   β”œβ”€β”€ components/

β”‚   β”‚   β”‚   β”œβ”€β”€ FileUpload.jsx   # Upload component

β”‚   β”‚   β”‚   β”œβ”€β”€ AnalysisDashboard.jsx  # Dashboard

β”‚   β”‚   β”‚   └── ReportPreview.jsx      # Report preview

β”‚   β”‚   β”œβ”€β”€ App.jsx              # Main app

β”‚   β”‚   β”œβ”€β”€ main.jsx             # Entry point

β”‚   β”‚   └── index.css            # Styles

β”‚   β”œβ”€β”€ index.html

β”‚   β”œβ”€β”€ vite.config.js

β”‚   └── package.json

β”‚

└── README.md

```

## πŸ”§ API Endpoints

### Upload & Analysis
- `POST /api/upload` - Upload and analyze document
- `GET /api/upload/documents` - Get all documents
- `GET /api/upload/document/:id` - Get specific document
- `DELETE /api/upload/document/:id` - Delete document

### Analysis & Reports
- `POST /api/analysis/ask` - Ask question about document (RAG)
- `GET /api/analysis/report/:filename` - Download report
- `GET /api/analysis/stats` - Get aggregate statistics

## 🎨 Tech Stack

**Backend:**
- Node.js + Express
- MongoDB + Mongoose
- Google Gemini AI
- PDFKit (report generation)
- Multer (file uploads)
- pdf-parse, xlsx, csv-parser

**Frontend:**
- React 18
- Vite
- Recharts (data visualization)
- React Dropzone
- Lucide React (icons)
- Axios

## πŸ“Š Sample Data Format

### Excel/CSV Format
```csv

Training ID,Date,Location,State,Theme,Participants,Trainer,Duration,Completion Rate

TR001,2024-01-15,Delhi,Delhi,Earthquake,50,Dr. Sharma,2 days,95%

TR002,2024-01-20,Mumbai,Maharashtra,Flood,75,Mr. Patel,3 days,88%

```

### Analysis Output
```json

{

  "totalTrainings": 150,

  "totalParticipants": 5000,

  "themeDistribution": {

    "Earthquake": 40,

    "Flood": 60,

    "Cyclone": 30

  },

  "stateWiseCoverage": {

    "Delhi": 20,

    "Maharashtra": 35

  },

  "averageCompletionRate": "91%",

  "gapAnalysis": {

    "underservedStates": ["Nagaland", "Mizoram"],

    "underservedThemes": ["Tsunami"]

  },

  "recommendations": [...]

}

```

## πŸ” Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `GEMINI_API_KEY` | Google Gemini API key | Yes |
| `MONGODB_URI` | MongoDB connection string | Yes |
| `PORT` | Backend server port | No (default: 5000) |
| `CLIENT_URL` | Frontend URL for CORS | No (default: http://localhost:5173) |

## 🀝 Contributing

This project was developed for Smart India Hackathon 2025 by Team JARVIS GGV.

## πŸ“ License

MIT License - Feel free to use for educational and government purposes.

## πŸ‘₯ Team JARVIS GGV

Smart India Hackathon 2025  
Problem Statement ID: SIH25258  
Theme: Disaster Management

---

**For Official Use by NDMA, Government of India**