LegalEase is a Streamlit-based AI legal assistant for Indian law. It helps users understand legal questions by retrieving relevant case-law context, mapping IPC sections to BNS sections, and surfacing relevant government schemes in a chat interfaces.
- Answers legal queries in English or Hinglish.
- Retrieves relevant text from
case_data.csvusing TF-IDF + cosine similarity. - Detects IPC sections from the retrieved context and looks up the matching BNS section from
mapping.csv. - Suggests relevant government schemes when the user query matches legal aid, victim support, women safety, cybercrime, or other assistance topics.
flowchart TD
U[User] --> S[Streamlit UI: app.py]
S --> B[backend.py]
B --> R[TF-IDF Search over case_data.csv]
R --> C[Relevant legal context]
B --> M[IPC ↔ BNS mapping.csv]
B --> G[Government schemes matcher]
B --> L[Sarvam chat completion API]
L --> B
B --> S
S --> U
app.pyrenders the chat UI in Streamlit and sends user prompts to the backend.backend.pybuilds the legal response.case_data.csvis searched with TF-IDF and cosine similarity to find relevant legal text.mapping.csvis used to translate IPC sections into BNS sections.- Sarvam API generates the final natural-language reply using the retrieved context.
python -m venv .venv
source .venv/bin/activateOn Windows:
.venv\Scripts\activatepip install -r requirements.txtapp.pybackend.pyschemes.jsonrequirements.txtcase_data.csvmapping.csv
Configure your Sarvam API keys using one of the following methods:
Method A: Streamlit Secrets (Recommended)
Create a file at .streamlit/secrets.toml inside the project root directory and add your API keys:
SARVAM_API_KEYS = "key1,key2,key3"Method B: Environment Variables
Set the SARVAM_API_KEYS environment variable:
- Linux/macOS:
export SARVAM_API_KEYS="key1,key2,key3" - Windows (Cmd):
set SARVAM_API_KEYS="key1,key2,key3" - Windows (PowerShell):
$env:SARVAM_API_KEYS="key1,key2,key3"
streamlit run app.py-
Open the app in your browser after running Streamlit.
-
Try one of the sample prompts on the home screen, such as:
What is the punishment for theft?Domestic violence ke liye kya section hai?Explain dowry laws in IndiaMujhe arrest kiya bina warrant, kya karoon?
-
Watch the app retrieve legal context, map IPC to BNS, and generate a response.
-
Use the Dark Mode toggle in the sidebar to switch themes.
-
Click Start New Conversation to clear the chat and begin again.
- The app expects a working Sarvam API connection in
backend.py. - The legal responses are based on the uploaded dataset and mapping file, so the quality of
case_data.csvandmapping.csvdirectly affects the output. - This project is designed for educational and hackathon use.
.
├── app.py
├── backend.py
├── schemes.json
├── requirements.txt
├── case_data.csv
├── mapping.csv
└── README.md
The project has been refactored with the following improvements:
- Security & API Keys: Hardcoded API keys in
backend.pyhave been removed. Keys are now securely loaded dynamically from Streamlit Secrets (st.secrets) or standard environment variables (SARVAM_API_KEYS). - Correctness of IPC Section Extraction: The regex in
backend.pywas updated to require legal qualifiers (like "Section", "Sec", "IPC", "dhara") before extracting a section number, preventing false positives from matching arbitrary 3-digit numbers such as years (1860) or helpline numbers (1098). - Exact BNS Mapping Resolution: Refactored the mapping logic to search the structured dictionary metadata in the
responsecolumn ofmapping.csvrather than performing loose substring matching. This ensures queries for specific sections (likeSection 37) don't return unrelated sections (likeSection 376). - Government Schemes Database: Government schemes were extracted from the codebase into a clean, maintainable
schemes.jsonconfiguration file. - Modern Theme Contrast: Polished Streamlit dark mode contrast dynamically, solving the problem of unreadable black text on light grey backgrounds for chat input fields in dark mode.