Mrigank005 commited on
Commit
63a9040
Β·
verified Β·
1 Parent(s): 56e1ad9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +192 -1
README.md CHANGED
@@ -8,4 +8,195 @@ pinned: false
8
  license: mit
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  license: mit
9
  ---
10
 
11
+ # LexiBot API πŸ€–βš–οΈ
12
+
13
+ **Headless RAG API for Indian Legal Information**
14
+
15
+ LexiBot is an AI-powered legal assistant that provides accurate information about Indian laws. Built with FastAPI, LangChain, and Pinecone for scalable, serverless deployment.
16
+
17
+ ---
18
+
19
+ ## 🌟 Features
20
+
21
+ - **Legal RAG System** - Retrieval-Augmented Generation for accurate legal information
22
+ - **Context Injection** - Prevents section overlap between different Acts
23
+ - **Session Memory** - Maintains conversation context per session
24
+ - **REST API** - Clean, headless API for frontend integration
25
+ - **Serverless Ready** - Optimized for Hugging Face Spaces deployment
26
+
27
+ ## πŸ“š Supported Legal Documents
28
+
29
+ | Act | Description |
30
+ |-----|-------------|
31
+ | Consumer Protection Act, 2019 | Consumer rights and grievance redressal |
32
+ | Motor Vehicles Act, 2019 | Traffic laws, licensing, penalties |
33
+ | IPC Harassment Sections | Criminal harassment provisions |
34
+ | Domestic Violence Act, 2005 | Protection of women from domestic violence |
35
+ | POCSO Act, 2012 | Protection of children from sexual offences |
36
+ | Workplace Harassment Act, 2013 | Prevention of sexual harassment at workplace |
37
+
38
+ ---
39
+
40
+ ## πŸš€ Quick Start
41
+
42
+ ### Prerequisites
43
+
44
+ - Python 3.10+
45
+ - [Pinecone Account](https://www.pinecone.io/) (free tier works)
46
+ - [Google AI API Key](https://aistudio.google.com/apikey)
47
+
48
+ ### Installation
49
+
50
+ ```bash
51
+ # Clone the repository
52
+ git clone https://github.com/yourusername/lexibot-api.git
53
+ cd lexibot-api
54
+
55
+ # Create virtual environment
56
+ python -m venv venv
57
+ source venv/bin/activate # On Windows: venv\Scripts\activate
58
+
59
+ # Install dependencies
60
+ pip install -r requirements.txt
61
+ ```
62
+
63
+ ### Configuration
64
+
65
+ ```bash
66
+ # Copy environment template
67
+ cp .env.example .env
68
+
69
+ # Edit .env with your API keys
70
+ GOOGLE_API_KEY=your_google_api_key
71
+ PINECONE_API_KEY=your_pinecone_api_key
72
+ PINECONE_INDEX_NAME=lexibot-legal-docs
73
+ ```
74
+
75
+ ### Data Ingestion (One-time)
76
+
77
+ ```bash
78
+ # Process legal documents and upload to Pinecone
79
+ python ingest_optimized.py
80
+ ```
81
+
82
+ ### Run the API
83
+
84
+ ```bash
85
+ # Development mode
86
+ uvicorn app:app --reload --port 7860
87
+
88
+ # Production mode
89
+ uvicorn app:app --host 0.0.0.0 --port 7860
90
+ ```
91
+
92
+ ---
93
+
94
+ ## πŸ“‘ API Endpoints
95
+
96
+ ### Health Check
97
+
98
+ ```http
99
+ GET /health
100
+ ```
101
+
102
+ **Response:**
103
+ ```json
104
+ {
105
+ "status": "ok"
106
+ }
107
+ ```
108
+
109
+ ### Chat
110
+
111
+ ```http
112
+ POST /chat
113
+ Content-Type: application/json
114
+ ```
115
+
116
+ **Request Body:**
117
+ ```json
118
+ {
119
+ "message": "What are the penalties for drunk driving?",
120
+ "session_id": "unique-session-id"
121
+ }
122
+ ```
123
+
124
+ **Response:**
125
+ ```json
126
+ {
127
+ "response": "Under the Motor Vehicles Act, 2019, drunk driving penalties include...",
128
+ "sources": ["Motor Vehicles (Amendment) Act, 2019"]
129
+ }
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 🐳 Docker Deployment
135
+
136
+ ### Build and Run Locally
137
+
138
+ ```bash
139
+ docker build -t lexibot-api .
140
+ docker run -p 7860:7860 --env-file .env lexibot-api
141
+ ```
142
+
143
+ ### Deploy to Hugging Face Spaces
144
+
145
+ 1. Create a new Space with **Docker SDK**
146
+ 2. Push this repository to the Space
147
+ 3. Add secrets in Settings:
148
+ - `GOOGLE_API_KEY`
149
+ - `PINECONE_API_KEY`
150
+
151
+ ---
152
+
153
+ ## πŸ—οΈ Project Structure
154
+
155
+ ```
156
+ lexibot-api/
157
+ β”œβ”€β”€ app.py # FastAPI application
158
+ β”œβ”€β”€ ingest_optimized.py # Data ingestion with Context Injection
159
+ β”œβ”€β”€ requirements.txt # Python dependencies
160
+ β”œβ”€β”€ Dockerfile # HuggingFace Spaces optimized
161
+ β”œβ”€β”€ .env.example # Environment template
162
+ β”œβ”€β”€ RawData/ # Raw legal documents (.txt)
163
+ └── README.md # This file
164
+ ```
165
+
166
+ ---
167
+
168
+ ## πŸ”§ Technical Stack
169
+
170
+ | Component | Technology |
171
+ |-----------|------------|
172
+ | API Framework | FastAPI |
173
+ | Vector Database | Pinecone (Serverless) |
174
+ | LLM | Google Gemini 2.0 Flash |
175
+ | Embeddings | Google embedding-001 |
176
+ | Orchestration | LangChain |
177
+ | Hosting | Hugging Face Spaces |
178
+
179
+ ---
180
+
181
+ ## ⚠️ Legal Disclaimer
182
+
183
+ > **This bot provides informational content only and is NOT a substitute for professional legal advice.**
184
+ >
185
+ > Always consult a qualified lawyer for specific legal matters. Laws are subject to change; verify current status before relying on any information.
186
+
187
+ ---
188
+
189
+ ## πŸ“„ License
190
+
191
+ MIT License - See [LICENSE](LICENSE) for details.
192
+
193
+ ---
194
+
195
+ ## 🀝 Contributing
196
+
197
+ Contributions are welcome! Please open an issue or submit a pull request.
198
+
199
+ ---
200
+
201
+ **Built with ❀️ for Indian Legal Accessibility**
202
+