Spaces:
Running
Running
| 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** | |