BrianIsaac commited on
Commit
4eba8ec
Β·
1 Parent(s): bc45c22

feat: migrate to Gradio SDK deployment for HF Spaces

Browse files

- Update README.md YAML frontmatter for Gradio SDK 5.49.1
- Add HF Spaces deployment files (requirements.txt, packages.txt)
- Add production logging suppression for cleaner HF Spaces logs
- Update documentation to show all 3 ML foundation models
- Add MCP client configuration section with HF Space URL
- Correct ensemble predictor to Chronos-Bolt + TTM + N-HiTS

Files changed (4) hide show
  1. README.md +105 -44
  2. app.py +16 -0
  3. packages.txt +9 -0
  4. requirements.txt +79 -0
README.md CHANGED
@@ -3,11 +3,15 @@ title: Portfolio Intelligence Platform
3
  emoji: πŸ“Š
4
  colorFrom: blue
5
  colorTo: purple
6
- sdk: docker
 
 
7
  app_file: app.py
8
  pinned: false
9
  license: mit
10
  short_description: AI portfolio analysis with multi-agent MCP orchestration
 
 
11
  tags:
12
  - building-mcp-track-enterprise
13
  - building-mcp-track-customer
@@ -89,11 +93,11 @@ This architecture demonstrates that **agentic systems can be both transparent an
89
 
90
  - **9 MCP Servers**: Yahoo Finance, FMP, Trading-MCP, FRED, Portfolio Optimiser, Risk Analyser, Ensemble Predictor, News Sentiment, Feature Extraction
91
  - **Advanced Risk Metrics**: VaR, CVaR, Monte Carlo simulation, Sharpe ratio, Information Ratio, Calmar Ratio, Ulcer Index, GARCH volatility forecasting
92
- - **ML Forecasting**: Amazon Chronos foundation model + ensemble methods for 30/90-day price predictions
93
  - **Quantitative Models**: Hierarchical Risk Parity (HRP), Black-Litterman, Mean-Variance optimisation
94
  - **Real-time Visualisations**: Interactive Plotly charts for allocations, risk, performance, correlations
95
 
96
- ### 🎯 Four Workflow Modes
97
 
98
  1. **Analyse Portfolio**: Comprehensive analysis with visualisations, risk metrics, and AI recommendations
99
  2. **Build Portfolio**: Goal-based portfolio construction using ReAct agent with dynamic tool selection
@@ -156,8 +160,8 @@ This architecture demonstrates that **agentic systems can be both transparent an
156
  β”‚ Phase 2.5: ML Predictions β”‚
157
  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
158
  β”‚ β”‚ Ensemble Predictor MCP β”‚ β”‚
159
- β”‚ β”‚ Chronos foundation model + statistical baselines β”‚ β”‚
160
- β”‚ β”‚ 30/90-day price forecasts with confidence intervals β”‚ β”‚
161
  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
162
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
163
  β”‚
@@ -184,6 +188,30 @@ This architecture demonstrates that **agentic systems can be both transparent an
184
 
185
  ### MCP Server Integration
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  | MCP Server | Purpose | Data Provided | API Provider |
188
  |------------|---------|---------------|--------------|
189
  | **Yahoo Finance** | Market data | Real-time quotes, historical prices, dividends | yfinance |
@@ -192,7 +220,7 @@ This architecture demonstrates that **agentic systems can be both transparent an
192
  | **FRED** | Economic data | GDP, unemployment, Fed funds rate | Federal Reserve |
193
  | **Portfolio Optimiser** | Allocation | HRP, Black-Litterman, Mean-Variance weights | PyPortfolioOpt |
194
  | **Risk Analyser** | Risk metrics | VaR, CVaR, Sharpe, Sortino, max drawdown | riskfolio-lib |
195
- | **Ensemble Predictor** | ML forecasts | 30/90-day price predictions with confidence | Chronos-Bolt |
196
  | **News Sentiment** | Sentiment analysis | VADER sentiment scores on recent news | VADER + Finnhub |
197
  | **Feature Extraction** | ML features | Technical and fundamental feature vectors | Internal |
198
 
@@ -227,12 +255,13 @@ This architecture demonstrates that **agentic systems can be both transparent an
227
  - QuantStats
228
 
229
  **ML & Forecasting**
230
- - Amazon Chronos-Bolt
231
- - NeuralForecast
 
232
  - scikit-learn
233
 
234
  **Infrastructure**
235
- - FastMCP 2.13.0
236
  - Supabase PostgreSQL
237
  - Redis (Upstash) with in-memory fallback
238
 
@@ -244,13 +273,40 @@ This architecture demonstrates that **agentic systems can be both transparent an
244
 
245
  ## πŸš€ Installation
246
 
247
- ### Prerequisites
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
  - **Python 3.12+** ([Download](https://www.python.org/downloads/))
250
  - **uv package manager** ([Install](https://github.com/astral-sh/uv))
251
  - **Anthropic API Key** ([Get Key](https://console.anthropic.com/))
252
 
253
- ### Quick Start
254
 
255
  ```bash
256
  # 1. Clone the repository
@@ -269,6 +325,7 @@ uv run python app.py
269
 
270
  # 5. Open your browser
271
  # Navigate to http://localhost:7860
 
272
  ```
273
 
274
  ### Environment Configuration
@@ -447,80 +504,81 @@ LINK 5
447
  ```
448
  Portfolio-Intelligence-Platform/
449
  β”‚
450
- β”œβ”€β”€ app.py # Main Gradio interface (4,800+ lines)
451
  β”‚
452
  β”œβ”€β”€ backend/
453
  β”‚ β”œβ”€β”€ agents/
454
- β”‚ β”‚ β”œβ”€β”€ base_agent.py # Base agent class
 
 
455
  β”‚ β”‚ β”œβ”€β”€ workflow.py # LangGraph 5-phase workflow
456
  β”‚ β”‚ β”œβ”€β”€ workflow_router.py # Workflow routing logic
457
  β”‚ β”‚ β”œβ”€β”€ react_agent.py # ReAct portfolio builder
458
  β”‚ β”‚ β”œβ”€β”€ portfolio_analyst.py # LLM synthesis agent
459
- β”‚ β”‚ β”œβ”€β”€ personas.py # Investor persona prompts
460
- β”‚ β”‚ β”œβ”€β”€ rehearsal.py # Change simulation engine
461
- β”‚ β”‚ └── council/
462
- β”‚ β”‚ └── advisory_council.py # Bull/bear debate system
463
  β”‚ β”‚
464
- β”‚ β”œβ”€β”€ audio/ # Audio generation
465
  β”‚ β”‚ └── tts_service.py # ElevenLabs TTS integration
466
  β”‚ β”‚
467
  β”‚ β”œβ”€β”€ mcp_servers/ # 9 MCP server implementations
468
- β”‚ β”‚ β”œβ”€β”€ yahoo_finance_mcp.py # Market data
469
- β”‚ β”‚ β”œβ”€β”€ fmp_mcp.py # Fundamentals
470
  β”‚ β”‚ β”œβ”€β”€ trading_mcp.py # Technical indicators
471
- β”‚ β”‚ β”œβ”€β”€ fred_mcp.py # Economic data
472
- β”‚ β”‚ β”œβ”€β”€ portfolio_optimizer_mcp.py # Optimisation
473
- β”‚ β”‚ β”œβ”€β”€ risk_analyzer_mcp.py # Risk metrics
474
- β”‚ β”‚ β”œβ”€β”€ ensemble_predictor_mcp.py # ML forecasting
475
- β”‚ β”‚ β”œβ”€β”€ news_sentiment_mcp.py # Sentiment analysis
476
- β”‚ β”‚ └── feature_extraction_mcp.py # Feature engineering
477
  β”‚ β”‚
478
  β”‚ β”œβ”€β”€ models/
479
  β”‚ β”‚ β”œβ”€β”€ agent_state.py # LangGraph state with reducers
480
  β”‚ β”‚ └── portfolio.py # Pydantic data models
481
  β”‚ β”‚
482
- β”‚ β”œβ”€β”€ data_providers/ # Data provider abstractions
483
  β”‚ β”‚ β”œβ”€β”€ base.py # Base provider interface
484
  β”‚ β”‚ β”œβ”€β”€ factory.py # Provider factory pattern
485
  β”‚ β”‚ β”œβ”€β”€ yfinance_provider.py # Yahoo Finance implementation
486
  β”‚ β”‚ └── fmp_provider.py # FMP implementation
487
  β”‚ β”‚
488
- β”‚ β”œβ”€β”€ visualizations/ # Plotly chart generators
489
- β”‚ β”‚ └── plotly_charts.py # All visualisation logic
490
  β”‚ β”‚
491
- β”‚ β”œβ”€β”€ caching/ # Distributed caching
492
- β”‚ β”‚ β”œβ”€β”€ redis_cache.py # Redis implementation
493
  β”‚ β”‚ β”œβ”€β”€ decorators.py # Cache decorators
494
  β”‚ β”‚ └── factory.py # Cache factory
495
  β”‚ β”‚
496
- β”‚ β”œβ”€β”€ rate_limiting/ # Tiered rate limiting
497
  β”‚ β”‚ β”œβ”€β”€ fixed_window.py # Fixed window algorithm
498
  β”‚ β”‚ └── limiter.py # Rate limiter interface
499
  β”‚ β”‚
500
- β”‚ β”œβ”€β”€ stress_testing/ # Portfolio stress testing
501
- β”‚ β”‚ β”œβ”€β”€ scenarios.py # Market scenarios
502
- β”‚ β”‚ β”œβ”€β”€ simulator.py # Simulation engine
503
  β”‚ β”‚ └── visualizations.py # Stress test charts
504
  β”‚ β”‚
505
- β”‚ β”œβ”€β”€ tax/ # Tax optimisation
506
  β”‚ β”‚ β”œβ”€β”€ calculator.py # Tax calculations
507
- β”‚ β”‚ β”œβ”€β”€ optimizer.py # Loss harvesting strategies
508
  β”‚ β”‚ β”œβ”€β”€ interface.py # Tax interfaces
509
  β”‚ β”‚ β”œβ”€β”€ models.py # Tax data models
510
  β”‚ β”‚ └── tests/ # Tax calculation tests
511
  β”‚ β”‚
512
- β”‚ β”œβ”€β”€ monitoring/ # Observability
513
  β”‚ β”‚ └── sentry.py # Sentry error tracking
514
  β”‚ β”‚
515
- β”‚ β”œβ”€β”€ utils/ # Utility functions
516
- β”‚ β”‚ β”œβ”€β”€ serialisation.py # Data serialisation
517
  β”‚ β”‚ └── uuid_generator.py # UUID generation
518
  β”‚ β”‚
519
- β”‚ β”œβ”€β”€ mcp_router.py # MCP orchestration
 
520
  β”‚ β”œβ”€β”€ auth.py # Supabase authentication
521
  β”‚ β”œβ”€β”€ database.py # PostgreSQL client
522
  β”‚ β”œβ”€β”€ config.py # Configuration management
523
- β”‚ β”œβ”€β”€ export.py # Portfolio export utilities
524
  β”‚ └── theme.py # UI theme configuration
525
  β”‚
526
  β”œβ”€β”€ database/
@@ -532,13 +590,16 @@ Portfolio-Intelligence-Platform/
532
  β”‚ β”œβ”€β”€ test_advisory_council.py # Advisory council tests
533
  β”‚ β”œβ”€β”€ test_integration.py # Integration tests
534
  β”‚ β”œβ”€β”€ test_mcp_servers.py # MCP server tests
 
535
  β”‚ β”œβ”€β”€ test_p1_features.py # P1 feature tests
536
  β”‚ β”œβ”€β”€ test_rehearsal.py # Rehearsal engine tests
537
  β”‚ └── test_single_asset_portfolio.py # Single asset tests
538
  β”‚
539
- β”œβ”€β”€ Dockerfile # Container configuration
540
- β”œβ”€β”€ pyproject.toml # uv dependencies
 
541
  β”œβ”€β”€ uv.lock # Locked dependencies
 
542
  └── README.md # This file
543
  ```
544
 
 
3
  emoji: πŸ“Š
4
  colorFrom: blue
5
  colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 5.49.1
8
+ python_version: "3.12"
9
  app_file: app.py
10
  pinned: false
11
  license: mit
12
  short_description: AI portfolio analysis with multi-agent MCP orchestration
13
+ suggested_hardware: cpu-upgrade
14
+ startup_duration_timeout: 30m
15
  tags:
16
  - building-mcp-track-enterprise
17
  - building-mcp-track-customer
 
93
 
94
  - **9 MCP Servers**: Yahoo Finance, FMP, Trading-MCP, FRED, Portfolio Optimiser, Risk Analyser, Ensemble Predictor, News Sentiment, Feature Extraction
95
  - **Advanced Risk Metrics**: VaR, CVaR, Monte Carlo simulation, Sharpe ratio, Information Ratio, Calmar Ratio, Ulcer Index, GARCH volatility forecasting
96
+ - **ML Forecasting**: Ensemble of 3 foundation models (Chronos-Bolt, TTM, N-HiTS) for 30-day price predictions
97
  - **Quantitative Models**: Hierarchical Risk Parity (HRP), Black-Litterman, Mean-Variance optimisation
98
  - **Real-time Visualisations**: Interactive Plotly charts for allocations, risk, performance, correlations
99
 
100
+ ### 🎯 Four Workflow Tasks
101
 
102
  1. **Analyse Portfolio**: Comprehensive analysis with visualisations, risk metrics, and AI recommendations
103
  2. **Build Portfolio**: Goal-based portfolio construction using ReAct agent with dynamic tool selection
 
160
  β”‚ Phase 2.5: ML Predictions β”‚
161
  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
162
  β”‚ β”‚ Ensemble Predictor MCP β”‚ β”‚
163
+ β”‚ β”‚ 3 Foundation Models: Chronos-Bolt + TTM + N-HiTS β”‚ β”‚
164
+ β”‚ β”‚ 30-day price forecasts with confidence intervals β”‚ β”‚
165
  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
166
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
167
  β”‚
 
188
 
189
  ### MCP Server Integration
190
 
191
+ The platform exposes **22 MCP tools** via Gradio's native MCP server at `/gradio_api/mcp/`. These tools are organised into namespaced categories:
192
+
193
+ | Category | Tools | Purpose |
194
+ |----------|-------|---------|
195
+ | **market_*** | 10 tools | Quotes, historical data, fundamentals, financials, economic data |
196
+ | **technical_*** | 5 tools | Indicators, feature extraction, normalisation, selection |
197
+ | **portfolio_*** | 3 tools | HRP, Black-Litterman, Mean-Variance optimisation |
198
+ | **risk_*** | 2 tools | VaR/CVaR analysis, GARCH volatility forecasting |
199
+ | **ml_*** | 1 tool | Ensemble forecasting (Chronos-Bolt + statistical models) |
200
+ | **sentiment_*** | 1 tool | News sentiment analysis |
201
+
202
+ **MCP Client Configuration:**
203
+ ```json
204
+ {
205
+ "mcpServers": {
206
+ "portfolio-intelligence": {
207
+ "url": "https://mcp-1st-birthday-finance-portfolio-intelligence-platform.hf.space/gradio_api/mcp/"
208
+ }
209
+ }
210
+ }
211
+ ```
212
+
213
+ #### Backend MCP Servers
214
+
215
  | MCP Server | Purpose | Data Provided | API Provider |
216
  |------------|---------|---------------|--------------|
217
  | **Yahoo Finance** | Market data | Real-time quotes, historical prices, dividends | yfinance |
 
220
  | **FRED** | Economic data | GDP, unemployment, Fed funds rate | Federal Reserve |
221
  | **Portfolio Optimiser** | Allocation | HRP, Black-Litterman, Mean-Variance weights | PyPortfolioOpt |
222
  | **Risk Analyser** | Risk metrics | VaR, CVaR, Sharpe, Sortino, max drawdown | riskfolio-lib |
223
+ | **Ensemble Predictor** | ML forecasts | 30-day price predictions with confidence | Chronos-Bolt + TTM + N-HiTS |
224
  | **News Sentiment** | Sentiment analysis | VADER sentiment scores on recent news | VADER + Finnhub |
225
  | **Feature Extraction** | ML features | Technical and fundamental feature vectors | Internal |
226
 
 
255
  - QuantStats
256
 
257
  **ML & Forecasting**
258
+ - Amazon Chronos-Bolt (9M params)
259
+ - IBM Tiny Time Mixers (TTM)
260
+ - Nixtla N-HiTS
261
  - scikit-learn
262
 
263
  **Infrastructure**
264
+ - FastMCP 2.9.1 + Native Gradio MCP
265
  - Supabase PostgreSQL
266
  - Redis (Upstash) with in-memory fallback
267
 
 
273
 
274
  ## πŸš€ Installation
275
 
276
+ ### Deployment Options
277
+
278
+ The platform supports two deployment methods:
279
+
280
+ | Method | Use Case | SDK | Configuration |
281
+ |--------|----------|-----|---------------|
282
+ | **Hugging Face Spaces** | Production hosting | Gradio SDK 5.49.1 | `requirements.txt` + `packages.txt` |
283
+ | **Local Development** | Development & testing | uv + pyproject.toml | `uv sync` |
284
+
285
+ ### Option 1: Hugging Face Spaces (Recommended)
286
+
287
+ The easiest way to deploy is via Hugging Face Spaces with the Gradio SDK:
288
+
289
+ 1. Fork this repository to your Hugging Face account
290
+ 2. Add your API keys as Space Secrets (Settings β†’ Variables and secrets)
291
+ 3. The Space will automatically build and deploy
292
+
293
+ **Required Secrets:**
294
+ - `ANTHROPIC_API_KEY` - Claude API access
295
+
296
+ **Optional Secrets:**
297
+ - `ELEVENLABS_API_KEY` - Audio narration
298
+ - `FMP_API_KEY` - Financial data
299
+ - `SUPABASE_URL`, `SUPABASE_KEY` - Database
300
+
301
+ ### Option 2: Local Development
302
+
303
+ #### Prerequisites
304
 
305
  - **Python 3.12+** ([Download](https://www.python.org/downloads/))
306
  - **uv package manager** ([Install](https://github.com/astral-sh/uv))
307
  - **Anthropic API Key** ([Get Key](https://console.anthropic.com/))
308
 
309
+ #### Quick Start
310
 
311
  ```bash
312
  # 1. Clone the repository
 
325
 
326
  # 5. Open your browser
327
  # Navigate to http://localhost:7860
328
+ # MCP endpoint at http://localhost:7860/gradio_api/mcp/
329
  ```
330
 
331
  ### Environment Configuration
 
504
  ```
505
  Portfolio-Intelligence-Platform/
506
  β”‚
507
+ β”œβ”€β”€ app.py # Main Gradio interface (~4,950 lines)
508
  β”‚
509
  β”œβ”€β”€ backend/
510
  β”‚ β”œβ”€β”€ agents/
511
+ β”‚ β”‚ β”œβ”€β”€ council/
512
+ β”‚ β”‚ β”‚ └── advisory_council.py # Bull/bear debate system
513
+ β”‚ β”‚ β”œβ”€β”€ base_agent.py # Base agent class with PydanticAI
514
  β”‚ β”‚ β”œβ”€β”€ workflow.py # LangGraph 5-phase workflow
515
  β”‚ β”‚ β”œβ”€β”€ workflow_router.py # Workflow routing logic
516
  β”‚ β”‚ β”œβ”€β”€ react_agent.py # ReAct portfolio builder
517
  β”‚ β”‚ β”œβ”€β”€ portfolio_analyst.py # LLM synthesis agent
518
+ β”‚ β”‚ β”œβ”€β”€ personas.py # Investor personas (Buffett, Wood, Dalio)
519
+ β”‚ β”‚ └── rehearsal.py # Change simulation engine
 
 
520
  β”‚ β”‚
521
+ β”‚ β”œβ”€β”€ audio/
522
  β”‚ β”‚ └── tts_service.py # ElevenLabs TTS integration
523
  β”‚ β”‚
524
  β”‚ β”œβ”€β”€ mcp_servers/ # 9 MCP server implementations
525
+ β”‚ β”‚ β”œβ”€β”€ yahoo_finance_mcp.py # Market data (yfinance)
526
+ β”‚ β”‚ β”œβ”€β”€ fmp_mcp.py # Fundamentals (FMP API)
527
  β”‚ β”‚ β”œβ”€β”€ trading_mcp.py # Technical indicators
528
+ β”‚ β”‚ β”œβ”€β”€ fred_mcp.py # Economic data (FRED API)
529
+ β”‚ β”‚ β”œβ”€β”€ portfolio_optimizer_mcp.py # HRP, Black-Litterman, Mean-Variance
530
+ β”‚ β”‚ β”œβ”€β”€ risk_analyzer_mcp.py # VaR, CVaR, GARCH, risk metrics
531
+ β”‚ β”‚ β”œβ”€β”€ ensemble_predictor_mcp.py # Chronos-Bolt + TTM + N-HiTS
532
+ β”‚ β”‚ β”œβ”€β”€ news_sentiment_mcp.py # VADER sentiment (Finnhub)
533
+ β”‚ β”‚ └── feature_extraction_mcp.py # Technical/fundamental features
534
  β”‚ β”‚
535
  β”‚ β”œβ”€β”€ models/
536
  β”‚ β”‚ β”œβ”€β”€ agent_state.py # LangGraph state with reducers
537
  β”‚ β”‚ └── portfolio.py # Pydantic data models
538
  β”‚ β”‚
539
+ β”‚ β”œβ”€β”€ data_providers/
540
  β”‚ β”‚ β”œβ”€β”€ base.py # Base provider interface
541
  β”‚ β”‚ β”œβ”€β”€ factory.py # Provider factory pattern
542
  β”‚ β”‚ β”œβ”€β”€ yfinance_provider.py # Yahoo Finance implementation
543
  β”‚ β”‚ └── fmp_provider.py # FMP implementation
544
  β”‚ β”‚
545
+ β”‚ β”œβ”€β”€ visualizations/
546
+ β”‚ β”‚ └── plotly_charts.py # Interactive Plotly charts
547
  β”‚ β”‚
548
+ β”‚ β”œβ”€β”€ caching/
549
+ β”‚ β”‚ β”œβ”€β”€ redis_cache.py # Redis/Upstash implementation
550
  β”‚ β”‚ β”œβ”€β”€ decorators.py # Cache decorators
551
  β”‚ β”‚ └── factory.py # Cache factory
552
  β”‚ β”‚
553
+ β”‚ β”œβ”€β”€ rate_limiting/
554
  β”‚ β”‚ β”œβ”€β”€ fixed_window.py # Fixed window algorithm
555
  β”‚ β”‚ └── limiter.py # Rate limiter interface
556
  β”‚ β”‚
557
+ β”‚ β”œβ”€β”€ stress_testing/
558
+ β”‚ β”‚ β”œβ”€β”€ scenarios.py # Market stress scenarios
559
+ β”‚ β”‚ β”œβ”€β”€ simulator.py # Monte Carlo simulation
560
  β”‚ β”‚ └── visualizations.py # Stress test charts
561
  β”‚ β”‚
562
+ β”‚ β”œβ”€β”€ tax/
563
  β”‚ β”‚ β”œβ”€β”€ calculator.py # Tax calculations
564
+ β”‚ β”‚ β”œβ”€β”€ optimizer.py # Tax-loss harvesting
565
  β”‚ β”‚ β”œβ”€β”€ interface.py # Tax interfaces
566
  β”‚ β”‚ β”œβ”€β”€ models.py # Tax data models
567
  β”‚ β”‚ └── tests/ # Tax calculation tests
568
  β”‚ β”‚
569
+ β”‚ β”œβ”€β”€ monitoring/
570
  β”‚ β”‚ └── sentry.py # Sentry error tracking
571
  β”‚ β”‚
572
+ β”‚ β”œβ”€β”€ utils/
573
+ β”‚ β”‚ β”œβ”€β”€ serialisation.py # JSON/Decimal serialisation
574
  β”‚ β”‚ └── uuid_generator.py # UUID generation
575
  β”‚ β”‚
576
+ β”‚ β”œβ”€β”€ mcp_tools.py # Unified MCP tools (22 namespaced functions)
577
+ β”‚ β”œβ”€β”€ mcp_router.py # MCP orchestration (compatibility layer)
578
  β”‚ β”œβ”€β”€ auth.py # Supabase authentication
579
  β”‚ β”œβ”€β”€ database.py # PostgreSQL client
580
  β”‚ β”œβ”€β”€ config.py # Configuration management
581
+ β”‚ β”œβ”€β”€ export.py # PDF/CSV export utilities
582
  β”‚ └── theme.py # UI theme configuration
583
  β”‚
584
  β”œβ”€β”€ database/
 
590
  β”‚ β”œβ”€β”€ test_advisory_council.py # Advisory council tests
591
  β”‚ β”œβ”€β”€ test_integration.py # Integration tests
592
  β”‚ β”œβ”€β”€ test_mcp_servers.py # MCP server tests
593
+ β”‚ β”œβ”€β”€ test_mcp_tools.py # MCP tools tests
594
  β”‚ β”œβ”€β”€ test_p1_features.py # P1 feature tests
595
  β”‚ β”œβ”€β”€ test_rehearsal.py # Rehearsal engine tests
596
  β”‚ └── test_single_asset_portfolio.py # Single asset tests
597
  β”‚
598
+ β”œβ”€β”€ pyproject.toml # uv dependencies (local development)
599
+ β”œβ”€β”€ requirements.txt # pip dependencies (HF Spaces)
600
+ β”œβ”€β”€ packages.txt # System dependencies (HF Spaces)
601
  β”œβ”€β”€ uv.lock # Locked dependencies
602
+ β”œβ”€β”€ Dockerfile # Docker deployment (optional)
603
  └── README.md # This file
604
  ```
605
 
app.py CHANGED
@@ -27,6 +27,19 @@ from dotenv import load_dotenv
27
  # Load environment variables first
28
  load_dotenv()
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # Initialise Sentry monitoring early (before other imports that might raise errors)
31
  from backend.monitoring import initialise_sentry
32
  initialise_sentry()
@@ -4925,10 +4938,13 @@ Please try again with different parameters.
4925
 
4926
  if __name__ == "__main__":
4927
  demo = create_interface()
 
 
4928
  demo.queue().launch(
4929
  server_name="0.0.0.0",
4930
  server_port=7860,
4931
  share=False,
 
4932
  mcp_server=True, # Native MCP server at /gradio_api/mcp/
4933
  allowed_paths=["/tmp"] # Allow serving export files from temp directory
4934
  )
 
27
  # Load environment variables first
28
  load_dotenv()
29
 
30
+ # Configure logging for production (suppress verbose output on HF Spaces)
31
+ # Check if running on HF Spaces (SPACE_ID is set automatically)
32
+ if os.environ.get("SPACE_ID"):
33
+ # Suppress verbose logging in production
34
+ logging.getLogger("gradio").setLevel(logging.WARNING)
35
+ logging.getLogger("gradio_client").setLevel(logging.WARNING)
36
+ logging.getLogger("httpx").setLevel(logging.WARNING)
37
+ logging.getLogger("uvicorn").setLevel(logging.WARNING)
38
+ logging.getLogger("uvicorn.access").setLevel(logging.WARNING)
39
+ # Disable telemetry
40
+ os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
41
+ os.environ["HF_HUB_DISABLE_TELEMETRY"] = "true"
42
+
43
  # Initialise Sentry monitoring early (before other imports that might raise errors)
44
  from backend.monitoring import initialise_sentry
45
  initialise_sentry()
 
4938
 
4939
  if __name__ == "__main__":
4940
  demo = create_interface()
4941
+ # Suppress console output on HF Spaces for cleaner logs
4942
+ is_hf_space = os.environ.get("SPACE_ID") is not None
4943
  demo.queue().launch(
4944
  server_name="0.0.0.0",
4945
  server_port=7860,
4946
  share=False,
4947
+ quiet=is_hf_space, # Suppress verbose output on HF Spaces
4948
  mcp_server=True, # Native MCP server at /gradio_api/mcp/
4949
  allowed_paths=["/tmp"] # Allow serving export files from temp directory
4950
  )
packages.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # System dependencies for HF Spaces Gradio SDK
2
+ # Pre-installed: ffmpeg, cmake, libsm6, libsndfile1
3
+
4
+ # Build tools for compiled packages
5
+ build-essential
6
+ libffi-dev
7
+
8
+ # For SSL/TLS support
9
+ libssl-dev
requirements.txt ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Portfolio Intelligence Platform - HF Spaces Gradio SDK Dependencies
2
+ # Note: gradio is pre-installed via sdk_version, DO NOT include here
3
+
4
+ # AI Framework
5
+ pydantic-ai-slim[anthropic]==1.18.0
6
+ anthropic>=0.39.0
7
+ instructor>=1.6.4
8
+
9
+ # Agent Orchestration
10
+ langgraph>=0.1.0
11
+ langchain-anthropic>=0.1.0
12
+ langchain-core>=0.2.0
13
+
14
+ # MCP Framework (compatible with gradio[mcp] mcp==1.10.1)
15
+ fastmcp==2.9.1
16
+
17
+ # Backend
18
+ fastapi>=0.104.0
19
+ uvicorn[standard]>=0.24.0
20
+ pydantic>=2.5.0
21
+
22
+ # Database (using binary to avoid libpq-dev requirement)
23
+ supabase>=2.9.0
24
+ psycopg2-binary>=2.9.9
25
+
26
+ # Caching & Rate Limiting
27
+ redis>=5.0.0
28
+ upstash-redis>=0.15.0
29
+ orjson>=3.10.0
30
+
31
+ # Quantitative Finance
32
+ pyportfolioopt>=1.5.6
33
+ riskfolio-lib>=7.0.0
34
+ arch>=8.0.0
35
+ quantstats>=0.0.77
36
+
37
+ # Data & Analysis
38
+ pandas>=2.2.3
39
+ numpy>=2.0.0
40
+ yfinance>=0.2.40
41
+ scipy>=1.11.0
42
+ matplotlib>=3.8.0
43
+ plotly>=5.18.0
44
+
45
+ # Export & Reporting
46
+ reportlab>=4.0.0
47
+ pypdf>=3.17.0
48
+
49
+ # Feature Engineering
50
+ pandas-ta>=0.3.14b
51
+ PyWavelets>=1.4.1
52
+ scikit-learn>=1.3.0
53
+
54
+ # ML Models
55
+ torch>=2.0.0
56
+ xgboost>=3.1.0
57
+ chronos-forecasting>=1.0.0
58
+
59
+ # Deep Learning Time Series
60
+ granite-tsfm>=0.2.22
61
+ neuralforecast>=3.1.0
62
+
63
+ # Utilities
64
+ python-dotenv>=1.0.0
65
+ httpx>=0.25.0
66
+ tenacity>=8.2.0
67
+ python-dateutil>=2.8.0
68
+
69
+ # Sentiment Analysis
70
+ vaderSentiment>=3.3.2
71
+
72
+ # Text-to-Speech
73
+ elevenlabs>=1.0.0
74
+
75
+ # Monitoring
76
+ sentry-sdk[fastapi]>=2.0.0,<3.0.0
77
+
78
+ # Financial Data
79
+ fmp-data>=1.0.2