ContractIQ is a legal document processing platform that allows users to extract and interrogate legal contracts using advanced AI techniques. This project provides two core functionalities:
- Interrogation - Ask natural language questions about the contract.
- Extraction - Extract key legal information (e.g., effective date, governing law, parties involved) from contract documents in
.docx
and.pdf
formats.
The platform leverages FastAPI for the backend and Angular for the frontend, while using OpenAI's GPT model to process and understand legal contracts.
- Upload
.docx
or.pdf
contract files and extract information. - Ask natural language questions about the content of the contract.
- Uses FastAPI for the backend and Angular for the frontend.
- Utilizes OpenAI's GPT-3.5 for intelligent contract interrogation.
- Chunking, query expansion, and hybrid dense + sparse search to improve accuracy.
- Frontend: Angular (with SCSS)
- Backend: FastAPI (Python)
- AI/ML: OpenAI GPT-3.5 for legal document interrogation
- Deployment: NGINX, Uvicorn, Systemd, AWS EC2
- Python 3.8+
- Node.js & Angular CLI
- NGINX (for deployment)
- OpenAI API key (for GPT integration)
-
Clone the repository and navigate to the backend directory:
git clone https://github.com/yourusername/contract-iq.git cd contract-iq/src/api
-
Create a virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file with your OpenAI API key:touch .env
Inside
.env
, add the following line:OPENAI_API_KEY=your_openai_api_key_here
-
Start FastAPI with Uvicorn:
uvicorn main:app --reload
-
Navigate to the frontend directory:
cd contract-iq/src/app
-
Install dependencies:
npm install
-
Run the Angular development server:
ng serve
-
Access the app at
http://localhost:4200
.
The FastAPI backend provides the core API for contract interrogation and extraction. It includes two primary routes:
/contracts/interrogate
: Interrogates a.docx
file based on natural language queries./contracts/extract
: Extracts key information (effective date, governing law, parties involved) from a legal document.
Once the Angular frontend is running, navigate to the main page where you can upload a contract, ask questions, and view the extracted legal information.
Interrogates the contract with natural language questions.
-
Request Parameters:
query
: Natural language question.file
:.docx
or.pdf
contract file.
-
Response:
answer
: Answer generated based on the context of the contract.
Extracts key contract information from a .docx
or .pdf
file.
-
Request Parameters:
file
:.docx
or.pdf
contract file.
-
Response:
data
: A formatted result with effective date, governing law, and parties involved.
The Angular frontend allows users to upload legal contracts and ask questions interactively.
- Drag and drop contract upload
- Interrogator and extractor tools with a user-friendly interface
- Responsive design using Angular Material
- HomeComponent: Introduction and overview of the app.
- InterrogatorComponent: The interface for querying contracts.
- ExtractorComponent: The interface for extracting contract details.
The backend is built using FastAPI and uses OpenAI's GPT-3.5 for language processing.
- File Upload: The
.docx
or.pdf
file is uploaded to FastAPI. - Text Extraction: The text is extracted using libraries like
python-docx
for.docx
andPyMuPDF
for.pdf
. - Chunking: The extracted text is chunked for efficient processing.
- Query Expansion: The input query is expanded using synonyms for better accuracy.
- AI Processing: The query and relevant chunks are passed to OpenAI's GPT to generate the answer.
- document_parser.py: Handles text extraction from
.docx
and.pdf
files. - chunking_processor.py: Breaks down the text into smaller chunks for better querying.
- interrogation.py: Handles interaction with OpenAI's GPT to generate answers.
NGINX is configured as a reverse proxy to serve the frontend and proxy API requests to FastAPI:
server {
server_name contractiq.dulandias.com;
location / {
root /var/www/contractiq.dulandias.com;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}