yuvrajsingh6 commited on
Commit
10e5f6c
Β·
1 Parent(s): 2d41a13

Add Hugging Face deployment configuration

Browse files
Files changed (1) hide show
  1. README.md +22 -246
README.md CHANGED
@@ -1,251 +1,27 @@
1
- # Analytical Finance Chatbot
2
-
3
- A full-stack AI-powered chatbot for financial data analysis with an OpenAI-inspired interface. The system analyzes CSV data (holdings and trades) and provides intelligent insights through natural language queries with real-time streaming responses.
4
-
5
- ![Tech Stack](https://img.shields.io/badge/Next.js-15+-black?style=flat-square&logo=next.js)
6
- ![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-009688?style=flat-square&logo=fastapi)
7
- ![Python](https://img.shields.io/badge/Python-3.10+-3776AB?style=flat-square&logo=python)
8
- ![Tailwind](https://img.shields.io/badge/Tailwind-4.0-38B2AC?style=flat-square&logo=tailwind-css)
9
-
10
- ## 🌟 Features
11
-
12
- ### Backend
13
- - **Intelligent Data Analysis**: Processes financial CSV data (holdings & trades)
14
- - **Contextual Facts Engine**: Pre-computes analytical facts for accurate responses
15
- - **LLM-Powered Insights**: Uses Groq's Llama 3.1 for natural language understanding
16
- - **Streaming Responses**: Real-time Server-Sent Events (SSE) for smooth UX
17
- - **Conversation Management**: Persistent conversation history and context
18
-
19
- ### Frontend
20
- - **OpenAI-Inspired UI**: Clean, minimalist black & white design
21
- - **Real-Time Streaming**: Live message streaming with visual feedback
22
- - **Rich Markdown Support**: Tables, code blocks, lists with proper formatting
23
- - **Responsive Design**: Mobile-friendly with collapsible sidebar
24
- - **Dark Mode**: Automatic light/dark theme support
25
- - **Conversation History**: Sidebar with all past conversations
26
-
27
- ## πŸ—οΈ Architecture
28
-
29
- ```
30
- project-proojectloop/
31
- β”œβ”€β”€ backend/ # FastAPI backend
32
- β”‚ β”œβ”€β”€ main.py # API endpoints & streaming logic
33
- β”‚ β”œβ”€β”€ csv_engine.py # Data processing & fact extraction
34
- β”‚ β”œβ”€β”€ llm_client.py # Groq LLM integration
35
- β”‚ └── data/
36
- β”‚ β”œβ”€β”€ holdings.csv # Financial holdings data
37
- β”‚ └── trades.csv # Trading data
38
- β”‚
39
- └── frontend-next/ # Next.js frontend
40
- β”œβ”€β”€ src/
41
- β”‚ β”œβ”€β”€ app/
42
- β”‚ β”‚ β”œβ”€β”€ layout.js # Root layout with sidebar
43
- β”‚ β”‚ β”œβ”€β”€ page.js # Home page
44
- β”‚ β”‚ β”œβ”€β”€ globals.css # Theme & styling
45
- β”‚ β”‚ └── c/[id]/ # Dynamic chat routes
46
- β”‚ β”œβ”€β”€ components/
47
- β”‚ β”‚ β”œβ”€β”€ Sidebar.js # Conversation list
48
- β”‚ β”‚ └── ChatInterface.js # Main chat UI
49
- β”‚ └── lib/
50
- β”‚ └── api.js # API client
51
- └── package.json
52
- ```
53
-
54
- ## πŸš€ Quick Start
55
-
56
- ### Prerequisites
57
- - Python 3.10+
58
- - Node.js 18+
59
- - Groq API Key ([Get one here](https://console.groq.com))
60
-
61
- ### Backend Setup
62
-
63
- 1. **Navigate to backend directory**:
64
- ```bash
65
- cd backend
66
- ```
67
-
68
- 2. **Create virtual environment** (optional but recommended):
69
- ```bash
70
- python -m venv .venv
71
- source .venv/bin/activate # On Windows: .venv\Scripts\activate
72
- ```
73
-
74
- 3. **Install dependencies**:
75
- ```bash
76
- pip install fastapi uvicorn pandas groq python-dotenv
77
- ```
78
-
79
- 4. **Configure environment**:
80
- Create a `.env` file in the `backend/` directory:
81
- ```env
82
- GROQ_API_KEY=your_groq_api_key_here
83
- DATA_DIR=data
84
- ```
85
-
86
- 5. **Run the server**:
87
- ```bash
88
- uvicorn main:app --host 0.0.0.0 --port 8000 --reload
89
- ```
90
-
91
- Backend will be available at: `http://localhost:8000`
92
-
93
- ### Frontend Setup
94
-
95
- 1. **Navigate to frontend directory**:
96
- ```bash
97
- cd frontend-next
98
- ```
99
-
100
- 2. **Install dependencies**:
101
- ```bash
102
- npm install
103
- ```
104
-
105
- 3. **Run the development server**:
106
- ```bash
107
- npm run dev
108
- ```
109
-
110
- Frontend will be available at: `http://localhost:3000` (or next available port)
111
-
112
- ## πŸ“‘ API Endpoints
113
-
114
- ### Core Endpoints
115
-
116
- | Method | Endpoint | Description |
117
- |--------|----------|-------------|
118
- | `GET` | `/auth/status` | Authentication status |
119
- | `GET` | `/chat_models` | Available chat models |
120
- | `POST` | `/chat/new_conversation` | Create new conversation |
121
- | `GET` | `/conversation/all` | List all conversations |
122
- | `GET` | `/conversation/{id}` | Get specific conversation |
123
- | `POST` | `/chat/conversation` | Send message (streaming) |
124
- | `POST` | `/chat/get_alias` | Generate conversation title |
125
-
126
- ### Example Request
127
-
128
- ```bash
129
- curl -X POST http://localhost:8000/chat/conversation \
130
- -H "Content-Type: application/json" \
131
- -d '{
132
- "conversation_id": "123e4567-e89b-12d3-a456-426614174000",
133
- "user_message": [{"type": "text", "text": "Which funds performed better?"}]
134
- }'
135
- ```
136
-
137
- ## πŸ’‘ Example Queries
138
-
139
- Try these questions with your data:
140
-
141
- - "Which funds performed better depending on the yearly Profit and Loss?"
142
- - "Show me the top 5 portfolios by total holdings"
143
- - "What is the total quantity for YTUM fund?"
144
- - "Which portfolio has the most records?"
145
- - "Compare the performance of Garfield vs Heather funds"
146
-
147
- ## 🎨 Tech Stack
148
-
149
- ### Backend
150
- - **FastAPI**: Modern Python web framework
151
- - **Pandas**: Data processing and analysis
152
- - **Groq**: LLM API (Llama 3.1 8B Instant)
153
- - **Uvicorn**: ASGI server
154
-
155
- ### Frontend
156
- - **Next.js 15+**: React framework with App Router
157
- - **Tailwind CSS v4**: Utility-first styling
158
- - **React Markdown**: Rich text rendering
159
- - **Lucide React**: Icon library
160
- - **Inter Font**: Clean typography
161
-
162
- ## πŸ”§ Configuration
163
-
164
- ### Backend Environment Variables
165
-
166
- ```env
167
- GROQ_API_KEY=your_api_key # Required: Groq API key
168
- DATA_DIR=data # Optional: Data directory path
169
- ```
170
-
171
- ### Frontend API Configuration
172
-
173
- Update `src/lib/api.js` if your backend runs on a different port:
174
-
175
- ```javascript
176
- const API_BASE_URL = 'http://localhost:8000';
177
- ```
178
-
179
- ## πŸ“Š Data Format
180
-
181
- The system expects CSV files with the following structure:
182
-
183
- ### Holdings CSV
184
- - `PortfolioName`: Fund/portfolio identifier
185
- - `PL_YTD`: Year-to-date profit/loss
186
- - `Qty`: Quantity
187
- - `MV_Base`: Market value
188
- - Other financial metrics...
189
-
190
- ### Trades CSV
191
- - Similar structure with trade-specific fields
192
-
193
- ## πŸ› οΈ Development
194
-
195
- ### Running Tests
196
-
197
- ```bash
198
- # Backend tests
199
- cd backend
200
- python test_api.py
201
-
202
- # Frontend (if tests are added)
203
- cd frontend-next
204
- npm test
205
- ```
206
-
207
- ### Building for Production
208
-
209
- ```bash
210
- # Frontend production build
211
- cd frontend-next
212
- npm run build
213
- npm start
214
- ```
215
-
216
- ## πŸ› Troubleshooting
217
-
218
- ### Backend Issues
219
-
220
- **Problem**: `ModuleNotFoundError: No module named 'csv_engine'`
221
- - **Solution**: Run uvicorn from the `backend/` directory
222
-
223
- **Problem**: No CSV files found
224
- - **Solution**: Ensure CSV files are in `backend/data/` directory
225
-
226
- ### Frontend Issues
227
-
228
- **Problem**: Grey/blurry text in responses
229
- - **Solution**: Already fixed with `prose-neutral dark:prose-invert` classes
230
-
231
- **Problem**: Page reloads on new chat
232
- - **Solution**: Using `window.history.pushState()` instead of router navigation
233
-
234
- **Problem**: Tables not rendering
235
- - **Solution**: Ensure `react-markdown` and `remark-gfm` are installed
236
-
237
- ## πŸ“ License
238
-
239
- This project is open source and available under the MIT License.
240
-
241
- ## 🀝 Contributing
242
 
243
- Contributions are welcome! Please feel free to submit a Pull Request.
244
 
245
- ## πŸ“§ Support
246
 
247
- For issues and questions, please open an issue on the repository.
 
 
 
 
248
 
249
- ---
 
 
 
250
 
251
- **Built with ❀️ using Next.js, FastAPI, and Groq AI**
 
1
+ ---
2
+ title: Analytical Finance Chatbot
3
+ emoji: πŸ’Ή
4
+ colorFrom: black
5
+ colorTo: gray
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ app_port: 7860
10
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Analytical Finance Chatbot
13
 
14
+ An AI-powered financial data analysis chatbot with an OpenAI-inspired interface.
15
 
16
+ ## Features
17
+ - Real-time streaming responses
18
+ - Financial data analysis (holdings & trades)
19
+ - Clean, modern UI with dark mode
20
+ - Markdown table rendering
21
 
22
+ ## Tech Stack
23
+ - Backend: FastAPI + Groq AI
24
+ - Frontend: Next.js + Tailwind CSS
25
+ - Deployment: Docker
26
 
27
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference