Spaces:
Running
on
Zero
Running
on
Zero
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
- README.md +105 -44
- app.py +16 -0
- packages.txt +9 -0
- 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:
|
|
|
|
|
|
|
| 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**:
|
| 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
|
| 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
|
| 160 |
-
β β 30
|
| 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
|
| 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 |
-
-
|
|
|
|
| 232 |
- scikit-learn
|
| 233 |
|
| 234 |
**Infrastructure**
|
| 235 |
-
- FastMCP 2.
|
| 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 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 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,
|
| 451 |
β
|
| 452 |
βββ backend/
|
| 453 |
β βββ agents/
|
| 454 |
-
β β βββ
|
|
|
|
|
|
|
| 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
|
| 460 |
-
β β
|
| 461 |
-
β β βββ council/
|
| 462 |
-
β β βββ advisory_council.py # Bull/bear debate system
|
| 463 |
β β
|
| 464 |
-
β βββ audio/
|
| 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 #
|
| 473 |
-
β β βββ risk_analyzer_mcp.py #
|
| 474 |
-
β β βββ ensemble_predictor_mcp.py #
|
| 475 |
-
β β βββ news_sentiment_mcp.py #
|
| 476 |
-
β β βββ feature_extraction_mcp.py #
|
| 477 |
β β
|
| 478 |
β βββ models/
|
| 479 |
β β βββ agent_state.py # LangGraph state with reducers
|
| 480 |
β β βββ portfolio.py # Pydantic data models
|
| 481 |
β β
|
| 482 |
-
β βββ data_providers/
|
| 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/
|
| 489 |
-
β β βββ plotly_charts.py #
|
| 490 |
β β
|
| 491 |
-
β βββ caching/
|
| 492 |
-
β β βββ redis_cache.py # Redis implementation
|
| 493 |
β β βββ decorators.py # Cache decorators
|
| 494 |
β β βββ factory.py # Cache factory
|
| 495 |
β β
|
| 496 |
-
β βββ rate_limiting/
|
| 497 |
β β βββ fixed_window.py # Fixed window algorithm
|
| 498 |
β β βββ limiter.py # Rate limiter interface
|
| 499 |
β β
|
| 500 |
-
β βββ stress_testing/
|
| 501 |
-
β β βββ scenarios.py # Market scenarios
|
| 502 |
-
β β βββ simulator.py #
|
| 503 |
β β βββ visualizations.py # Stress test charts
|
| 504 |
β β
|
| 505 |
-
β βββ tax/
|
| 506 |
β β βββ calculator.py # Tax calculations
|
| 507 |
-
β β βββ optimizer.py #
|
| 508 |
β β βββ interface.py # Tax interfaces
|
| 509 |
β β βββ models.py # Tax data models
|
| 510 |
β β βββ tests/ # Tax calculation tests
|
| 511 |
β β
|
| 512 |
-
β βββ monitoring/
|
| 513 |
β β βββ sentry.py # Sentry error tracking
|
| 514 |
β β
|
| 515 |
-
β βββ utils/
|
| 516 |
-
β β βββ serialisation.py #
|
| 517 |
β β βββ uuid_generator.py # UUID generation
|
| 518 |
β β
|
| 519 |
-
β βββ
|
|
|
|
| 520 |
β βββ auth.py # Supabase authentication
|
| 521 |
β βββ database.py # PostgreSQL client
|
| 522 |
β βββ config.py # Configuration management
|
| 523 |
-
β βββ export.py #
|
| 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 |
-
βββ
|
| 540 |
-
βββ
|
|
|
|
| 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
|