This project provides comprehensive financial analysis and AI-powered Q&A for Apple, Microsoft, and Tesla (FY2022-2024). It includes:
- Financial Analysis Notebook - Data processing, metrics calculation, and visualizations
- Rule-Based Chatbot - Keyword-matching Q&A system
- Smart AI Chatbot - LLM-powered natural language understanding
- Web Interface - Dark mode Streamlit UI for easy interaction
Built for the Forage BCGX GenAI program.
| File | Description |
|---|---|
analysis.ipynb |
Jupyter notebook for data cleaning, metrics engineering, and visualization |
chatbot_5.py |
Rule-based command-line chatbot with predefined queries |
smart_chatbot.py |
LLM-powered chatbot engine using Google Gemini API |
chatbot_ui.py |
Streamlit web interface with dark mode theme |
| File | Description |
|---|---|
financial_data.csv |
Raw financial statements (revenue, income, assets, liabilities) |
financial_data_summaryreport.csv |
Processed dataset with calculated metrics and growth rates |
| File | Description |
|---|---|
requirements.txt |
Python dependencies (pandas, streamlit, httpx, etc.) |
.env |
Environment variables (API keys) - not tracked in git |
.env.example |
Template for environment variables |
.gitignore |
Files excluded from version control |
| File | Description |
|---|---|
README.md |
Project overview (this file) |
ChatBot_Documentation.md |
Detailed chatbot usage guide |
pip install -r requirements.txtVisit https://aistudio.google.com/apikey and create a Gemini API key (no credit card required).
Copy .env.example to .env and add your key:
GEMINI_API_KEY=your_actual_key_hereWeb Interface (Recommended):
streamlit run chatbot_ui.pyCommand Line:
python chatbot_5.py # Rule-based
python smart_chatbot.py # LLM-powered (needs setup)The analysis.ipynb notebook performs comprehensive financial analysis:
- Reads
financial_data.csvcontaining raw financial statements - Sorts by Company and Fiscal Year
- Cleans numeric columns and handles formatting
Growth Metrics (Year-over-Year):
- Revenue Growth (%)
- Net Income Growth (%)
- Assets Growth (%)
- Liabilities Growth (%)
- Cash Flow Growth (%)
Quality/Risk Indicators:
- Profit Margin (%) = Net Income / Total Revenue
- Debt to Asset Ratio (%) = Total Liabilities / Total Assets
- Cash Flow Margin (%) = Operating Cash Flow / Total Revenue
- Company-level averages across all fiscal years
- Cross-company performance rankings
- Trend analysis over time
- Line charts: Revenue, net income, assets, liabilities over time
- Bar charts: Profitability metrics comparison
- Bar charts: Growth rates by company
Generates financial_data_summaryreport.csv with all calculated metrics for chatbot use.
Analysis of FY2022-2024 data reveals:
- Microsoft: 11.28% average growth (leader)
- Tesla: 9.87% average growth
- Apple: -0.39% (flat/declining)
- Microsoft: 35.60% profit margin (highest)
- Apple: 24.86% profit margin
- Tesla: 12.75% profit margin (lowest)
- Apple: 84.14% debt-to-asset ratio (most leveraged)
- Microsoft: 50.62% debt-to-asset ratio
- Tesla: 41.41% debt-to-asset ratio (least leveraged)
- Microsoft: 44.87% cash flow margin (best)
- Apple: 30.02% cash flow margin
- Tesla: 15.68% cash flow margin
- Microsoft = Strongest performer in growth quality and profitability
- Apple = Stable but limited growth, high leverage
- Tesla = High asset growth but volatile earnings (net income dropped 52% in FY2024)
Type: Keyword-matching Q&A
Setup: None required
Run: python chatbot_5.py
Supported Queries:
- Total revenue for each company
- Net income year-on-year change
- Which company has highest profit margin
- Debt-to-asset ratio by company
- Operating cash flow trends
- Company-specific revenue growth
- Company-specific asset growth
- Company-specific net income trend
Example Questions:
What is Apple's total revenue in 2023?
How has Tesla's net income changed?
3
menu
Type: LLM-powered (Google Gemini)
Setup: Requires API key (free)
Run: python smart_chatbot.py (command-line) or via chatbot_ui.py (web interface)
Features:
- Natural language understanding (ask in your own words)
- Concise 2-4 sentence answers with exact numbers
- Only answers from available data (no hallucinations)
- Interprets complex comparative questions
How It Works:
- Loads entire financial dataset as context
- Sends your question + data to Gemini API
- Returns concise, data-backed response
Example Questions:
What is Apple's revenue in 2024?
Which company has the highest profit margin?
How has Tesla's net income changed over the years?
Compare Microsoft and Apple debt ratios
What are the key financial findings?
Which company performed best in profitability?
Type: Streamlit web UI powered by Smart AI Chatbot
Setup: Requires API key (free)
Run: streamlit run chatbot_ui.py
Features:
- Dark mode theme (#0f0f0f background, #2563eb accents)
- Chat interface with message history
- 6 example question buttons for quick access
- Real-time AI responses with "Thinking..." indicator
- Clear chat button to reset conversation
Interface Elements:
- Title: "Financial Analysis Chatbot"
- Companies: Apple | Microsoft | Tesla -- FY2022-2024
- Example buttons in 3-column grid
- Chat input at bottom
- Responses formatted in markdown
- pandas - CSV loading, data manipulation, aggregations
- numpy - Numerical computations
- matplotlib - Line and bar charts
- seaborn - Statistical visualizations
- plotly - Interactive charts
- httpx - HTTP requests to Gemini API
- python-dotenv - Environment variable management
- Google Gemini 2.0 Flash - LLM for natural language understanding
- streamlit - Web framework and UI components
- Custom CSS - Dark mode styling
- Python 3.8+ - Core language
- Jupyter - Notebook environment
BCGX-Forage_GenAI-main/
│
├── analysis.ipynb # Data analysis notebook
├── financial_data.csv # Raw financial data
├── financial_data_summaryreport.csv # Processed data with metrics
│
├── chatbot_5.py # Rule-based chatbot
├── smart_chatbot.py # LLM chatbot engine
├── chatbot_ui.py # Streamlit web interface
│
├── requirements.txt # Python dependencies
├── .env # API keys (create this)
├── .env.example # API key template
├── .gitignore # Git exclusions
│
├── README.md # Project overview (this file)
└── ChatBot_Documentation.md # Detailed chatbot guide
- Python 3.8 or higher
- pip package manager
- Google Gemini API key (free)
-
Clone or download the repository
-
Navigate to project directory
cd BCGX-Forage_GenAI-main -
Install dependencies
pip install -r requirements.txt
-
Get API key
- Visit https://aistudio.google.com/apikey
- Click "Create API Key"
- Copy the generated key
-
Configure environment
# Copy example file cp .env.example .env # Edit .env and add your key GEMINI_API_KEY=your_actual_key_here
-
Run the application
streamlit run chatbot_ui.py
jupyter notebook analysis.ipynbRun all cells to:
- Load and clean raw data
- Calculate growth and profitability metrics
- Generate visualizations
- Export processed dataset
python chatbot_5.pyType questions or numbers (1-8) from menu.
streamlit run chatbot_ui.pyBrowser opens automatically. Click example buttons or type questions.
python smart_chatbot.pyType questions directly in terminal.
- What is Apple's revenue in 2024?
- Which company grew revenue the fastest?
- How does Microsoft's revenue compare to Tesla?
- Which company has the highest profit margin?
- Compare profit margins across all three companies
- How profitable is Apple compared to Microsoft?
- What is Tesla's debt-to-asset ratio?
- Which company is most leveraged?
- Compare Microsoft and Apple debt levels
- How has Tesla's net income changed over the years?
- What is the trend in Apple's cash flow?
- Which company shows the strongest growth trajectory?
- What are the key financial findings?
- Which company performed best overall?
- Summarize the financial health of all companies
- Verify
.envfile exists in project folder - Check
GEMINI_API_KEY=is set correctly (no spaces) - Ensure API key is valid (test at https://aistudio.google.com)
- Confirm you're in the correct directory
- Verify
financial_data_summaryreport.csvexists - Run
analysis.ipynbto regenerate if missing
- Check Python version:
python --version(need 3.8+) - Try:
python -m streamlit run chatbot_ui.py - Check port 8501 is available
- Gemini free tier has rate limits
- Wait a few minutes before retrying
- Consider creating a new API key if needed
- Run:
pip install -r requirements.txt - Verify all packages installed:
pip list - Use virtual environment if conflicts occur
- Companies: Apple, Microsoft, Tesla only
- Period: Fiscal years 2022, 2023, 2024
- Metrics: From historical financial statements
- Only answers questions about available data
- Does not access real-time information
- Cannot make predictions or provide investment advice
- No internet access or external data sources
- Google Gemini free tier included
- Fair use limits apply
- Responses typically take 1-3 seconds
- Context size: ~3000 tokens per request
✅ Transform raw financial data into analysis-ready format
✅ Calculate growth, profitability, and risk indicators
✅ Generate clear visual insights for comparison
✅ Export enriched dataset for downstream use
✅ Build rule-based financial Q&A chatbot
✅ Build smart LLM-powered chatbot with natural language understanding
✅ Deploy interactive web interface with dark mode design
Program: Forage BCGX GenAI
Data Source: Public financial statements (Apple, Microsoft, Tesla)
LLM Provider: Google Gemini API (free tier)
UI Framework: Streamlit
This project is for educational purposes as part of the Forage BCGX GenAI program.
For detailed chatbot usage instructions, see ChatBot_Documentation.md
For issues or questions about the financial data, refer to the analysis notebook analysis.ipynb