Spaces:
Sleeping
Sleeping
iamsims commited on
Commit ·
82d1b17
1
Parent(s): 1da2ffa
dockerized app
Browse files- .dockerignore +67 -0
- Dockerfile +41 -0
- README.md +343 -7
- app.py +106 -0
- docker-compose.yml +28 -0
- docker-run.sh +65 -0
- requirements.txt +2 -1
.dockerignore
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
*.egg-info/
|
| 8 |
+
dist/
|
| 9 |
+
build/
|
| 10 |
+
*.egg
|
| 11 |
+
|
| 12 |
+
# Virtual environments
|
| 13 |
+
.venv/
|
| 14 |
+
venv/
|
| 15 |
+
env/
|
| 16 |
+
ENV/
|
| 17 |
+
|
| 18 |
+
# IDE
|
| 19 |
+
.vscode/
|
| 20 |
+
.idea/
|
| 21 |
+
*.swp
|
| 22 |
+
*.swo
|
| 23 |
+
*~
|
| 24 |
+
|
| 25 |
+
# Jupyter
|
| 26 |
+
.ipynb_checkpoints/
|
| 27 |
+
*.ipynb
|
| 28 |
+
|
| 29 |
+
# Environment files
|
| 30 |
+
.env.local
|
| 31 |
+
.env.*.local
|
| 32 |
+
|
| 33 |
+
# Git
|
| 34 |
+
.git/
|
| 35 |
+
.gitignore
|
| 36 |
+
|
| 37 |
+
# Temporary files
|
| 38 |
+
*.log
|
| 39 |
+
*.sqlite
|
| 40 |
+
*.db
|
| 41 |
+
temp_data/
|
| 42 |
+
qdrant_db/
|
| 43 |
+
merchant_cache.json
|
| 44 |
+
|
| 45 |
+
# Data files (upload via UI instead)
|
| 46 |
+
demo_data/
|
| 47 |
+
data/
|
| 48 |
+
|
| 49 |
+
# Logs
|
| 50 |
+
logs/
|
| 51 |
+
*.log
|
| 52 |
+
|
| 53 |
+
# Docker
|
| 54 |
+
Dockerfile
|
| 55 |
+
docker-compose.yml
|
| 56 |
+
.dockerignore
|
| 57 |
+
|
| 58 |
+
# Documentation
|
| 59 |
+
README.md
|
| 60 |
+
ARCHITECTURE.md
|
| 61 |
+
*.md
|
| 62 |
+
|
| 63 |
+
# macOS
|
| 64 |
+
.DS_Store
|
| 65 |
+
|
| 66 |
+
# Notebooks (testing only)
|
| 67 |
+
notebooks/
|
Dockerfile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.12 slim image
|
| 2 |
+
FROM python:3.12-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
curl \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
|
| 15 |
+
|
| 16 |
+
# Copy requirements first for better caching
|
| 17 |
+
COPY requirements.txt .
|
| 18 |
+
|
| 19 |
+
# Install Python dependencies
|
| 20 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# Copy application code
|
| 23 |
+
COPY . .
|
| 24 |
+
|
| 25 |
+
# Create directories for data persistence
|
| 26 |
+
RUN mkdir -p /app/data /app/logs
|
| 27 |
+
|
| 28 |
+
# Expose Streamlit default port
|
| 29 |
+
EXPOSE 8501
|
| 30 |
+
|
| 31 |
+
# Health check
|
| 32 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 33 |
+
CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 34 |
+
|
| 35 |
+
# Set environment variables
|
| 36 |
+
ENV PYTHONUNBUFFERED=1
|
| 37 |
+
ENV STREAMLIT_SERVER_PORT=8501
|
| 38 |
+
ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 39 |
+
|
| 40 |
+
# Run Streamlit app
|
| 41 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.maxUploadSize=200", "--server.maxMessageSize=200", "--server.runOnSave=true", "--server.enableXsrfProtection=false", "--server.enableCORS=false"]
|
README.md
CHANGED
|
@@ -1,10 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
## Architecture
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
- For chase card:
|
| 10 |
-
>>>>>>> Stashed changes
|
|
|
|
| 1 |
+
# MoneyRAG - Personal Finance Transaction Analysis
|
| 2 |
+
|
| 3 |
+
AI-powered financial transaction analysis using RAG (Retrieval-Augmented Generation) with Model Context Protocol (MCP) integration.
|
| 4 |
+
|
| 5 |
+
## Features
|
| 6 |
+
|
| 7 |
+
- **Smart CSV Ingestion**: Automatically maps any CSV format to standardized transaction schema using LLM
|
| 8 |
+
- **Multi-Provider Support**: Works with Google Gemini and OpenAI models
|
| 9 |
+
- **Merchant Enrichment**: Automatically enriches transactions with web-searched merchant information
|
| 10 |
+
- **Dual Storage**: SQLite for structured queries + Qdrant for semantic search
|
| 11 |
+
- **MCP Integration**: Leverages Model Context Protocol for tool-based agent interactions
|
| 12 |
+
- **Interactive UI**: Streamlit-based web interface for chat-based analysis
|
| 13 |
+
- **Dockerized**: Complete containerized deployment ready for production
|
| 14 |
+
|
| 15 |
## Architecture
|
| 16 |
|
| 17 |
+
```mermaid
|
| 18 |
+
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#fff', 'primaryBorderColor': '#333', 'primaryTextColor': '#333', 'lineColor': '#666' }}}%%
|
| 19 |
+
|
| 20 |
+
graph TD
|
| 21 |
+
%% --- Top Layer: Entry Point ---
|
| 22 |
+
subgraph UI["💻 User Interface"]
|
| 23 |
+
Streamlit["🌐 Streamlit Web App<br/><i>Interactive Dashboard</i>"]
|
| 24 |
+
end
|
| 25 |
+
|
| 26 |
+
%% --- Middle Layer: Split Processes ---
|
| 27 |
+
|
| 28 |
+
%% Left Column: Ingestion (The Write Path)
|
| 29 |
+
subgraph Ingestion["📥 Data Pipeline (Write)"]
|
| 30 |
+
direction TB
|
| 31 |
+
CSV["📄 CSV Upload<br/><i>Raw Data</i>"]
|
| 32 |
+
Mapper["🧠 LLM Mapper<br/><i>Schema Norm.</i>"]
|
| 33 |
+
Enrich["🔍 Web Enrich<br/><i>DuckDuckGo</i>"]
|
| 34 |
+
|
| 35 |
+
CSV --> Mapper
|
| 36 |
+
Mapper --> Enrich
|
| 37 |
+
end
|
| 38 |
+
|
| 39 |
+
%% Right Column: Intelligence (The Read Path)
|
| 40 |
+
subgraph Agent["🤖 AI Orchestration (Read)"]
|
| 41 |
+
direction TB
|
| 42 |
+
Brain["🧩 LangGraph Agent<br/><i>Controller</i>"]
|
| 43 |
+
LLM["✨ LLM Model<br/><i>Gemini / GPT-4</i>"]
|
| 44 |
+
Brain <-->|Inference| LLM
|
| 45 |
+
end
|
| 46 |
+
|
| 47 |
+
subgraph MCP["🔧 MCP Tool Server"]
|
| 48 |
+
direction LR
|
| 49 |
+
SQL_Tool["⚡ SQL Tool<br/><i>Structured</i>"]
|
| 50 |
+
Vector_Tool["🎯 Vector Tool<br/><i>Semantic</i>"]
|
| 51 |
+
end
|
| 52 |
+
|
| 53 |
+
%% --- Bottom Layer: Persistence ---
|
| 54 |
+
subgraph Storage["💾 Storage Layer"]
|
| 55 |
+
direction LR
|
| 56 |
+
SQLite[("🗄️ SQLite")]
|
| 57 |
+
Qdrant[("🔮 Qdrant")]
|
| 58 |
+
end
|
| 59 |
+
|
| 60 |
+
%% --- Connections & Logic ---
|
| 61 |
+
|
| 62 |
+
%% 1. User Actions
|
| 63 |
+
Streamlit -->|1. Upload| CSV
|
| 64 |
+
Streamlit -->|3. Query| Brain
|
| 65 |
+
|
| 66 |
+
%% 2. Ingestion to Storage flow
|
| 67 |
+
Enrich -->|2. Store| SQLite
|
| 68 |
+
Enrich -->|2. Embed| Qdrant
|
| 69 |
+
|
| 70 |
+
%% 3. Agent to Tools flow
|
| 71 |
+
Brain -->|4. Route| SQL_Tool
|
| 72 |
+
Brain -->|4. Route| Vector_Tool
|
| 73 |
+
|
| 74 |
+
%% 4. Tools to Storage flow (Vertical alignment matches)
|
| 75 |
+
SQL_Tool <-->|5. Read/Write| SQLite
|
| 76 |
+
Vector_Tool <-->|5. Search| Qdrant
|
| 77 |
+
|
| 78 |
+
%% 5. Return Path
|
| 79 |
+
Brain -.->|6. Response| Streamlit
|
| 80 |
+
|
| 81 |
+
%% --- Styling ---
|
| 82 |
+
classDef ui fill:#E3F2FD,stroke:#1565C0,stroke-width:2px,color:#0D47A1,rx:10,ry:10
|
| 83 |
+
classDef ingest fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px,color:#1B5E20,rx:5,ry:5
|
| 84 |
+
classDef agent fill:#F3E5F5,stroke:#7B1FA2,stroke-width:2px,color:#4A148C,rx:5,ry:5
|
| 85 |
+
classDef mcp fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px,color:#E65100,rx:5,ry:5
|
| 86 |
+
classDef storage fill:#ECEFF1,stroke:#455A64,stroke-width:2px,color:#263238,rx:5,ry:5
|
| 87 |
+
|
| 88 |
+
class Streamlit ui
|
| 89 |
+
class CSV,Mapper,Enrich ingest
|
| 90 |
+
class Brain,LLM agent
|
| 91 |
+
class SQL_Tool,Vector_Tool mcp
|
| 92 |
+
class SQLite,Qdrant storage
|
| 93 |
+
|
| 94 |
+
%% Curve the lines for better readability
|
| 95 |
+
linkStyle default interpolate basis
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## Quick Start
|
| 99 |
+
|
| 100 |
+
### Option 1: Docker (Recommended)
|
| 101 |
+
|
| 102 |
+
1. **Run the application**
|
| 103 |
+
```bash
|
| 104 |
+
./docker-run.sh
|
| 105 |
+
```
|
| 106 |
+
Choose option 1 to build and run.
|
| 107 |
+
|
| 108 |
+
2. **Access the app**
|
| 109 |
+
Open browser: http://localhost:8501
|
| 110 |
+
|
| 111 |
+
3. **Enter your API key**
|
| 112 |
+
- Select your LLM provider (Google or OpenAI)
|
| 113 |
+
- Choose your model
|
| 114 |
+
- Enter your API key in the sidebar
|
| 115 |
+
- Click "Authenticate"
|
| 116 |
+
|
| 117 |
+
**Note:** No `.env` file is required! API keys are entered through the web interface.
|
| 118 |
+
|
| 119 |
+
### Option 2: Local Development
|
| 120 |
+
|
| 121 |
+
1. **Install dependencies**
|
| 122 |
+
```bash
|
| 123 |
+
python -m venv .venv
|
| 124 |
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
| 125 |
+
pip install -r requirements.txt
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
2. **Run Streamlit app**
|
| 129 |
+
```bash
|
| 130 |
+
streamlit run app.py
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
3. **Access the app**
|
| 134 |
+
Open browser: http://localhost:8501
|
| 135 |
+
|
| 136 |
+
## Usage
|
| 137 |
+
|
| 138 |
+
1. **Authenticate**: Enter your API key in the sidebar
|
| 139 |
+
2. **Upload CSV**: Upload one or more transaction CSV files
|
| 140 |
+
3. **Ask Questions**: Chat with your financial data:
|
| 141 |
+
- "How much did I spend on restaurants last month?"
|
| 142 |
+
- "What are my largest expenses?"
|
| 143 |
+
- "Show me all transactions over $100"
|
| 144 |
+
- "Analyze my spending patterns"
|
| 145 |
+
|
| 146 |
+
## CSV Format Support
|
| 147 |
+
|
| 148 |
+
MoneyRAG automatically handles different CSV formats including:
|
| 149 |
+
- **Chase Bank**: Negative values for spending
|
| 150 |
+
- **Discover**: Positive values for spending
|
| 151 |
+
- **Custom formats**: LLM-based column mapping
|
| 152 |
+
|
| 153 |
+
Required information (can have any column names):
|
| 154 |
+
- Date
|
| 155 |
+
- Merchant/Description
|
| 156 |
+
- Amount
|
| 157 |
+
- Category (optional)
|
| 158 |
+
|
| 159 |
+
## Project Structure
|
| 160 |
+
|
| 161 |
+
```
|
| 162 |
+
money_rag/
|
| 163 |
+
├── app.py # Streamlit UI
|
| 164 |
+
├── money_rag.py # Core RAG engine
|
| 165 |
+
├── mcp_server.py # MCP server with tools
|
| 166 |
+
├── requirements.txt # Python dependencies
|
| 167 |
+
├── Dockerfile # Container definition
|
| 168 |
+
├── docker-compose.yml # Docker orchestration
|
| 169 |
+
├── docker-run.sh # Helper script
|
| 170 |
+
└── utils/
|
| 171 |
+
└── data_ingestion.py # Data processing utilities
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
## Docker Commands
|
| 175 |
+
|
| 176 |
+
### Using the Helper Script
|
| 177 |
+
```bash
|
| 178 |
+
./docker-run.sh
|
| 179 |
+
```
|
| 180 |
+
Interactive menu with options:
|
| 181 |
+
- Build and run
|
| 182 |
+
- Start/stop
|
| 183 |
+
- View logs
|
| 184 |
+
- Clean up
|
| 185 |
+
|
| 186 |
+
### Manual Docker Compose Commands
|
| 187 |
+
|
| 188 |
+
**Build and start:**
|
| 189 |
+
```bash
|
| 190 |
+
docker-compose up -d --build
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
**Stop:**
|
| 194 |
+
```bash
|
| 195 |
+
docker-compose down
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
**View logs:**
|
| 199 |
+
```bash
|
| 200 |
+
docker-compose logs -f
|
| 201 |
+
```
|
| 202 |
+
|
| 203 |
+
**Rebuild after code changes:**
|
| 204 |
+
```bash
|
| 205 |
+
docker-compose build --no-cache
|
| 206 |
+
docker-compose up -d
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
## Configuration
|
| 210 |
+
|
| 211 |
+
### API Keys
|
| 212 |
+
|
| 213 |
+
**API keys are entered through the Streamlit UI** - no environment variables needed!
|
| 214 |
+
|
| 215 |
+
For standalone MCP server or development, optionally create a `.env` file:
|
| 216 |
+
```bash
|
| 217 |
+
cp .env.example .env
|
| 218 |
+
# Edit with your keys (optional)
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
### Supported Models
|
| 222 |
+
|
| 223 |
+
**Google (via Google AI Studio):**
|
| 224 |
+
- gemini-2.0-flash-exp
|
| 225 |
+
- gemini-1.5-flash
|
| 226 |
+
- gemini-1.5-pro
|
| 227 |
+
|
| 228 |
+
**OpenAI:**
|
| 229 |
+
- gpt-4o
|
| 230 |
+
- gpt-4o-mini
|
| 231 |
+
|
| 232 |
+
### Data Storage
|
| 233 |
+
|
| 234 |
+
- **SQLite**: Structured transaction data (session-based)
|
| 235 |
+
- **Qdrant**: Vector embeddings for semantic search (session-based)
|
| 236 |
+
- **Temporary**: All data is ephemeral per session
|
| 237 |
+
|
| 238 |
+
## Troubleshooting
|
| 239 |
+
|
| 240 |
+
### Container won't start
|
| 241 |
+
```bash
|
| 242 |
+
docker-compose logs
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
### Check container health
|
| 246 |
+
```bash
|
| 247 |
+
docker ps
|
| 248 |
+
docker inspect money-rag-app | grep Health
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
### Reset everything
|
| 252 |
+
```bash
|
| 253 |
+
docker-compose down -v
|
| 254 |
+
docker rmi money_rag-money-rag
|
| 255 |
+
./docker-run.sh # Choose option 1
|
| 256 |
+
```
|
| 257 |
+
|
| 258 |
+
### MCP Server Issues
|
| 259 |
+
The MCP server runs as a subprocess. If you see connection errors:
|
| 260 |
+
1. Check logs: `docker-compose logs -f`
|
| 261 |
+
2. Verify mcp_server.py exists: `docker exec money-rag-app ls -la`
|
| 262 |
+
|
| 263 |
+
### Permission Issues
|
| 264 |
+
```bash
|
| 265 |
+
chmod +x docker-run.sh
|
| 266 |
+
sudo chown -R $USER:$USER data logs
|
| 267 |
+
```
|
| 268 |
+
|
| 269 |
+
## Production Deployment
|
| 270 |
+
|
| 271 |
+
### Using Docker Hub
|
| 272 |
+
|
| 273 |
+
1. **Tag and push:**
|
| 274 |
+
```bash
|
| 275 |
+
docker tag money-rag:latest your-username/money-rag:latest
|
| 276 |
+
docker push your-username/money-rag:latest
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
2. **Pull and run on server:**
|
| 280 |
+
```bash
|
| 281 |
+
docker pull your-username/money-rag:latest
|
| 282 |
+
docker run -d -p 8501:8501 your-username/money-rag:latest
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
### Cloud Platforms
|
| 286 |
+
|
| 287 |
+
**Google Cloud Run:**
|
| 288 |
+
```bash
|
| 289 |
+
gcloud builds submit --tag gcr.io/PROJECT-ID/money-rag
|
| 290 |
+
gcloud run deploy money-rag \
|
| 291 |
+
--image gcr.io/PROJECT-ID/money-rag \
|
| 292 |
+
--platform managed \
|
| 293 |
+
--allow-unauthenticated
|
| 294 |
+
```
|
| 295 |
+
|
| 296 |
+
**AWS ECS / Azure Container Instances:**
|
| 297 |
+
- Build and push to respective container registries
|
| 298 |
+
- Deploy using platform-specific CLI tools
|
| 299 |
+
|
| 300 |
+
## Security Notes
|
| 301 |
+
|
| 302 |
+
⚠️ **Important:**
|
| 303 |
+
- API keys are entered via UI and stored only in session state (not persisted)
|
| 304 |
+
- Keys are cleared when browser session ends
|
| 305 |
+
- Transaction data is session-based and ephemeral
|
| 306 |
+
- No sensitive data stored in environment variables or files
|
| 307 |
+
- For production, implement secure session management and authentication
|
| 308 |
+
|
| 309 |
+
## Development
|
| 310 |
+
|
| 311 |
+
### Hot Reload
|
| 312 |
+
Mount code as volume in docker-compose.yml:
|
| 313 |
+
```yaml
|
| 314 |
+
volumes:
|
| 315 |
+
- ./app.py:/app/app.py
|
| 316 |
+
- ./money_rag.py:/app/money_rag.py
|
| 317 |
+
- ./mcp_server.py:/app/mcp_server.py
|
| 318 |
+
```
|
| 319 |
+
|
| 320 |
+
### Testing
|
| 321 |
+
```bash
|
| 322 |
+
# Run unit tests (if available)
|
| 323 |
+
pytest tests/
|
| 324 |
+
|
| 325 |
+
# Test CSV ingestion
|
| 326 |
+
python -c "from money_rag import MoneyRAG; ..."
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
## Technologies
|
| 330 |
+
|
| 331 |
+
- **LangChain**: Agent orchestration and tool integration
|
| 332 |
+
- **LangGraph**: Conversational agent with memory
|
| 333 |
+
- **MCP**: Model Context Protocol via langchain-mcp-adapters
|
| 334 |
+
- **Qdrant**: Vector database for semantic search
|
| 335 |
+
- **SQLite**: Relational database for structured queries
|
| 336 |
+
- **Streamlit**: Web UI framework
|
| 337 |
+
- **FastMCP**: MCP server implementation
|
| 338 |
+
- **DuckDuckGo**: Web search for merchant enrichment
|
| 339 |
+
|
| 340 |
+
## License
|
| 341 |
+
|
| 342 |
+
MIT
|
| 343 |
+
|
| 344 |
+
## Contributing
|
| 345 |
|
| 346 |
+
Contributions welcome! Please open an issue or submit a pull request.
|
|
|
|
|
|
app.py
CHANGED
|
@@ -34,6 +34,112 @@ This app helps you analyze your personal finances using AI.
|
|
| 34 |
Upload your bank/credit card CSV statements to chat with your data semantically.
|
| 35 |
""")
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if "rag" in st.session_state:
|
| 38 |
uploaded_files = st.file_uploader("Upload CSV transactions", accept_multiple_files=True, type=['csv'])
|
| 39 |
|
|
|
|
| 34 |
Upload your bank/credit card CSV statements to chat with your data semantically.
|
| 35 |
""")
|
| 36 |
|
| 37 |
+
# Guides Section
|
| 38 |
+
col1, col2 = st.columns(2)
|
| 39 |
+
|
| 40 |
+
with col1:
|
| 41 |
+
with st.expander("📚 How to get API keys"):
|
| 42 |
+
st.markdown("**Google Gemini API:**")
|
| 43 |
+
st.markdown("🔗 [Get API key from Google AI Studio](https://aistudio.google.com/app/apikey)")
|
| 44 |
+
st.markdown("")
|
| 45 |
+
st.markdown("**OpenAI API:**")
|
| 46 |
+
st.markdown("🔗 [Get API key from OpenAI Platform](https://platform.openai.com/api-keys)")
|
| 47 |
+
|
| 48 |
+
with col2:
|
| 49 |
+
with st.expander("📥 How to download transaction history"):
|
| 50 |
+
st.markdown("**Chase Credit Card:**")
|
| 51 |
+
st.video("https://www.youtube.com/watch?v=gtAFaP9Lts8")
|
| 52 |
+
st.markdown("")
|
| 53 |
+
st.markdown("**Discover Credit Card:**")
|
| 54 |
+
st.video("https://www.youtube.com/watch?v=cry6-H5b0PQ")
|
| 55 |
+
|
| 56 |
+
# Architecture Diagram
|
| 57 |
+
with st.expander("🏗️ How MoneyRAG Works"):
|
| 58 |
+
st.markdown("""
|
| 59 |
+
```mermaid
|
| 60 |
+
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#fff', 'primaryBorderColor': '#333', 'primaryTextColor': '#333', 'lineColor': '#666' }}}%%
|
| 61 |
+
|
| 62 |
+
graph TD
|
| 63 |
+
%% --- Top Layer: Entry Point ---
|
| 64 |
+
subgraph UI["💻 User Interface"]
|
| 65 |
+
Streamlit["🌐 Streamlit Web App<br/><i>Interactive Dashboard</i>"]
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
%% --- Middle Layer: Split Processes ---
|
| 69 |
+
|
| 70 |
+
%% Left Column: Ingestion (The Write Path)
|
| 71 |
+
subgraph Ingestion["📥 Data Pipeline (Write)"]
|
| 72 |
+
direction TB
|
| 73 |
+
CSV["📄 CSV Upload<br/><i>Raw Data</i>"]
|
| 74 |
+
Mapper["🧠 LLM Mapper<br/><i>Schema Norm.</i>"]
|
| 75 |
+
Enrich["🔍 Web Enrich<br/><i>DuckDuckGo</i>"]
|
| 76 |
+
|
| 77 |
+
CSV --> Mapper
|
| 78 |
+
Mapper --> Enrich
|
| 79 |
+
end
|
| 80 |
+
|
| 81 |
+
%% Right Column: Intelligence (The Read Path)
|
| 82 |
+
subgraph Agent["🤖 AI Orchestration (Read)"]
|
| 83 |
+
direction TB
|
| 84 |
+
Brain["🧩 LangGraph Agent<br/><i>Controller</i>"]
|
| 85 |
+
LLM["✨ LLM Model<br/><i>Gemini / GPT-4</i>"]
|
| 86 |
+
Brain <-->|Inference| LLM
|
| 87 |
+
end
|
| 88 |
+
|
| 89 |
+
subgraph MCP["🔧 MCP Tool Server"]
|
| 90 |
+
direction LR
|
| 91 |
+
SQL_Tool["⚡ SQL Tool<br/><i>Structured</i>"]
|
| 92 |
+
Vector_Tool["🎯 Vector Tool<br/><i>Semantic</i>"]
|
| 93 |
+
end
|
| 94 |
+
|
| 95 |
+
%% --- Bottom Layer: Persistence ---
|
| 96 |
+
subgraph Storage["💾 Storage Layer"]
|
| 97 |
+
direction LR
|
| 98 |
+
SQLite[("🗄️ SQLite")]
|
| 99 |
+
Qdrant[("🔮 Qdrant")]
|
| 100 |
+
end
|
| 101 |
+
|
| 102 |
+
%% --- Connections & Logic ---
|
| 103 |
+
|
| 104 |
+
%% 1. User Actions
|
| 105 |
+
Streamlit -->|1. Upload| CSV
|
| 106 |
+
Streamlit -->|3. Query| Brain
|
| 107 |
+
|
| 108 |
+
%% 2. Ingestion to Storage flow
|
| 109 |
+
Enrich -->|2. Store| SQLite
|
| 110 |
+
Enrich -->|2. Embed| Qdrant
|
| 111 |
+
|
| 112 |
+
%% 3. Agent to Tools flow
|
| 113 |
+
Brain -->|4. Route| SQL_Tool
|
| 114 |
+
Brain -->|4. Route| Vector_Tool
|
| 115 |
+
|
| 116 |
+
%% 4. Tools to Storage flow (Vertical alignment matches)
|
| 117 |
+
SQL_Tool <-->|5. Read/Write| SQLite
|
| 118 |
+
Vector_Tool <-->|5. Search| Qdrant
|
| 119 |
+
|
| 120 |
+
%% 5. Return Path
|
| 121 |
+
Brain -.->|6. Response| Streamlit
|
| 122 |
+
|
| 123 |
+
%% --- Styling ---
|
| 124 |
+
classDef ui fill:#E3F2FD,stroke:#1565C0,stroke-width:2px,color:#0D47A1,rx:10,ry:10
|
| 125 |
+
classDef ingest fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px,color:#1B5E20,rx:5,ry:5
|
| 126 |
+
classDef agent fill:#F3E5F5,stroke:#7B1FA2,stroke-width:2px,color:#4A148C,rx:5,ry:5
|
| 127 |
+
classDef mcp fill:#FFF3E0,stroke:#EF6C00,stroke-width:2px,color:#E65100,rx:5,ry:5
|
| 128 |
+
classDef storage fill:#ECEFF1,stroke:#455A64,stroke-width:2px,color:#263238,rx:5,ry:5
|
| 129 |
+
|
| 130 |
+
class Streamlit ui
|
| 131 |
+
class CSV,Mapper,Enrich ingest
|
| 132 |
+
class Brain,LLM agent
|
| 133 |
+
class SQL_Tool,Vector_Tool mcp
|
| 134 |
+
class SQLite,Qdrant storage
|
| 135 |
+
|
| 136 |
+
%% Curve the lines for better readability
|
| 137 |
+
linkStyle default interpolate basis
|
| 138 |
+
```
|
| 139 |
+
""")
|
| 140 |
+
|
| 141 |
+
st.divider()
|
| 142 |
+
|
| 143 |
if "rag" in st.session_state:
|
| 144 |
uploaded_files = st.file_uploader("Upload CSV transactions", accept_multiple_files=True, type=['csv'])
|
| 145 |
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
money-rag:
|
| 5 |
+
build:
|
| 6 |
+
context: .
|
| 7 |
+
dockerfile: Dockerfile
|
| 8 |
+
container_name: money-rag-app
|
| 9 |
+
ports:
|
| 10 |
+
- "8501:8501"
|
| 11 |
+
environment:
|
| 12 |
+
- PYTHONUNBUFFERED=1
|
| 13 |
+
- STREAMLIT_SERVER_PORT=8501
|
| 14 |
+
- STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 15 |
+
# Note: API keys are entered through the Streamlit UI
|
| 16 |
+
# No environment variables required
|
| 17 |
+
volumes:
|
| 18 |
+
# Mount data directory for persistence (optional)
|
| 19 |
+
- ./data:/app/data
|
| 20 |
+
# Mount logs directory
|
| 21 |
+
- ./logs:/app/logs
|
| 22 |
+
restart: unless-stopped
|
| 23 |
+
healthcheck:
|
| 24 |
+
test: ["CMD", "curl", "-f", "http://localhost:8501/_stcore/health"]
|
| 25 |
+
interval: 30s
|
| 26 |
+
timeout: 10s
|
| 27 |
+
retries: 3
|
| 28 |
+
start_period: 10s
|
docker-run.sh
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# MoneyRAG Docker Run Script
|
| 4 |
+
# This script helps you run the application easily
|
| 5 |
+
|
| 6 |
+
set -e
|
| 7 |
+
|
| 8 |
+
echo "🐳 MoneyRAG Docker Setup"
|
| 9 |
+
echo "========================"
|
| 10 |
+
echo "ℹ️ Note: API keys are entered through the web UI"
|
| 11 |
+
echo ""
|
| 12 |
+
|
| 13 |
+
# Check if Docker is running
|
| 14 |
+
if ! docker info > /dev/null 2>&1; then
|
| 15 |
+
echo "❌ Docker is not running. Please start Docker Desktop."
|
| 16 |
+
exit 1
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
# Create data and logs directories
|
| 20 |
+
mkdir -p data logs
|
| 21 |
+
|
| 22 |
+
echo ""
|
| 23 |
+
echo "Choose an option:"
|
| 24 |
+
echo "1) Build and run (first time or after code changes)"
|
| 25 |
+
echo "2) Run existing container"
|
| 26 |
+
echo "3) Stop container"
|
| 27 |
+
echo "4) View logs"
|
| 28 |
+
echo "5) Clean up (remove containers and images)"
|
| 29 |
+
echo ""
|
| 30 |
+
read -p "Enter choice [1-5]: " choice
|
| 31 |
+
|
| 32 |
+
case $choice in
|
| 33 |
+
1)
|
| 34 |
+
echo "🔨 Building Docker image..."
|
| 35 |
+
docker-compose build
|
| 36 |
+
echo "🚀 Starting container..."
|
| 37 |
+
docker-compose up -d
|
| 38 |
+
echo "✅ Application is running at http://localhost:8501"
|
| 39 |
+
echo "📋 View logs with: docker-compose logs -f"
|
| 40 |
+
;;
|
| 41 |
+
2)
|
| 42 |
+
echo "🚀 Starting container..."
|
| 43 |
+
docker-compose up -d
|
| 44 |
+
echo "✅ Application is running at http://localhost:8501"
|
| 45 |
+
;;
|
| 46 |
+
3)
|
| 47 |
+
echo "🛑 Stopping container..."
|
| 48 |
+
docker-compose down
|
| 49 |
+
echo "✅ Container stopped"
|
| 50 |
+
;;
|
| 51 |
+
4)
|
| 52 |
+
echo "📋 Showing logs (Ctrl+C to exit)..."
|
| 53 |
+
docker-compose logs -f
|
| 54 |
+
;;
|
| 55 |
+
5)
|
| 56 |
+
echo "🧹 Cleaning up..."
|
| 57 |
+
docker-compose down -v
|
| 58 |
+
docker rmi money_rag-money-rag 2>/dev/null || true
|
| 59 |
+
echo "✅ Cleanup complete"
|
| 60 |
+
;;
|
| 61 |
+
*)
|
| 62 |
+
echo "❌ Invalid choice"
|
| 63 |
+
exit 1
|
| 64 |
+
;;
|
| 65 |
+
esac
|
requirements.txt
CHANGED
|
@@ -39,4 +39,5 @@ requests>=2.32.5
|
|
| 39 |
tenacity>=9.1.2
|
| 40 |
|
| 41 |
|
| 42 |
-
streamlit
|
|
|
|
|
|
| 39 |
tenacity>=9.1.2
|
| 40 |
|
| 41 |
|
| 42 |
+
streamlit>=1.53.0
|
| 43 |
+
ddgs>=9.10.0
|