CoolFace
Apppublic

TheOrbotAI/ai-contract-risk-analyzer

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

⚖️ AI Contract Risk Analyzer

An AI-powered web application for analyzing legal contracts using NLP, Machine Learning, and Large Language Models.

Python Streamlit Gemini HuggingFace License


🧠 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

FeatureDescription
💬 Smart ChatAsk questions about your contract in plain English and get instant AI answers
🚨 Risk AnalysisAutomatic risk scoring (0-100) with category breakdown and keyword detection
📄 AI SummaryConcise plain-English contract summary using BART model
🏷️ NER ExtractionExtract people, organizations, dates, money amounts, and legal references
🕸️ Entity GraphInteractive visual network showing relationships between contract entities
📊 Compare ModeUpload 2 contracts and compare risk scores, keywords, and categories side by side
🌍 Urdu TranslationTranslate contract summary and analysis to Urdu — اردو میں ترجمہ
📄 PDF ReportDownload a professional PDF risk report with all findings
🤖 Gemini AIOptional Gemini 2.5 Flash integration for much better AI responses
🌙 Dark/Light ModeSwitch between beautiful dark purple and clean light themes
💬 Chat HistoryAll questions and answers saved with download option
📥 Download AllDownload summary, risk report, entities, and chat history as files
AnimationsFloating particles, wave background, card hover glow, badge pop-in effects

🛠️ Tech Stack

TechnologyPurpose
StreamlitWeb application framework
Google Flan-T5-BaseLocal LLM for Q&A and risk analysis
Facebook BART-Large-CNNContract summarization
Sentence Transformers (all-MiniLM-L6-v2)Semantic embeddings
FAISSVector similarity search
Google Gemini 2.5 FlashCloud LLM (optional)
PyMuPDF (fitz)PDF text extraction
ReportLabPDF report generation
Deep TranslatorUrdu translation
PyVisInteractive network graphs
HuggingFace TransformersNLP model loading
PythonCore programming language

📁 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)

  1. 1.Go to → https://aistudio.google.com
  2. 2.Click "Get API Key" → Create new key
  3. 3.In the app sidebar → Toggle "Use Gemini AI" → Paste your key
  4. 4.Enjoy much better AI responses!

🚨 Risk Analysis System

The system detects risky legal patterns using weighted keyword matching:

Risk LevelScore RangeColorExample Keywords
🔴 HIGH60-100Rednot liable, no warranty, terminate immediately, as is
🟡 MEDIUM30-59Yellowmay terminate, subject to change, sole discretion
🟢 LOW0-29Greenconfidential, governing law, notice period

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

ModelSizePurpose
google/flan-t5-base250MBLocal Q&A and Risk Analysis
facebook/bart-large-cnn1.6GBContract Summarization
all-MiniLM-L6-v290MBSemantic Embeddings
gemini-2.5-flashCloudAdvanced AI Analysis (Optional)
FAISSVector Similarity Search

📊 How It Works

  1. 1.User uploads PDF contract
  2. 2.Text extracted using PyMuPDF
  3. 3.Text split into chunks (500 chars each)
  4. 4.Embeddings created using Sentence Transformers
  5. 5.FAISS indexes all chunks for fast search
  6. 6.User asks a question
  7. 7.Top relevant chunks retrieved semantically
  8. 8.LLM generates answer from retrieved context
  9. 9.Risk analyzer scans for 30+ risky keywords
  10. 10.Risk score (0-100) calculated with categories
  11. 11.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