|
|
--- |
|
|
title: AI FINANCIAL INSIGHTS |
|
|
emoji: π |
|
|
colorFrom: green |
|
|
colorTo: yellow |
|
|
sdk: docker |
|
|
pinned: true |
|
|
--- |
|
|
|
|
|
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference |
|
|
|
|
|
## AI Financial Insights |
|
|
|
|
|
AI Financial Insights provides personalized spending summaries that mirror the AI-driven budgeting direction outlined for WalletSync, helping users spot changing expense patterns before overspending occurs. The service analyzes up to the three most recent months of transaction history (or gracefully handles brand-new users) and surfaces conversational insights such as βYour grocery expenses increased by 22% this month compared to last month.β |
|
|
|
|
|
### Features |
|
|
- FastAPI backend with `/insights` endpoint that accepts a list of transactions and returns contextual insights per category plus overall month-over-month highlights. |
|
|
- Logic considers up to the latest three months of data; if less history is available, it adapts without errors. |
|
|
- Dockerfile tailored for Hugging Face Spaces (listening on port `7860`). |
|
|
|
|
|
### Project structure |
|
|
``` |
|
|
. |
|
|
βββ app |
|
|
β βββ __init__.py |
|
|
β βββ main.py # FastAPI entrypoint |
|
|
β βββ schemas.py # Pydantic models |
|
|
β βββ services.py # Insight generation logic |
|
|
βββ requirements.txt |
|
|
βββ Dockerfile |
|
|
``` |
|
|
|
|
|
### Local development |
|
|
1. Create a virtual environment and install dependencies: |
|
|
``` |
|
|
python -m venv .venv |
|
|
.\.venv\Scripts\activate |
|
|
python -m pip install --upgrade pip |
|
|
python -m pip install -r requirements.txt |
|
|
``` |
|
|
2. Export your Mongo connection string (provided by WalletSync) before running the API: |
|
|
``` |
|
|
setx MONGODB_URI "mongodb://expenseuser:Kem_6o%3F%3F@165.227.69.221:27017/expense?authSource=admin" |
|
|
``` |
|
|
3. Run the FastAPI server (per user rule, use `python3` to launch uvicorn): |
|
|
``` |
|
|
python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8000 |
|
|
``` |
|
|
4. Open the docs at `http://localhost:8000/docs`. |
|
|
|
|
|
### Request example |
|
|
``` |
|
|
POST /insights |
|
|
{ |
|
|
"user_id": "demo-user", |
|
|
"transactions": [ |
|
|
{"timestamp": "2025-09-05T10:00:00Z", "category": "Groceries", "amount": 120.5, "currency": "INR"}, |
|
|
{"timestamp": "2025-10-04T11:00:00Z", "category": "Groceries", "amount": 150.0, "currency": "INR"}, |
|
|
{"timestamp": "2025-10-15T09:30:00Z", "category": "Travel", "amount": 2000.0, "currency": "INR"} |
|
|
] |
|
|
} |
|
|
``` |
|
|
|
|
|
### Docker (Hugging Face Space) |
|
|
Build and test locally: |
|
|
``` |
|
|
docker build -t ai-financial-insights . |
|
|
docker run -it -p 7860:7860 ai-financial-insights |
|
|
``` |
|
|
When deploying on Hugging Face, add `MONGODB_URI` as a Space secret so the container can reach your database. |
|
|
|
|
|
### Deploying to Hugging Face |
|
|
1. Log in and clone the Space: |
|
|
``` |
|
|
git clone https://huggingface.co/spaces/LogicGoInfotechSpaces/AI_FINANCIAL_INSIGHTS |
|
|
cd AI_FINANCIAL_INSIGHTS |
|
|
``` |
|
|
2. Copy the project files into the cloned repo and commit: |
|
|
``` |
|
|
git add . |
|
|
git commit -m "Add AI Financial Insights FastAPI app" |
|
|
git push |
|
|
``` |
|
|
3. The Docker Space automatically builds and serves the FastAPI app on port `7860`. Monitor the Space page for build logs and status. |