Spaces:
Runtime error
Runtime error
OfirMatzlawi
commited on
Commit
•
c845410
1
Parent(s):
b9713c3
Update main.py
Browse files
main.py
CHANGED
@@ -36,17 +36,16 @@ def get_data_from_yahoo(ticker: str):
|
|
36 |
df = pd.DataFrame(data).reset_index()
|
37 |
return df
|
38 |
|
39 |
-
##TimeGPT APIkey validation
|
40 |
|
41 |
-
api_key = 'nixt-7nixiWJtV1TwD3vp9K8WqLrgkIZmsXZ0gxBqrOSI1E3XPpkVSakyPYgMtWdtNKeBgStnPncgzpGqQzoG'
|
42 |
-
|
43 |
-
def apikey(api_key):
|
44 |
-
nixtla_client = NixtlaClient(
|
45 |
-
api_key = api_key
|
46 |
-
)
|
47 |
-
key_valid = nixtla_client.validate_api_key()
|
48 |
-
return key_valid
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
|
@@ -55,8 +54,8 @@ def apikey(api_key):
|
|
55 |
@app.get("/ticker/{ticker}")
|
56 |
def read_item(ticker: str):
|
57 |
data = get_data_from_yahoo(ticker)
|
58 |
-
|
59 |
-
result =
|
60 |
return result
|
61 |
|
62 |
|
|
|
36 |
df = pd.DataFrame(data).reset_index()
|
37 |
return df
|
38 |
|
|
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
|
42 |
+
def forecasting(df):
|
43 |
+
api_key = 'nixt-7nixiWJtV1TwD3vp9K8WqLrgkIZmsXZ0gxBqrOSI1E3XPpkVSakyPYgMtWdtNKeBgStnPncgzpGqQzoG'
|
44 |
+
nixtla_client = NixtlaClient(api_key = api_key)
|
45 |
+
## forecasting 3 months
|
46 |
+
timegpt_fcst_df = nixtla_client.forecast(df=df, h=3, freq='MS', time_col='Date', target_col='Adj Close')
|
47 |
+
|
48 |
+
return timegpt_fcst_df
|
49 |
|
50 |
|
51 |
|
|
|
54 |
@app.get("/ticker/{ticker}")
|
55 |
def read_item(ticker: str):
|
56 |
data = get_data_from_yahoo(ticker)
|
57 |
+
pred = forecasting(data)
|
58 |
+
result = pred.to_json()
|
59 |
return result
|
60 |
|
61 |
|