ariG23498 HF Staff commited on
Commit
4fcf704
·
verified ·
1 Parent(s): bee63d7

Upload amazon_chronos-2_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. amazon_chronos-2_0.py +77 -0
amazon_chronos-2_0.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "torch",
5
+ # "torchvision",
6
+ # "transformers",
7
+ # "diffusers",
8
+ # "sentence-transformers",
9
+ # "accelerate",
10
+ # "peft",
11
+ # "slack-sdk",
12
+ # ]
13
+ # ///
14
+
15
+ try:
16
+ import pandas as pd
17
+ from chronos import BaseChronosPipeline
18
+
19
+ pipeline = BaseChronosPipeline.from_pretrained("amazon/chronos-2", device_map="cuda")
20
+
21
+ # Load historical data
22
+ context_df = pd.read_csv("https://autogluon.s3.us-west-2.amazonaws.com/datasets/timeseries/misc/AirPassengers.csv")
23
+
24
+ # Generate predictions
25
+ pred_df = pipeline.predict_df(
26
+ context_df,
27
+ prediction_length=36, # Number of steps to forecast
28
+ quantile_levels=[0.1, 0.5, 0.9], # Quantiles for probabilistic forecast
29
+ id_column="item_id", # Column identifying different time series
30
+ timestamp_column="Month", # Column with datetime information
31
+ target="#Passengers", # Column(s) with time series values to predict
32
+ )
33
+ with open('amazon_chronos-2_0.txt', 'w', encoding='utf-8') as f:
34
+ f.write('Everything was good in amazon_chronos-2_0.txt')
35
+ except Exception as e:
36
+ import os
37
+ from slack_sdk import WebClient
38
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
39
+ client.chat_postMessage(
40
+ channel='#hub-model-metadata-snippets-sprint',
41
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/amazon_chronos-2_0.txt|amazon_chronos-2_0.txt>',
42
+ )
43
+
44
+ with open('amazon_chronos-2_0.txt', 'a', encoding='utf-8') as f:
45
+ import traceback
46
+ f.write('''```CODE:
47
+ import pandas as pd
48
+ from chronos import BaseChronosPipeline
49
+
50
+ pipeline = BaseChronosPipeline.from_pretrained("amazon/chronos-2", device_map="cuda")
51
+
52
+ # Load historical data
53
+ context_df = pd.read_csv("https://autogluon.s3.us-west-2.amazonaws.com/datasets/timeseries/misc/AirPassengers.csv")
54
+
55
+ # Generate predictions
56
+ pred_df = pipeline.predict_df(
57
+ context_df,
58
+ prediction_length=36, # Number of steps to forecast
59
+ quantile_levels=[0.1, 0.5, 0.9], # Quantiles for probabilistic forecast
60
+ id_column="item_id", # Column identifying different time series
61
+ timestamp_column="Month", # Column with datetime information
62
+ target="#Passengers", # Column(s) with time series values to predict
63
+ )
64
+ ```
65
+
66
+ ERROR:
67
+ ''')
68
+ traceback.print_exc(file=f)
69
+
70
+ finally:
71
+ from huggingface_hub import upload_file
72
+ upload_file(
73
+ path_or_fileobj='amazon_chronos-2_0.txt',
74
+ repo_id='model-metadata/code_execution_files',
75
+ path_in_repo='amazon_chronos-2_0.txt',
76
+ repo_type='dataset',
77
+ )