Prerequisites
Before installing FinAI, ensure you have the following:Python 3.11+
Download from python.org
Google Gemini API Key
Get your free key from Google AI Studio
Git
Version control system to clone the repository
Email Account (Optional)
Gmail account for password reset functionality
AI Key Required: The Google Gemini API key is essential for AI categorization and chatbot features. FinAI will not function properly without it.
Installation Steps
Clone the Repository
Download the FinAI source code from GitHub:This will create a
finai-expense-manager directory with all the necessary source files.Create Virtual Environment
Set up an isolated Python environment to avoid dependency conflicts:You should see
(venv) prefix in your terminal prompt when activated.Install Dependencies
Install all required Python packages using pip:This installs the following core dependencies:
requirements.txt
Installation typically takes 2-3 minutes depending on your internet speed.
Configure Environment Variables
Create a Add the following environment variables:
.env file in the root directory to store sensitive configuration:.env
Environment Variable Details
| Variable | Purpose | Required | Default |
|---|---|---|---|
SECRET_KEY | Flask session encryption and CSRF protection | Yes | khoa-mac-dinh-khong-an-toan (dev only) |
GEMINI_API_KEY | Google Gemini 2.0 Flash AI API access | Yes | None |
MAIL_USERNAME | Gmail address for sending password reset emails | No | None |
MAIL_PASSWORD | Gmail App Password (not regular password) | No | None |
How to generate a secure SECRET_KEY
How to generate a secure SECRET_KEY
Run this command in your terminal:Copy the output and paste it as your
SECRET_KEY value.How to get a Gmail App Password
How to get a Gmail App Password
- Enable 2-Factor Authentication on your Gmail account
- Go to Google Account → Security → 2-Step Verification → App passwords
- Generate a new app password for “Mail”
- Copy the 16-character password (without spaces) to
MAIL_PASSWORD
Initialize Database
FinAI uses SQLite for data storage, which requires no additional configuration. The database is automatically created when you run the application.The application automatically creates the
Automatic Setup: The database file will be created at
instance/quanlychitieu.db on first run. This path is configured in config.py:config.py
instance directory and initializes all required tables:app/__init__.py
Create Admin Account
Run the setup script to create a superuser account for system management:You should see this confirmation:
What the Script Does
Thecreate_admin.py script performs the following operations:create_admin.py
Verification
Confirm your installation is successful by checking:1. Database Created
1. Database Created
Verify the SQLite database exists:You should see
quanlychitieu.db2. Admin Account Created
2. Admin Account Created
Try logging in with:
- Email:
[email protected] - Password:
admin123
3. AI Integration Working
3. AI Integration Working
After logging in, try the chatbot or add a transaction with a natural language description. If the AI categorizes it correctly, your Gemini API key is configured properly.
Project Structure
Understanding the directory layout:Troubleshooting
ImportError: No module named 'flask'
ImportError: No module named 'flask'
Your virtual environment is not activated or dependencies are not installed.Solution:
AI features not working
AI features not working
Your
GEMINI_API_KEY is missing or invalid.Solution:- Verify the key exists in your
.envfile - Check for extra spaces or quotes around the key
- Generate a new key at Google AI Studio
- Restart the application after updating
.env
Database locked error
Database locked error
Another process is accessing the SQLite database.Solution:
- Close any database browsers (DB Browser for SQLite, etc.)
- Ensure only one instance of the app is running
- Restart the Flask server
Port 5000 already in use
Port 5000 already in use
Another application is using port 5000.Solution:
Edit
run.py to use a different port:run.py
Next Steps
Your FinAI installation is complete! Continue to the Quick Start guide to:Quick Start Guide
Create your first user account and record transactions
API Reference
Explore the REST API endpoints for integration
Production Deployment: This guide covers local development setup. For production deployment on platforms like AWS, Render, or Docker, see the Production Deployment guide.
