--- 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**