Spaces:
Sleeping
Sleeping
File size: 5,688 Bytes
ac98d23 6dd3d42 ac98d23 ae277d6 7703449 ae277d6 0e07197 bc5c925 4f45b17 0e07197 ae277d6 9f56b18 ae277d6 9f56b18 ae277d6 ba10c56 ae277d6 4f45b17 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | ---
title: FinAI-Agent
emoji: π°
colorFrom: indigo
colorTo: green
sdk: streamlit
app_file: app.py
python_version: "3.13" # β specify your Python version
pinned: false
---
# Finance-Agent π€π°
[](https://www.python.org/)
[](https://streamlit.io/)
[](LICENSE)
---
## π What Is This?
**Finance-Agent** is your chat-native **CFO co-pilot**.
Ask plain-English questions about your companyβs Excel ledger, and get **instant answers with context + charts**.
---
## TRY IT NOW!!
https://huggingface.co/spaces/Sbboss/FinAIAgent

---
### Example
You β βCompare EBITDA and cash runway for Q1 vs Q2, convert EUR to USD.β
Agent β βEBITDA Q1: $1.42 M, Q2: $1.65 M (+16.4 %).
Cash runway improved from 7.1 β 8.3 months.β
---
## β¨ Feature Tour
- **Natural-Language Querying** β Gemini 2.5 Flash interprets finance jargon and casual questions alike.
- **Dynamic Tool Routing** β LangChain React agent picks one or more of 7 custom Python tools (revenue variance, gross-margin %, OpEx breakdownβ¦).
- **Smart Currency Handling** β Detects EUR rows, fetches FX sheet, normalizes to USD.
- **Date Inference** β βThis yearβ, βlast 3 monthsβ, βJunβ25β β precise periods.
- **Chart Factory** β Generates PNGs via Matplotlib (line, bar, area, stacked).
- **Streamlit UI** β Slack-style sidebar, message persistence, spinner feedback.
- **Excel Plug-and-Play** β Works with a single `data.xlsx` containing 4 sheets: `actuals`, `budget`, `cash`, `fx`.
- **Fallback PythonREPL** β If no tool fits, agent writes ad-hoc Pandas code.
- **Pytest Suite** β Automated tests for tool selection, calc accuracy, caching, and rendering.
- **One-click Deploy** β Just `streamlit run app.py`.
---
## ποΈ Architecture
```text
βββββββββ Chat UI (Streamlit) ββββββββ
β User Input + Chat History β
β β finance_agent.invoke() β
ββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββ LangChain AgentExecutor βββββββββββββββ
β Prompt (system + history + input) β
β LLM: Gemini 2.5 Flash β
β React tool-calling loop β
ββββββββββββββββ¬βββββββββββββββββββββββββββ
β selects & runs
ββββββββββββββββ΄βββββββββββββββββββββββββββ
β Custom Tools β
β β’ get_revenue_variance β
β β’ get_gross_margin_pct β
β β’ get_opex_breakdown β
β β’ get_ebitda_proxy β
β β’ get_cash_runway β
β β’ plot_chart β
β β’ code_analysis (PythonREPL) β
βββββββββββββββββββββββββββββββββββββββββββ
```
---
## π Folder Structure
```text
finance-agent/
ββ agent/
β ββ agent.py # creates cached AgentExecutor
β ββ utils.py # numeric calculations
β ββ tests/ # pytest suite
ββ data.xlsx # sample ledger
ββ app.py # Streamlit front-end
ββ requirements.txt
ββ .streamlit/
ββ secrets.toml # custom theme & font
```
---
## βοΈ Installation
```bash
git clone https://github.com/Sbboss/FinAIAgent.git
cd FinAIAgent
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
streamlit run app.py
```
π Quick Start
Drop your company ledger into data.xlsx with sheets: actuals, budget, cash, fx.
1. Run the app:
```bash
streamlit run app.py
```
2. Ask away:
```
βTrend gross margin % monthly for 2024.β
βWhy did revenue miss budget in Nov 25?β
βHow many months of runway if burn stays flat?β
```
π Charts appear inline; numeric answers include deltas vs budget and YOY.
___
π¬ Testing
```
pip install -r requirements-dev.txt
pytest -v
```
Covers:
Tool parameter validation
Correct tool selection via intermediate steps
Currency conversion accuracy
Streamlit image rendering
Caching behaviour (st.cache_resource)
---
π οΈ Configuration
| Setting | File / Env | Default |
| ---------------------- | ------------------------ | --------------------- |
| Google Gemini API key | `GOOGLE_API_KEY` | put in `secrets.toml` |
| Excel file path | `data.xlsx` | β |
| LLM temperature | agent | `0.2` |
---
π
Roadmap
* π CSV and SQL connectors
* ποΈ Vector memory for conversation continuity
* π Multi-LLM failover (Gemini β GPT-4o)
* π Automatic dashboard snapshots to PDF
* π¬ Slack / Teams integration
* π₯ Demo GIF: live chat β chart β answer
---
π Contributing
1. Fork & branch (feat/your-feature)
2. Add tests (pytest -k your_test)
3. Submit PR with concise description
β
All significant changes must pass CI and keep coverage β₯ 95%.
---
π License
MIT β see [LICENSE](LICENSE)
Finance-Agent turns spreadsheets into strategy. Ask. Analyze. Act. β‘
---
|