TheOrbotAI/ai-contract-risk-analyzer
⚖️ AI Contract Risk Analyzer
An AI-powered web application for analyzing legal contracts using NLP, Machine Learning, and Large Language Models.
🧠 Overview
AI Contract Risk Analyzer is a complete AI-powered web application that helps users analyze legal contracts and extract key insights automatically. It uses Local LLM models + Gemini AI + NLP + Vector Search to process and understand legal documents intelligently — all running locally on your machine with no data leaving your device.
🚀 Live Demo
🌐 Deployed App: Click here to try it live
✨ Features
🛠️ Tech Stack
📁 Project Structure
ai-contract-risk-analyzer/ │ ├── app.py ← Main Streamlit application ├── requirements.txt ← All dependencies ├── README.md ← Project documentation │ ├── utils/ │ ├── pdfloader.py ← PDF text extraction │ ├── chunker.py ← Text splitting into chunks │ ├── embeddings.py ← Sentence embeddings │ ├── vectorstore.py ← FAISS vector index │ ├── retriever.py ← Semantic retrieval │ ├── llm.py ← Local Flan-T5 model │ ├── riskanalyzer.py ← Risk scoring & keywords │ ├── summarizer.py ← BART summarization │ ├── nerextractor.py ← Named entity extraction │ ├── entitygraph.py ← PyVis network graph │ ├── geminillm.py ← Gemini AI integration │ ├── translator.py ← Urdu translation │ └── pdfreport.py ← PDF report generation
⚙️ Installation & Setup
1. Clone the repository: git clone https://github.com/Aleesha-Aslam/ai-contract-risk-analyzer.git cd ai-contract-risk-analyzer
2. Install dependencies: pip install -r requirements.txt
3. Run the application: streamlit run app.py
4. Open browser: http://localhost:8501
🔑 Gemini AI Setup (Optional)
- Go to → https://aistudio.google.com
- Click "Get API Key" → Create new key
- In the app sidebar → Toggle "Use Gemini AI" → Paste your key
- Enjoy much better AI responses!
🚨 Risk Analysis System
The system detects risky legal patterns using weighted keyword matching:
5 Category Scores:
- 💰 Payment Terms — Are payment conditions risky?
- ⚖️ Liability — Are liability clauses vague?
- 📅 Termination — Can contract be terminated unfairly?
- 🔒 Confidentiality — Is data protection adequate?
- 📋 Obligations — Are obligations clearly defined?
🤖 AI Models Used
📊 How It Works
- User uploads PDF contract
- Text extracted using PyMuPDF
- Text split into chunks (500 chars each)
- Embeddings created using Sentence Transformers
- FAISS indexes all chunks for fast search
- User asks a question
- Top relevant chunks retrieved semantically
- LLM generates answer from retrieved context
- Risk analyzer scans for 30+ risky keywords
- Risk score (0-100) calculated with categories
- Professional PDF report generated
🌍 Urdu Translation Support
The app supports Urdu translation of:
- 📄 Contract Summary
- 🚨 Risk Analysis Report
- 📝 Full Contract Text
Using Google Translate via deep-translator library with proper RTL (Right-to-Left) text rendering.
🎨 UI Features
- Modern Purple Theme with dark mode
- Floating Particles animated background
- Wave Animation at bottom of screen
- Card Hover Glow effect
- Progress Bar smooth fill animation
- Badge Pop-In bounce animation
- Pulsing Buttons with glow effect
- Custom Purple scrollbar
📋 Requirements
streamlit pymupdf sentence-transformers faiss-cpu transformers torch numpy reportlab deep-translator pyvis google-genai beautifulsoup4
🎓 About This Project
This project was developed as an AI Course Assignment demonstrating:
- Natural Language Processing (NLP)
- Machine Learning and Deep Learning Models
- Large Language Models (LLM)
- Information Retrieval using FAISS Vector Search
- Full Stack Web Application using Streamlit
- API Integration with Gemini AI
- Document Processing with PDF
- Data Visualization using PyVis Graphs
- Urdu Language Support
👩💻 Author
Aleesha Aslam GitHub: https://github.com/Aleesha-Aslam
📜 License
This project is developed for educational purposes as part of an AI course assignment.
Made with ❤️ by Aleesha Aslam ⚖️ AI Contract Risk Analyzer — v3.0 Final
