Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Install necessary packages (only for local environment)
|
2 |
+
# !pip install pandas granite-tsfm
|
3 |
+
|
4 |
+
import pandas as pd
|
5 |
+
from granite_tsfm import TimeSeriesPreprocessor, TinyTimeMixerForPrediction, TimeSeriesForecastingPipeline
|
6 |
+
|
7 |
+
# Load dataset (Replace with actual dataset)
|
8 |
+
data = pd.read_csv('your_dataset.csv', parse_dates=['timestamp_column'])
|
9 |
+
|
10 |
+
# Preprocess the data
|
11 |
+
tsp = TimeSeriesPreprocessor(
|
12 |
+
id_columns=[],
|
13 |
+
timestamp_column='timestamp_column',
|
14 |
+
target_columns=['value1', 'value2'], # Replace with your target column names
|
15 |
+
prediction_length=96,
|
16 |
+
context_length=512,
|
17 |
+
scaling=True
|
18 |
+
)
|
19 |
+
processed_data = tsp.fit_transform(data)
|
20 |
+
|
21 |
+
# Load the pre-trained model
|
22 |
+
model = TinyTimeMixerForPrediction.from_pretrained(
|
23 |
+
'ibm-granite/granite-timeseries-ttm-r2',
|
24 |
+
num_input_channels=tsp.num_input_channels
|
25 |
+
)
|
26 |
+
|
27 |
+
# Generate forecasts
|
28 |
+
pipeline = TimeSeriesForecastingPipeline(
|
29 |
+
model=model,
|
30 |
+
feature_extractor=tsp
|
31 |
+
)
|
32 |
+
forecasts = pipeline(data)
|
33 |
+
|
34 |
+
# Display the forecasts
|
35 |
+
print(forecasts)
|