A modern full-stack web application that uses AI to analyze credit card statements and provide intelligent spending recommendations.
- Upload credit card statement images
- Extract key information using OpenAI Vision API:
- Customer Name
- Card Account Number
- Statement Date
- Total Amount Due
- Minimum Amount Due
- Due Date
- Categorize transactions automatically
- Get AI-powered spending reduction recommendations
- Visualize spending patterns by category
- Python 3.12+
- Flask - Web framework
- LangChain - AI orchestration
- OpenAI GPT-4o-mini - Vision API for image analysis
- Flask-CORS - Cross-origin resource sharing
- HTML5, CSS3, JavaScript
- Modern UI with glassmorphism and animations
- Python 3.12 or higher
- OpenAI API key (Get one here)
- pip (Python package manager)
cd "c:\Users\nad\Desktop\ai assignment"# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activatepip install -r requirements.txt-
Copy the example environment file:
copy .env.example .env
-
Edit
.envfile and add your OpenAI API key:OPENAI_API_KEY=your-api-key-goes-here
python app.pyThe server will start on http://localhost:5000
You should see:
β
OpenAI API key loaded successfully
============================================================
π Credit Card Analysis API Server
============================================================
Phase 1: Statement Data Extraction
Server running on: http://localhost:5000
============================================================
# Test health check
curl http://localhost:5000/
# Test statement extraction
curl -X POST http://localhost:5000/api/extract -F "image=@sample_statements/statement1.png"Create a test file test_api.py:
import requests
# Test extraction
url = "http://localhost:5000/api/extract"
files = {"image": open("sample_statements/statement1.png", "rb")}
response = requests.post(url, files=files)
print(response.json())Run it:
python test_api.py{
"status": "success",
"message": "Statement data extracted successfully",
"data": {
"customer_name": "MR. HITESH KUMAR",
"card_account_number": "4375 XXXX XXXX 8007",
"statement_date": "23/04/2018",
"total_amount_due": "βΉ 8,795.59",
"minimum_amount_due": "βΉ 6,620.00",
"due_date": "11/05/2018"
}
}ai assignment/
βββ app.py # Flask backend application
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (create this)
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
βββ assignment_1.ipynb # Original Jupyter notebook (Assignment 1)
βββ assignment_2.ipynb # Original Jupyter notebook (Assignment 2)
βββ sample_statements/ # Sample credit card statements
β βββ statement1.png
β βββ statement2.png
β βββ statement3.png
βββ README.md # This file
Health check endpoint
Response:
{
"status": "success",
"message": "Credit Card Analysis API is running",
"version": "1.0.0",
"endpoints": {
"extract": "/api/extract",
"analyze": "/api/analyze (Coming in Phase 2)"
}
}Extract credit card statement data from image
Request:
- Method:
POST - Content-Type:
multipart/form-data - Body:
imagefile (PNG, JPG, JPEG, WEBP)
Response:
{
"status": "success",
"message": "Statement data extracted successfully",
"data": {
"customer_name": "string",
"card_account_number": "string",
"statement_date": "string",
"total_amount_due": "string",
"minimum_amount_due": "string",
"due_date": "string"
}
}Error Response:
{
"status": "error",
"message": "Error description"
}Solution: Make sure you've created a .env file with your API key:
OPENAI_API_KEY=sk-your-key-here
Solution: Install dependencies:
pip install -r requirements.txtSolution: Change the port in app.py:
app.run(debug=True, host='0.0.0.0', port=5001) # Use different portSolution: The backend already has CORS enabled via flask-cors. Make sure the backend is running.
- β Phase 1: Backend Foundation & Statement Extraction - COMPLETE
- β³ Phase 2: Backend Spending Analysis - Coming Next
- β³ Phase 3: Frontend Development - Planned
- β³ Phase 4: Integration & Testing - Planned
- Test the
/api/extractendpoint with all sample statements - Verify extraction accuracy
- Move to Phase 2: Implement spending analysis endpoint
This is a learning project for AI-powered credit card analysis. Feel free to experiment and extend!
Educational project - Free to use and modify