oluinioluwa814/WealthMangementAdvisor
Wealth Management Advisor API
FastAPI service that answers financial education questions using Gemini, a local FAISS index, and CPU sentence-transformer models. It is educational software, not a licensed financial adviser.
Current features
- FastAPI health, readiness, and streaming chat endpoints
- Server-sent event responses from Gemini
- Hugging Face finance dataset ingestion on first start
- FAISS retrieval with local JSON document storage
- CPU-only embedding and reranking
- Basic request validation, rate limiting, CORS, and gzip support
Runtime components
Project structure
app.py FastAPI application
main.py RAG, Gemini, and market-data logic
requirements.txt Python dependencies
finance.index Generated FAISS index
finance_docs.json Generated document metadataMemory and 4 GB deployments
The service is configured for CPU execution and a small dataset slice (train[:2000]). A 4 GB machine may run it, but this is not a guarantee: PyTorch, the embedding model, reranker, Python process, and first-start dataset/index build can create a high memory peak. The first start is the riskiest because it downloads models and builds the index.
For a 4 GB host:
- Use one Uvicorn worker only.
- Do not run multiple replicas on the same host.
- Keep
DATASET_SPLITattrain[:2000]or reduce it. - Build
finance.indexandfinance_docs.jsononce, then reuse them. - Leave at least 1 GB of free disk space for model and dataset caches.
- Monitor memory during the first start; use a 6 to 8 GB host if it is killed by the platform.
The application does not currently use Redis, PostgreSQL, JWT authentication, or a database. Do not configure those services unless you add their implementation.
API endpoints
Example request:
{"query": "How can I plan for inflation?"}Run locally
py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1
py -3 -m pip install -r requirements.txtSet the required secret before starting:
$env:GEMINI_API_KEY = "your-key"
py -3 -m uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1For Linux or a container, use uvicorn app:app --host 0.0.0.0 --port 7860 --workers 1.
Configuration
Do not commit .env files or API keys. Configure secrets through the deployment platform.
Deployment
For Hugging Face Spaces, use a Docker Space or another ASGI-capable deployment. A Gradio Space configuration is not appropriate for this FastAPI entry point. Configure the platform to expose port 7860, provide GEMINI_API_KEY, and persist the generated FAISS files if possible.
User -> FastAPI -> safety check -> FAISS retrieval -> Gemini -> SSE responseThe responses provide financial education only and should not be treated as personalized investment advice.
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
