Spaces:
Running
Running
File size: 4,341 Bytes
748a398 63a9040 |
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 |
---
title: Lexibot Api
emoji: π₯
colorFrom: red
colorTo: gray
sdk: docker
pinned: false
license: mit
---
# LexiBot API π€βοΈ
**Headless RAG API for Indian Legal Information**
LexiBot is an AI-powered legal assistant that provides accurate information about Indian laws. Built with FastAPI, LangChain, and Pinecone for scalable, serverless deployment.
---
## π Features
- **Legal RAG System** - Retrieval-Augmented Generation for accurate legal information
- **Context Injection** - Prevents section overlap between different Acts
- **Session Memory** - Maintains conversation context per session
- **REST API** - Clean, headless API for frontend integration
- **Serverless Ready** - Optimized for Hugging Face Spaces deployment
## π Supported Legal Documents
| Act | Description |
|-----|-------------|
| Consumer Protection Act, 2019 | Consumer rights and grievance redressal |
| Motor Vehicles Act, 2019 | Traffic laws, licensing, penalties |
| IPC Harassment Sections | Criminal harassment provisions |
| Domestic Violence Act, 2005 | Protection of women from domestic violence |
| POCSO Act, 2012 | Protection of children from sexual offences |
| Workplace Harassment Act, 2013 | Prevention of sexual harassment at workplace |
---
## π Quick Start
### Prerequisites
- Python 3.10+
- [Pinecone Account](https://www.pinecone.io/) (free tier works)
- [Google AI API Key](https://aistudio.google.com/apikey)
### Installation
```bash
# Clone the repository
git clone https://github.com/yourusername/lexibot-api.git
cd lexibot-api
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
```
### Configuration
```bash
# Copy environment template
cp .env.example .env
# Edit .env with your API keys
GOOGLE_API_KEY=your_google_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=lexibot-legal-docs
```
### Data Ingestion (One-time)
```bash
# Process legal documents and upload to Pinecone
python ingest_optimized.py
```
### Run the API
```bash
# Development mode
uvicorn app:app --reload --port 7860
# Production mode
uvicorn app:app --host 0.0.0.0 --port 7860
```
---
## π‘ API Endpoints
### Health Check
```http
GET /health
```
**Response:**
```json
{
"status": "ok"
}
```
### Chat
```http
POST /chat
Content-Type: application/json
```
**Request Body:**
```json
{
"message": "What are the penalties for drunk driving?",
"session_id": "unique-session-id"
}
```
**Response:**
```json
{
"response": "Under the Motor Vehicles Act, 2019, drunk driving penalties include...",
"sources": ["Motor Vehicles (Amendment) Act, 2019"]
}
```
---
## π³ Docker Deployment
### Build and Run Locally
```bash
docker build -t lexibot-api .
docker run -p 7860:7860 --env-file .env lexibot-api
```
### Deploy to Hugging Face Spaces
1. Create a new Space with **Docker SDK**
2. Push this repository to the Space
3. Add secrets in Settings:
- `GOOGLE_API_KEY`
- `PINECONE_API_KEY`
---
## ποΈ Project Structure
```
lexibot-api/
βββ app.py # FastAPI application
βββ ingest_optimized.py # Data ingestion with Context Injection
βββ requirements.txt # Python dependencies
βββ Dockerfile # HuggingFace Spaces optimized
βββ .env.example # Environment template
βββ RawData/ # Raw legal documents (.txt)
βββ README.md # This file
```
---
## π§ Technical Stack
| Component | Technology |
|-----------|------------|
| API Framework | FastAPI |
| Vector Database | Pinecone (Serverless) |
| LLM | Google Gemini 2.0 Flash |
| Embeddings | Google embedding-001 |
| Orchestration | LangChain |
| Hosting | Hugging Face Spaces |
---
## β οΈ Legal Disclaimer
> **This bot provides informational content only and is NOT a substitute for professional legal advice.**
>
> Always consult a qualified lawyer for specific legal matters. Laws are subject to change; verify current status before relying on any information.
---
## π License
MIT License - See [LICENSE](LICENSE) for details.
---
## π€ Contributing
Contributions are welcome! Please open an issue or submit a pull request.
---
**Built with β€οΈ for Indian Legal Accessibility**
|