πWebsite
Know Your Rights is an AI-powered legal assistant that helps users understand their rights under the Indian Penal Code (IPC). The chatbot provides information on fundamental rights, legal procedures, and human rights protections using a knowledge base of Indian legal documents. You can simply ask a question in plain language β like whether a certain action is a crime or what a specific law means β and the chatbot will provide a clear, structured explanation, including punishments, examples, and related laws. Whether you're a student, a concerned citizen, or just curious about your rights, this tool makes complex legal information easy to access and understand.
Demo.of.Chatbot.Working.mp4
Know-Your-Rights/
βββ app.py # Main Streamlit app
βββ process_pdfs.py # Script to generate FAISS index
βββ formatter.py # Formatter using Gemini LLM
βββ just_is.gif # Visual logo/animation
βββ requirements.txt # Dependencies list
βββ .env # API key config (user-provided)
βββ docs/ # Folder for legal PDFs
β βββ Indian Penal Code.pdf
βββ faiss_index/ # FAISS vector index files
β βββ index.faiss
β βββ index.pkl
βββ src/
βββ helper.py # Embedding + retrieval logic
- PDF Preprocessing: IPC PDFs are loaded and split into chunks. Each chunk is converted into numerical embeddings using HuggingFace (all-MiniLM-L6-v2).
- Vector Storage (FAISS): The embeddings are stored in FAISS, a fast vector database that allows semantic search.
- User Input via Streamlit: Users ask legal questions through a chat interface built with Streamlit.
- Semantic Retrieval: The question is embedded and compared to the FAISS index to fetch the most relevant IPC sections.
- Initial Response (LLM 1): A lightweight local model (Flan-T5) generates a basic natural language answer from the retrieved content.
- Structured Formatting (LLM 2): The answer is passed to Gemini 1.5 Flash, which reformats it into a clean legal structure that is easily understood.
- Conversational Memory: Using LangChainβs memory module, chat history is preserved for follow-up questions.
- Why: Provides a fast, interactive, and easy-to-use web interface for Python applications.
- How: Used to build the chatbot UI, display responses, and manage user input/output in real time.
- Why: Efficiently extracts text from PDF documents.
- How: Parses the IPC and other legal PDFs, splitting them into manageable text chunks for further processing.
- Why: Converts text into dense vector embeddings that capture semantic meaning.
- How: Each chunk of legal text is embedded so that similar questions and legal sections are close in vector space, enabling semantic search.
- Why: Provides fast and scalable similarity search over large collections of vectors.
- How: Stores all legal text embeddings, allowing the system to quickly retrieve the most relevant sections for any user query.
- Why: Lightweight, open-source LLM fine-tuned for instruction following and question answering.
- How: Generates initial answers to user questions based on the retrieved legal text, ensuring responses are relevant and concise.
- Why: Advanced LLM capable of understanding context and formatting complex information.*
- How: Reformats the initial answer into a structured, easy-to-understand legal summary (with punishments, explanations, and examples).
- Why: Simplifies LLM orchestration, memory management, and chaining multiple models.
- How: Maintains conversational memory, manages prompt templates, and coordinates the flow between retrieval, answer generation, and formatting.
- Why: Securely manages API keys and environment variables.
- How: Loads sensitive credentials (like the Gemini API key) from a
.envfile, keeping them out of source code.
- Why: Precomputes and stores vector embeddings for all legal documents.
- How:
process_pdfs.pyreads PDFs, splits them, embeds each chunk, and saves the FAISS index for fast runtime retrieval.
- Why: Modularizes code for embedding, retrieval, and formatting logic.
- How:
helper.pyhandles embedding and semantic search.formatter.pyuses Gemini to structure the output.
- Frontend: Streamlit
- LLMs: Flan-T5 (google/flan-t5-small), Gemini 1.5 Flash
- Embeddings: sentence-transformers/all-MiniLM-L6-v2
- Vector DB: FAISS
- PDF Parsing: PyPDF2
- Env Config: python-dotenv
git clone [https://github.com/Sam221104/Know-Your-Rights.git](https://github.com/Sam221104/Know-Your-Rights.git)
cd Know-Your-Rights
On Windows:
python -m venv .venv
Set-ExecutionPolicy Unrestricted -Scope Process
.venv\Scripts\Activate
On macOS/Linux:
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
Create a .env file in the root directory with the following:
GOOGLE_API_KEY=your_google_gemini_api_key_here
python process_pdfs.py
This reads IPC PDFs from the docs/ folder and builds a FAISS index using HuggingFace embeddings.
streamlit run app.py
- Ask Legal Questions in natural language
- Semantic Search across IPC sections using FAISS and HuggingFace embeddings
- Structured Summaries with punishments, explanation, and example cases
- Conversational Memory to retain chat history
Know Your Rights is a digital assistant that helps people easily understand their legal rights under the Indian Penal Code. By allowing users to ask questions in everyday language, it provides clear and concise explanations of laws, punishments, and legal procedures. This tool empowers individuals to make informed decisions, promotes legal awareness, and helps bridge the gap between complex legal language and the general public. Whether you are a student, a concerned citizen, or someone seeking guidance, Know Your Rights makes legal information accessible and understandable for everyone.
