Download scripts/simple_demo.py from ParallelLLC/FREDML: direct link, hf CLI and curl.
- Browser
- Download file 8.19 kB
-
https://huggingface.co/ParallelLLC/FREDML/resolve/2c2da682a4a324ca69ea17a2cbf2ae14b5cdc1ba/scripts/simple_demo.py
- Command line
-
hf download hf://ParallelLLC/FREDML@2c2da682a4a324ca69ea17a2cbf2ae14b5cdc1ba/scripts/simple_demo.py
-
curl -L -o simple_demo.py https://huggingface.co/ParallelLLC/FREDML/resolve/2c2da682a4a324ca69ea17a2cbf2ae14b5cdc1ba/scripts/simple_demo.py
8.19 kB
| #!/usr/bin/env python3 | |
| """ | |
| FRED ML Simple Demo | |
| Shows system capabilities without requiring real credentials | |
| """ | |
| import os | |
| import sys | |
| import json | |
| import time | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| from plotly.subplots import make_subplots | |
| import seaborn as sns | |
| from datetime import datetime, timedelta | |
| def demo_data_processing(): | |
| """Demo data processing capabilities""" | |
| print("π Data Processing Demo") | |
| print("=" * 40) | |
| # Create sample economic data | |
| np.random.seed(42) | |
| dates = pd.date_range('2020-01-01', '2024-01-01', freq='M') | |
| # Simulate economic indicators | |
| data = { | |
| 'GDP': np.random.normal(100, 5, len(dates)) + np.cumsum(np.random.normal(0, 0.5, len(dates))), | |
| 'UNRATE': np.random.normal(5, 1, len(dates)), | |
| 'CPIAUCSL': np.random.normal(200, 10, len(dates)) + np.cumsum(np.random.normal(0, 1, len(dates))), | |
| 'FEDFUNDS': np.random.normal(2, 0.5, len(dates)), | |
| 'DGS10': np.random.normal(3, 0.3, len(dates)) | |
| } | |
| df = pd.DataFrame(data, index=dates) | |
| print(f"β Generated {len(df)} data points for {len(df.columns)} indicators") | |
| print(f"π Date range: {df.index.min()} to {df.index.max()}") | |
| # Basic statistics | |
| print("\nπ Summary Statistics:") | |
| print(df.describe().round(2)) | |
| # Correlation analysis | |
| print("\nπ Correlation Matrix:") | |
| correlation = df.corr() | |
| print(correlation.round(3)) | |
| return df | |
| def demo_visualization(df): | |
| """Demo visualization capabilities""" | |
| print("\nπ¨ Visualization Demo") | |
| print("=" * 40) | |
| # 1. Time series plot | |
| print("π Creating time series visualization...") | |
| fig1 = go.Figure() | |
| for col in df.columns: | |
| fig1.add_trace(go.Scatter( | |
| x=df.index, | |
| y=df[col], | |
| name=col, | |
| mode='lines' | |
| )) | |
| fig1.update_layout( | |
| title="Economic Indicators Over Time", | |
| xaxis_title="Date", | |
| yaxis_title="Value", | |
| height=500 | |
| ) | |
| # Save the plot | |
| fig1.write_html("demo_time_series.html") | |
| print("β Time series plot saved as demo_time_series.html") | |
| # 2. Correlation heatmap | |
| print("π₯ Creating correlation heatmap...") | |
| correlation = df.corr() | |
| fig2 = px.imshow( | |
| correlation, | |
| text_auto=True, | |
| aspect="auto", | |
| color_continuous_scale="RdBu", | |
| title="Correlation Matrix Heatmap" | |
| ) | |
| fig2.write_html("demo_correlation.html") | |
| print("β Correlation heatmap saved as demo_correlation.html") | |
| # 3. Distribution plots | |
| print("π Creating distribution plots...") | |
| fig3 = make_subplots( | |
| rows=2, cols=3, | |
| subplot_titles=df.columns, | |
| specs=[[{"secondary_y": False}, {"secondary_y": False}, {"secondary_y": False}], | |
| [{"secondary_y": False}, {"secondary_y": False}, {"secondary_y": False}]] | |
| ) | |
| for i, col in enumerate(df.columns): | |
| row = (i // 3) + 1 | |
| col_num = (i % 3) + 1 | |
| fig3.add_trace( | |
| go.Histogram(x=df[col], name=col), | |
| row=row, col=col_num | |
| ) | |
| fig3.update_layout(height=600, title_text="Distribution of Economic Indicators") | |
| fig3.write_html("demo_distributions.html") | |
| print("β Distribution plots saved as demo_distributions.html") | |
| return True | |
| def demo_analysis(df): | |
| """Demo analysis capabilities""" | |
| print("\nπ Analysis Demo") | |
| print("=" * 40) | |
| # Trend analysis | |
| print("π Trend Analysis:") | |
| trends = {} | |
| for col in df.columns: | |
| # Simple linear trend | |
| x = np.arange(len(df)) | |
| y = df[col].values | |
| slope, intercept = np.polyfit(x, y, 1) | |
| trends[col] = { | |
| 'slope': slope, | |
| 'trend_direction': 'Increasing' if slope > 0 else 'Decreasing', | |
| 'trend_strength': abs(slope) | |
| } | |
| for indicator, trend in trends.items(): | |
| print(f" {indicator}: {trend['trend_direction']} (slope: {trend['slope']:.4f})") | |
| # Volatility analysis | |
| print("\nπ Volatility Analysis:") | |
| volatility = df.pct_change().std() * np.sqrt(252) # Annualized | |
| for indicator, vol in volatility.items(): | |
| print(f" {indicator}: {vol:.2%} annualized volatility") | |
| # Correlation analysis | |
| print("\nπ Correlation Analysis:") | |
| correlation = df.corr() | |
| for i, col1 in enumerate(df.columns): | |
| for j, col2 in enumerate(df.columns): | |
| if i < j: # Avoid duplicates | |
| corr = correlation.loc[col1, col2] | |
| strength = 'Strong' if abs(corr) > 0.7 else 'Moderate' if abs(corr) > 0.3 else 'Weak' | |
| print(f" {col1} vs {col2}: {corr:.3f} ({strength})") | |
| return trends, volatility | |
| def demo_system_architecture(): | |
| """Demo system architecture""" | |
| print("\nποΈ System Architecture Demo") | |
| print("=" * 40) | |
| architecture = { | |
| "Frontend": { | |
| "Technology": "Streamlit", | |
| "Features": ["Interactive dashboard", "Real-time visualization", "User-friendly interface"], | |
| "Status": "β Ready" | |
| }, | |
| "Backend": { | |
| "Technology": "AWS Lambda", | |
| "Features": ["Serverless processing", "Event-driven", "Auto-scaling"], | |
| "Status": "β Ready" | |
| }, | |
| "Storage": { | |
| "Technology": "AWS S3", | |
| "Features": ["Scalable storage", "Lifecycle policies", "Versioning"], | |
| "Status": "β Ready" | |
| }, | |
| "Scheduling": { | |
| "Technology": "EventBridge", | |
| "Features": ["Automated triggers", "Quarterly analysis", "CloudWatch monitoring"], | |
| "Status": "β Ready" | |
| }, | |
| "Data Source": { | |
| "Technology": "FRED API", | |
| "Features": ["Economic indicators", "Real-time data", "Historical analysis"], | |
| "Status": "β Ready" | |
| } | |
| } | |
| for component, details in architecture.items(): | |
| print(f"\n{component}:") | |
| print(f" Technology: {details['Technology']}") | |
| print(f" Features: {', '.join(details['Features'])}") | |
| print(f" Status: {details['Status']}") | |
| def demo_workflow(): | |
| """Demo complete workflow""" | |
| print("\nπ Complete Workflow Demo") | |
| print("=" * 40) | |
| steps = [ | |
| ("Data Retrieval", "Fetching economic data from FRED API"), | |
| ("Data Processing", "Cleaning and preparing data for analysis"), | |
| ("Statistical Analysis", "Calculating correlations and trends"), | |
| ("Visualization", "Creating charts and graphs"), | |
| ("Report Generation", "Compiling results into reports"), | |
| ("Cloud Storage", "Uploading results to S3"), | |
| ("Scheduling", "Setting up automated quarterly analysis") | |
| ] | |
| for i, (step, description) in enumerate(steps, 1): | |
| print(f"{i}. {step}: {description}") | |
| time.sleep(0.5) # Simulate processing time | |
| print("\nβ Complete workflow demonstrated!") | |
| def main(): | |
| """Main demo function""" | |
| print("π FRED ML System Demo") | |
| print("=" * 50) | |
| print("This demo shows the capabilities of the FRED ML system") | |
| print("without requiring real AWS credentials or FRED API key.") | |
| print() | |
| # Demo system architecture | |
| demo_system_architecture() | |
| # Demo data processing | |
| df = demo_data_processing() | |
| # Demo analysis | |
| trends, volatility = demo_analysis(df) | |
| # Demo visualization | |
| demo_visualization(df) | |
| # Demo complete workflow | |
| demo_workflow() | |
| print("\n" + "=" * 50) | |
| print("π Demo completed successfully!") | |
| print("\nπ Generated files:") | |
| print(" - demo_time_series.html") | |
| print(" - demo_correlation.html") | |
| print(" - demo_distributions.html") | |
| print("\nπ― Next steps:") | |
| print("1. Set up real AWS credentials and FRED API key") | |
| print("2. Run: python scripts/test_dev.py") | |
| print("3. Launch: streamlit run frontend/app.py") | |
| print("4. Deploy to production using CI/CD pipeline") | |
| if __name__ == '__main__': | |
| main() |