abhaypratapsingh111 commited on
Commit
aebe391
·
verified ·
1 Parent(s): 5cc6362

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +365 -8
README.md CHANGED
@@ -1,10 +1,367 @@
1
- ---
2
- title: Chronos2 Forecasting
3
- emoji: 🦀
4
- colorFrom: purple
5
- colorTo: red
6
- sdk: docker
7
- pinned: false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # Chronos 2 Time Series Forecasting Application
2
+
3
+ A production-ready web application for testing Amazon's **Chronos 2** time series forecasting model using the latest `Chronos2Pipeline` API. Built with Dash for enterprise scalability and designed for both local development and cloud deployment.
4
+
5
+ ## Features
6
+
7
+ - **Latest Chronos 2 API**: Uses `Chronos2Pipeline.predict_df()` with DataFrame-based interface
8
+ - **Interactive Forecasting**: Generate forecasts up to 365 days with adjustable confidence intervals
9
+ - **Dual Model Support**: Switch between Fast (Chronos-Bolt) and Accurate (Chronos-2) variants
10
+ - **Multivariate Ready**: Built on Chronos 2 architecture supporting multivariate forecasting
11
+ - **Flexible Data Input**: Upload CSV/Excel files or use sample datasets
12
+ - **Rich Visualizations**: Interactive Plotly charts with confidence bands and zoom capabilities
13
+ - **Data Quality Analysis**: Automatic preprocessing with quality reports
14
+ - **GPU Acceleration**: Automatic CUDA support with CPU fallback
15
+ - **Security Hardened**: Non-root Docker containers, server-side validation, filename sanitization
16
+ - **Production Ready**: Designed for deployment on local machines or Databricks Apps
17
+
18
+ ## Architecture
19
+
20
+ Built following best practices for scalability and maintainability:
21
+
22
+ - **Dash Framework**: Handles thousands of concurrent users
23
+ - **Plotly Visualizations**: Smooth rendering of 100K+ data points
24
+ - **Model Caching**: Chronos 2 loaded once at startup for fast inference
25
+ - **Client-Side State**: Efficient state management without server sessions
26
+ - **Modular Design**: Clean separation of components, services, and utilities
27
+
28
+ ## Installation
29
+
30
+ ### Prerequisites
31
+
32
+ - Python 3.10+
33
+ - CUDA-capable GPU (optional, for faster inference)
34
+ - 8GB+ RAM (4-8GB for model + overhead)
35
+
36
+ ### Local Setup
37
+
38
+ 1. **Clone the repository**
39
+ ```bash
40
+ git clone <repository-url>
41
+ cd chronos2-forecasting-app
42
+ ```
43
+
44
+ 2. **Create a virtual environment**
45
+ ```bash
46
+ python -m venv venv
47
+
48
+ # On Windows
49
+ venv\Scripts\activate
50
+
51
+ # On Linux/Mac
52
+ source venv/bin/activate
53
+ ```
54
+
55
+ 3. **Install dependencies**
56
+ ```bash
57
+ pip install -r requirements.txt
58
+ ```
59
+
60
+ 4. **Run the application**
61
+ ```bash
62
+ python app.py
63
+ ```
64
+
65
+ 5. **Access the app**
66
+ Open your browser to `http://127.0.0.1:8050`
67
+
68
+ ## Usage Guide
69
+
70
+ ### Quick Start
71
+
72
+ 1. **Load Sample Data**
73
+ - Click one of the sample dataset buttons (Electricity, Retail, Manufacturing)
74
+ - Or upload your own CSV/Excel file
75
+
76
+ 2. **Configure Data**
77
+ - Select the date column
78
+ - Select the target variable to forecast
79
+ - (Optional) Select an ID column for multivariate series
80
+
81
+ 3. **Set Forecast Parameters**
82
+ - Adjust the forecast horizon (1-365 days)
83
+ - Select confidence levels (80%, 90%, 95%, 99%)
84
+ - Choose model variant (Fast or Accurate)
85
+
86
+ 4. **Generate Forecast**
87
+ - Click "Generate Forecast" button
88
+ - Wait for model inference (typically 1-5 seconds)
89
+ - View interactive chart with confidence intervals
90
+
91
+ ### Data Requirements
92
+
93
+ Your data should have:
94
+ - **Date column**: Any standard date format
95
+ - **Target column**: Numeric values to forecast
96
+ - **Minimum rows**: At least 2x the forecast horizon
97
+ - **File size**: Up to 100MB
98
+ - **Formats**: CSV, XLSX, XLS
99
+
100
+ ### Tips for Best Results
101
+
102
+ - Use at least 2x the forecast horizon in historical data
103
+ - Clean your data before upload (though the app handles basic preprocessing)
104
+ - Start with the Fast model variant for quick testing
105
+ - Use the Accurate variant for final forecasts
106
+ - Larger confidence intervals provide more conservative forecasts
107
+
108
+ ## Project Structure
109
+
110
+ ```
111
+ chronos2-forecasting-app/
112
+ ├── app.py # Main Dash application
113
+ ├── components/ # UI components
114
+ │ ├── upload.py # File upload component
115
+ │ ├── chart.py # Chart generation
116
+ │ └── controls.py # Parameter controls
117
+ ├── services/ # Business logic
118
+ │ ├── model_service.py # Chronos model wrapper
119
+ │ ├── data_processor.py # Data preprocessing
120
+ │ └── cache_manager.py # Caching logic
121
+ ├── utils/ # Utilities
122
+ │ ├── validators.py # Input validation
123
+ │ └── metrics.py # Forecast metrics
124
+ ├── config/ # Configuration
125
+ │ ├── settings.py # Environment settings
126
+ │ └── constants.py # App constants
127
+ ├── datasets/ # Sample datasets
128
+ ├── static/ # Static assets
129
+ │ └── custom.css # Custom styles
130
+ ├── requirements.txt # Python dependencies
131
+ ├── Dockerfile # Container definition
132
+ └── README.md # This file
133
+ ```
134
+
135
+ ## Configuration
136
+
137
+ ### Environment Variables
138
+
139
+ - `ENVIRONMENT`: Set to `local` or `production`
140
+ - `DEVICE`: Set to `auto`, `cuda`, or `cpu`
141
+ - `LOG_LEVEL`: Set to `DEBUG`, `INFO`, `WARNING`, or `ERROR`
142
+ - `DATABRICKS_APP_PORT`: Port for Databricks deployment (default: 8080)
143
+
144
+ ### Local vs Databricks Configuration
145
+
146
+ The app automatically detects the environment and adjusts settings:
147
+
148
+ **Local Development:**
149
+ - Host: 127.0.0.1
150
+ - Port: 8050
151
+ - Debug: Enabled
152
+ - Storage: Local directories
153
+
154
+ **Databricks Deployment:**
155
+ - Host: 0.0.0.0
156
+ - Port: 8080 (or DATABRICKS_APP_PORT)
157
+ - Debug: Disabled
158
+ - Storage: /tmp and /dbfs
159
+
160
+ ## Deployment
161
+
162
+ ### Hugging Face Spaces (Recommended for Free Hosting)
163
+
164
+ The easiest way to deploy this app for free:
165
+
166
+ 1. **Create a Hugging Face account** at https://huggingface.co
167
+
168
+ 2. **Create a new Space**
169
+ - Go to https://huggingface.co/spaces
170
+ - Click "Create new Space"
171
+ - Select "Dash" as the SDK
172
+ - Choose a name for your Space
173
+
174
+ 3. **Upload your code**
175
+ - Option A: Connect your GitHub repository (recommended)
176
+ - Option B: Upload files directly through the web interface
177
+
178
+ 4. **Configure the Space**
179
+ - The app will automatically use `app.py` as the entry point
180
+ - HuggingFace Spaces provides 16GB RAM (sufficient for Chronos-2)
181
+ - Optional: Request GPU upgrade for faster inference
182
+
183
+ 5. **Access your deployed app**
184
+ - Your app will be live at: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME`
185
+
186
+ **Note**: First startup may take 2-3 minutes as the Chronos-2 model downloads (~500MB).
187
+
188
+ ### Docker Deployment
189
+
190
+ 1. **Build the image**
191
+ ```bash
192
+ docker build -t chronos2-forecasting .
193
+ ```
194
+
195
+ 2. **Run the container**
196
+ ```bash
197
+ docker run -p 8080:8080 chronos2-forecasting
198
+ ```
199
+
200
+ 3. **With GPU support**
201
+ ```bash
202
+ docker run --gpus all -p 8080:8080 chronos2-forecasting
203
+ ```
204
+
205
+ ### Databricks Apps Deployment
206
+
207
+ 1. **Upload code to DBFS**
208
+ ```bash
209
+ databricks fs cp -r . dbfs:/apps/chronos2-forecasting/
210
+ ```
211
+
212
+ 2. **Create Databricks App**
213
+ - Use the Databricks Apps UI
214
+ - Point to the uploaded directory
215
+ - Set environment variable: `ENVIRONMENT=production`
216
+
217
+ 3. **Configure resources**
218
+ - Minimum: 8GB RAM
219
+ - Recommended: GPU instance for faster inference
220
+
221
+ ### Production Considerations
222
+
223
+ - **Memory**: Allocate 6-8GB for the model + overhead
224
+ - **Scaling**: Use multiple workers with Gunicorn
225
+ - **Monitoring**: Check `/health` endpoint for status
226
+ - **Logging**: Logs to stdout for easy collection
227
+ - **Timeouts**: Set to 300s+ for large forecasts
228
+
229
+ ## API Reference
230
+
231
+ ### Health Check Endpoint
232
+
233
+ ```
234
+ GET /health
235
+ ```
236
+
237
+ Returns:
238
+ ```json
239
+ {
240
+ "status": "healthy",
241
+ "model_loaded": true,
242
+ "model_variant": "fast",
243
+ "device": "cuda"
244
+ }
245
+ ```
246
+
247
+ ## Troubleshooting
248
+
249
+ ### Model Loading Issues
250
+
251
+ **Problem**: Model fails to load
252
+ - Check available memory (need 4-8GB)
253
+ - Try CPU mode: Set `DEVICE=cpu`
254
+ - Check internet connection (first run downloads model)
255
+
256
+ ### GPU Not Detected
257
+
258
+ **Problem**: CUDA device not found
259
+ - Verify CUDA installation: `python -c "import torch; print(torch.cuda.is_available())"`
260
+ - Install correct PyTorch version for your CUDA
261
+ - App will automatically fall back to CPU
262
+
263
+ ### Upload Failures
264
+
265
+ **Problem**: File upload fails
266
+ - Check file size (<100MB)
267
+ - Verify file format (CSV, XLSX, XLS)
268
+ - Ensure file is not corrupted
269
+
270
+ ### Slow Performance
271
+
272
+ **Problem**: Forecasts take too long
273
+ - Use Fast model variant instead of Accurate
274
+ - Reduce forecast horizon
275
+ - Enable GPU acceleration
276
+ - Limit data points (app decimates to 10K for display)
277
+
278
+ ### Memory Errors
279
+
280
+ **Problem**: Out of memory during inference
281
+ - Switch to Fast model variant (smaller)
282
+ - Use CPU instead of GPU
283
+ - Reduce batch size in model_service.py
284
+ - Close other applications
285
+
286
+ ## Performance Tuning
287
+
288
+ ### For Development
289
+ - Enable debug mode for detailed logging
290
+ - Use Fast model variant
291
+ - Work with smaller datasets initially
292
+
293
+ ### For Production
294
+ - Disable debug mode
295
+ - Use GPU for inference
296
+ - Enable caching (already configured)
297
+ - Use Gunicorn with 4 workers
298
+ - Set up monitoring and alerting
299
+
300
+ ## Contributing
301
+
302
+ Contributions are welcome! Please:
303
+
304
+ 1. Fork the repository
305
+ 2. Create a feature branch
306
+ 3. Make your changes
307
+ 4. Add tests if applicable
308
+ 5. Submit a pull request
309
+
310
+ ## License
311
+
312
+ This project is provided as-is for educational and research purposes.
313
+
314
+ ## Acknowledgments
315
+
316
+ - **Chronos Model**: Amazon Science
317
+ - **Dash Framework**: Plotly
318
+ - **Sample Data**: Generated for demonstration purposes
319
+
320
+ ## Support
321
+
322
+ For issues, questions, or suggestions:
323
+ - Open an issue in the repository
324
+ - Check existing documentation
325
+ - Review troubleshooting guide above
326
+
327
+ ## Changelog
328
+
329
+ ### Version 1.0.1 (Latest - Chronos 2 Full Implementation)
330
+ - **BREAKING**: Migrated to Chronos 2 API with `Chronos2Pipeline`
331
+ - Fixed deprecated pandas methods (`fillna(method=...)` → `ffill()`/`bfill()`)
332
+ - Updated to `chronos-forecasting==2.0.0` package
333
+ - Fixed type hints (`any` → `Any`) across all modules
334
+ - Added DataFrame-based prediction interface
335
+ - Security improvements:
336
+ - Non-root user in Docker container
337
+ - Server-side file validation
338
+ - Filename sanitization
339
+ - Health check timeout configuration
340
+ - Updated model paths to support Chronos-2 (s3://autogluon/chronos-2)
341
+ - Fixed data format compatibility (id/timestamp/target columns)
342
+ - Added `requests` library for health checks
343
+
344
+ ### Version 1.0.0 (Initial Release)
345
+ - Chronos 2 model integration
346
+ - Single-page Dash application
347
+ - CSV/Excel upload support
348
+ - Interactive visualizations
349
+ - Confidence interval display
350
+ - Sample datasets included
351
+ - Docker deployment ready
352
+ - Databricks Apps compatible
353
+
354
+ ## Roadmap
355
+
356
+ Future enhancements being considered:
357
+ - Multi-series forecasting UI
358
+ - Model comparison features
359
+ - Export forecast results
360
+ - Custom model fine-tuning
361
+ - Real-time data streaming
362
+ - Advanced metrics dashboard
363
+ - API-only mode for programmatic access
364
+
365
  ---
366
 
367
+ Built with Dash and Chronos 2 for production-ready time series forecasting.