File size: 6,171 Bytes
388aa42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---

title: JanSahayak
emoji: ๐Ÿ™
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
---


# ๐Ÿ™ JanSahayak - AI-Powered Government Schemes & Exams Assistant

> Your personal AI assistant for discovering government schemes and competitive exam opportunities in India

[![Hugging Face Spaces](https://img.shields.io/badge/๐Ÿค—-Hugging%20Face-yellow)](https://huggingface.co/spaces)
[![Flask](https://img.shields.io/badge/Flask-2.3+-green)](https://flask.palletsprojects.com/)
[![LangChain](https://img.shields.io/badge/LangChain-Latest-blue)](https://www.langchain.com/)

---

## ๐ŸŒŸ Features

### ๐Ÿค– Multi-Agent AI System
- **Profiling Agent**: Extracts structured user information
- **Scheme Agent**: Recommends relevant government schemes  
- **Exam Agent**: Suggests competitive exams based on qualifications
- **RAG Agent**: Retrieves information from curated document database

### ๐Ÿ’ก Intelligent Capabilities
- โœ… Natural language understanding of user profiles
- โœ… Smart recommendations based on eligibility criteria
- โœ… RAG (Retrieval-Augmented Generation) with FAISS vectorstore
- โœ… Real-time web search via Tavily API
- โœ… PDF generation for saving recommendations
- โœ… Beautiful web interface with modern UI

---

## ๐Ÿš€ Deploy to Hugging Face Spaces (Recommended)

### Why Hugging Face Spaces?
- โœ… **16GB RAM for FREE** (perfect for RAG apps!)
- โœ… Built for ML/AI applications
- โœ… Git-based deployment
- โœ… Public URL instantly
- โœ… Persistent storage

### Quick Deploy Steps:

**Method 1: Using HF CLI (Easiest)**

```bash

# Install HF CLI

pip install huggingface_hub[cli]



# Login

huggingface-cli login



# Create Space and push

huggingface-cli repo create jansahayak --type space --space_sdk gradio

git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/jansahayak

git push hf main

```

**Method 2: Manual Setup**

1. **Create Space** on [huggingface.co/spaces](https://huggingface.co/spaces)
   - Click "Create new Space"
   - Name: `jansahayak`
   - SDK: Select "Gradio" (works with Flask)
   - Hardware: CPU basic (Free - 16GB RAM!)
   - License: MIT

2. **Clone YOUR Space repo** (not GitHub!)
   ```bash

   git clone https://huggingface.co/spaces/YOUR_USERNAME/jansahayak

   cd jansahayak

   ```

3. **Copy your project files**
   ```bash

   # Copy all files from your JanSahayak folder to the cloned space folder

   cp -r /path/to/JanSahayak/* .

   ```

4. **Add Environment Variables** (Space Settings โ†’ Variables and secrets)
   ```

   GROQ_API_KEY=your_groq_key

   TAVILY_API_KEY=your_tavily_key  

   HF_TOKEN=your_hf_token (optional)

   SKIP_VECTORSTORES=false

   ```

5. **Push to Space**
   ```bash

   git add .

   git commit -m "Initial commit"

   git push

   ```

Your app will be live at: `https://huggingface.co/spaces/YOUR_USERNAME/jansahayak`

### Important Notes:
- HF Spaces uses its own Git repo (not GitHub directly)
- App runs on port 7860 by default (Flask uses 5000, update if needed)
- First deployment may take 5-10 minutes to install dependencies
- Check Space logs if deployment fails

---

## ๐Ÿ› ๏ธ Local Development

```bash

# Clone and setup

git clone https://github.com/YOUR_USERNAME/JanSahayak.git

cd JanSahayak



# Create virtual environment

python -m venv .venv

source .venv/bin/activate  # Linux/Mac

.venv\Scripts\activate     # Windows



# Install dependencies

pip install -r requirements.txt



# Configure API keys

cp .env.example .env

# Edit .env with your keys



# Build vectorstores (optional - if you have PDFs)

python init_embeddings.py



# Run app

python app.py

# or use launcher scripts: start_web.bat (Windows) / ./start_web.sh (Linux/Mac)

```

Visit `http://localhost:5000`

---

## ๐Ÿ”‘ Get API Keys

| Service | URL | Free Tier | Used For |
|---------|-----|-----------|----------|
| **Groq** | [console.groq.com](https://console.groq.com) | โœ… Yes | LLM Inference |
| **Tavily** | [tavily.com](https://tavily.com) | 1000 searches/mo | Web Search |
| **HuggingFace** | [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) | โœ… Yes | Model Downloads |

---

## ๐Ÿ’พ Adding Custom Documents

### Government Schemes PDFs
1. Place PDFs in `data/schemes_pdfs/`
2. Run `python init_embeddings.py`
3. Restart app

### Exam Information PDFs
1. Place PDFs in `data/exams_pdfs/`
2. Run `python init_embeddings.py`
3. Restart app

Automatically indexed and searchable via RAG!

---

## ๐Ÿงช Technology Stack

- **Backend**: Flask
- **AI**: LangChain + LangGraph  
- **LLM**: Groq (Llama 3.3 70B)
- **Embeddings**: sentence-transformers/all-MiniLM-L6-v2
- **Vector DB**: FAISS (local)
- **Search**: Tavily API
- **Frontend**: HTML5 + CSS3 + JavaScript

---

## ๐Ÿ“ Project Structure

```

JanSahayak/

โ”œโ”€โ”€ app.py                    # Flask web app

โ”œโ”€โ”€ main.py                   # CLI interface

โ”œโ”€โ”€ agents/                   # AI agents

โ”‚   โ”œโ”€โ”€ profiling_agent.py

โ”‚   โ”œโ”€โ”€ scheme_agent.py

โ”‚   โ”œโ”€โ”€ exam_agent.py

โ”‚   โ””โ”€โ”€ rag_agent.py

โ”œโ”€โ”€ rag/                      # RAG components

โ”‚   โ”œโ”€โ”€ embeddings.py

โ”‚   โ”œโ”€โ”€ scheme_vectorstore.py

โ”‚   โ””โ”€โ”€ exam_vectorstore.py

โ”œโ”€โ”€ data/                     # Documents

โ”‚   โ”œโ”€โ”€ schemes_pdfs/

โ”‚   โ””โ”€โ”€ exams_pdfs/

โ”œโ”€โ”€ templates/                # HTML templates

โ””โ”€โ”€ static/                   # CSS/JS

```

---

## ๐Ÿ› Troubleshooting

**Memory issues on local machine?**
```env

# Set in .env

SKIP_VECTORSTORES=true

```
Uses web search only (no embeddings needed)

**Vectorstore errors?**
```bash

rm -rf rag/scheme_index rag/exam_index

python init_embeddings.py

```

---

## ๐Ÿค Contributing

Contributions welcome! Fork โ†’ Create branch โ†’ Submit PR

---

## ๐Ÿ“œ License

MIT License

---

## ๐Ÿ™ Acknowledgments

Built with [LangChain](https://www.langchain.com/), [Groq](https://groq.com/), [Tavily](https://tavily.com/), and โค๏ธ

---

Made for the people of India ๐Ÿ‡ฎ๐Ÿ‡ณ