An intelligent, responsive financial services chatbot built with React + Vite + Tailwind on the frontend and Flask + HuggingFace on the backend. Delivers concise, cited answers to financial questions with a dual-provider LLM architecture β HuggingFace (free, primary) and OpenAI (paid, fallback).
Try asking:
- "What is cryptocurrency?"
- "Explain credit default swap in simple terms"
- "How does compound interest work?"
- "What are the risks of trading stocks?"
Every answer includes valid Investopedia source links for further reading.
| Service | URL |
|---|---|
| Frontend (Vercel) | finsathi-chatbot-madhavp.vercel.app |
| Backend (Render) | madhavp-financial-service-backend.onrender.com |
| GitHub | Madhav-P-2005/LLM_Powered-Financial-Service-ChatBot |
- π¨οΈ Conversational Chat UI β Real-time chat with message history and auto-scroll
- π Curated Knowledge Base β Instant, hand-written answers for high-traffic topics (no API call needed)
- π€ Qwen2.5-7B LLM β Powered by HuggingFace's free Inference API (Qwen2.5-7B-Instruct)
- π OpenAI Fallback β Automatic fallback to OpenAI (gpt-4o-mini) if HuggingFace is down
- π Smart Citations β 200+ verified Investopedia URLs with multi-tier fallback resolution
- β‘ Retry Button β Failed messages show a styled retry button for better UX
- π Dark/Light Mode β Auto-applies based on saved or system preference
- π§Ή Clear Chat & Home β Quick-action toolbar buttons
- π± Fully Responsive β Mobile-first design with Tailwind CSS
- π Secure β API keys loaded from backend
.env, never exposed to the browser
User Question
β
βΌ
ββββββββββββββββββββββ
β Curated KB β βββ Instant response (no API call)
β (6 topics) β Hand-written, verified answers
βββββββββ¬βββββββββββββ
β Not found
βΌ
ββββββββββββββββββββββ
β HuggingFace β βββ FREE (Qwen2.5-7B-Instruct)
β (Primary) β With retry + exponential backoff
βββββββββ¬βββββββββββββ
β Failed / rate-limited
βΌ
ββββββββββββββββββββββ
β OpenAI β βββ PAID fallback (gpt-4o-mini)
β (Fallback) β Only if OPENAI_API_KEY is set
ββββββββββββββββββββββ
- Exact match β Direct lookup from 200+ verified Investopedia URLs
- Partial match β Longest canonical key found inside the user's query
- Heuristic β Auto-generate URL from financial term patterns
- Directory fallback β Link to Investopedia's alphabetical term pages
LLM-Powered Financial Services Chatbot/
β
βββ financial-service-chatbot-backend/
β βββ app.py # Flask entry point (~70 lines)
β βββ routes/
β β βββ __init__.py
β β βββ chat.py # /chat and / endpoints (Blueprint)
β βββ services/
β β βββ __init__.py
β β βββ llm_service.py # HuggingFace + OpenAI dual-provider
β β βββ url_service.py # Investopedia URL generation
β βββ knowledge/
β β βββ __init__.py
β β βββ curated_kb.py # Hand-written answers (6 topics)
β β βββ canonical_urls.py # 200+ verified Investopedia URLs
β βββ config/
β β βββ .env # HF_API_TOKEN + OPENAI_API_KEY
β βββ requirements.txt # Python dependencies
β βββ Procfile # Render start command
β βββ Dockerfile # Container config (optional)
β βββ MyEnvironment/ # Python venv (gitignored)
β
βββ financial-service-chatbot-frontend/
β βββ src/
β β βββ components/
β β β βββ Navbar.jsx # Header with theme toggle
β β β βββ Footer.jsx # Footer with social links
β β βββ pages/
β β β βββ HomePage.jsx # Landing page
β β β βββ ChatPage.jsx # Chat UI (Retry/Clear/Home)
β β βββ App.jsx # Router setup
β β βββ main.jsx # React entry point
β β βββ index.css # Global styles
β βββ public/
β β βββ finsathi.svg # Custom favicon
β βββ tailwind.config.js # darkMode: 'class'
β βββ vite.config.js # Vite configuration
β βββ package.json # Node dependencies
β
βββ Readme.md # This file
βββ LICENSE # MIT License
βββ .gitignore # Ignores .env, __pycache__, node_modules, etc.
- Node.js (v18+) and npm
- Python 3.11+
- A free HuggingFace account (for API token)
Open a terminal and navigate to financial-service-chatbot-backend/:
Windows (PowerShell):
python -m venv MyEnvironment
.\MyEnvironment\Scripts\Activate.ps1macOS / Linux:
python3 -m venv MyEnvironment
source MyEnvironment/bin/activatepip install -r requirements.txtCreate the file config/.env with your keys:
# PRIMARY β HuggingFace Inference API (FREE, no expiry)
# Get your token at: https://huggingface.co/settings/tokens
# Click "Create new token" β Select "Read" access β Copy the hf_... token
HF_API_TOKEN=hf_your_actual_token_here
# FALLBACK β OpenAI API (PAID, optional)
# Only needed if you want OpenAI as a backup when HuggingFace is down
# OPENAI_API_KEY=sk-your-key-here
# OPENAI_MODEL=gpt-4o-mini
β οΈ Never commit.envto GitHub! It is already listed in.gitignore.
python app.pyBackend runs at: http://127.0.0.1:5000
You can verify it's working by visiting http://127.0.0.1:5000/ in your browser β you should see:
{ "status": "ok", "providers": { "huggingface": { "configured": true, ... } } }Open a second terminal and navigate to financial-service-chatbot-frontend/:
npm installnpm run devFrontend runs at: http://localhost:5173
Open http://localhost:5173 in your browser, click "Get Started", and try asking:
- "What is a credit card?" β Curated answer (instant)
- "What is dollar cost averaging?" β HuggingFace LLM answer
| Package | Version | Purpose |
|---|---|---|
| React | 18.x | UI library |
| Vite | 7.x | Build tool & dev server |
| Tailwind CSS | 4.x | Utility-first styling |
| Axios | 1.x | HTTP client for API calls |
| React Router | 6.x | Client-side routing |
| React Icons | 5.x | Icon library (FaPaperPlane, FaSpinner, etc.) |
| Package | Version | Purpose |
|---|---|---|
| Flask | 3.x | Web framework |
| Flask-CORS | 4.x | Cross-origin support for frontend |
| huggingface_hub | 0.25+ | Primary LLM β HuggingFace Inference API |
| openai | 1.x | Fallback LLM β OpenAI API (optional) |
| python-dotenv | 1.x | Load .env variables |
| gunicorn | 23.x | Production WSGI server (Render) |
| Variable | Required | Description |
|---|---|---|
HF_API_TOKEN |
β Yes | Free HuggingFace Inference API token |
OPENAI_API_KEY |
β Optional | Paid OpenAI API key (fallback only) |
OPENAI_MODEL |
β Optional | OpenAI model name (default: gpt-4o-mini) |
| Variable | Required | Description |
|---|---|---|
VITE_API_BASE |
β For production | Backend URL (e.g., https://madhavp-financial-service-backend.onrender.com) |
GET /
Response:
{
"status": "ok",
"providers": {
"huggingface": { "configured": true, "model": "Qwen/Qwen2.5-7B-Instruct", "role": "primary (free)" },
"openai": { "configured": false, "model": "gpt-4o-mini", "role": "fallback (paid)" }
}
}POST /chat
Content-Type: application/json
Request:
{ "message": "What is a credit default swap?" }Response:
{ "response": "Credit Default Swap (CDS) β Plain-English definition\nβ’ A CDS is a derivative contract...\nSource: https://www.investopedia.com/terms/c/creditdefaultswap.asp" }Error Response (500):
{ "error": "Sorry, I couldn't process your question right now. Error: ..." }CORS is configured for http://localhost:5173 (dev) and https://finsathi-chatbot-madhavp.vercel.app (production).
- Create a new Web Service on Render.
- Connect your GitHub repository and select the branch (
Project-3). - Configure the service:
| Setting | Value |
|---|---|
| Name | madhavp-financial-service-backend |
| Runtime | Python 3 |
| Root Directory | financial-service-chatbot-backend |
| Build Command | pip install -r requirements.txt |
| Start Command | gunicorn app:app |
- Set Environment Variables in the Render dashboard:
| Key | Value |
|---|---|
HF_API_TOKEN |
hf_your_token_here |
OPENAI_API_KEY |
(optional β only if you have one) |
- Click Deploy. Render will build and start your backend.
- Verify: Visit your Render URL β you should see the health check JSON.
π‘ Tip: Render's free tier spins down after 15 min of inactivity. The first request after sleep may take ~30s (cold start).
- Import your repository on Vercel.
- Configure the project:
| Setting | Value |
|---|---|
| Framework Preset | Vite |
| Root Directory | financial-service-chatbot-frontend |
| Build Command | npm run build |
| Output Directory | dist |
- Set Environment Variables in Vercel dashboard:
| Key | Value |
|---|---|
VITE_API_BASE |
https://madhavp-financial-service-backend.onrender.com |
β οΈ Important: Vite environment variables must start withVITE_to be accessible in the frontend code.
- Click Deploy. Vercel will build the React app and serve it.
- Verify: Open your Vercel URL β Click "Get Started" β Ask a question.
Whenever you push new code to GitHub, both Render and Vercel will auto-redeploy. If you change environment variables (like API tokens), update them in the respective dashboards and trigger a manual redeploy.
PRs and suggestions welcome. Open an issue for bugs or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
Built with π by Madhav P