Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -318,12 +318,65 @@ def dynamic_forecasting():
|
|
318 |
if st.sidebar.button("Submit"):
|
319 |
forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps,y_col)
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
def timegpt_fcst():
|
322 |
nixtla_token = os.environ.get("NIXTLA_API_KEY")
|
323 |
-
nixtla_client = NixtlaClient(
|
324 |
-
api_key = nixtla_token
|
325 |
-
)
|
326 |
-
|
327 |
|
328 |
st.title("TimeGPT Forecasting")
|
329 |
with st.sidebar.expander("Upload and Configure Dataset", expanded=True):
|
@@ -335,44 +388,34 @@ def timegpt_fcst():
|
|
335 |
df = load_default()
|
336 |
st.session_state.df = df
|
337 |
|
338 |
-
columns = df.columns.tolist()
|
339 |
-
|
|
|
340 |
ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
|
341 |
-
|
342 |
-
|
343 |
-
columns.pop(columns.index('unique_id'))
|
344 |
-
opt = columns
|
345 |
-
y_col = st.selectbox("Select Target column", options=opt, index=0)
|
346 |
-
|
347 |
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
|
|
348 |
|
349 |
-
st.write(df)
|
350 |
id_col = 'ts_test'
|
351 |
-
df['unique_id']=id_col
|
352 |
-
|
353 |
-
st.session_state.df = df
|
354 |
|
355 |
-
st.
|
356 |
-
st.session_state.y_col = y_col
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
h=7,
|
365 |
-
time_col='ds',
|
366 |
-
target_col='y',
|
367 |
-
freq=freq,
|
368 |
-
level=[90]
|
369 |
-
)
|
370 |
|
371 |
-
nixtla_client.plot(
|
372 |
-
forecast_df,
|
373 |
-
level=[90],
|
374 |
-
max_insample_length=365
|
375 |
-
)
|
376 |
|
377 |
def timegpt_anom():
|
378 |
nixtla_token = os.environ.get("NIXTLA_API_KEY")
|
|
|
318 |
if st.sidebar.button("Submit"):
|
319 |
forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps,y_col)
|
320 |
|
321 |
+
# def timegpt_fcst():
|
322 |
+
# nixtla_token = os.environ.get("NIXTLA_API_KEY")
|
323 |
+
# nixtla_client = NixtlaClient(
|
324 |
+
# api_key = nixtla_token
|
325 |
+
# )
|
326 |
+
|
327 |
+
|
328 |
+
# st.title("TimeGPT Forecasting")
|
329 |
+
# with st.sidebar.expander("Upload and Configure Dataset", expanded=True):
|
330 |
+
# uploaded_file = st.file_uploader("Upload your time series data (CSV)", type=["csv"])
|
331 |
+
# if uploaded_file:
|
332 |
+
# df = pd.read_csv(uploaded_file)
|
333 |
+
# st.session_state.df = df
|
334 |
+
# else:
|
335 |
+
# df = load_default()
|
336 |
+
# st.session_state.df = df
|
337 |
+
|
338 |
+
# columns = df.columns.tolist() # Convert Index to list
|
339 |
+
# opt = []
|
340 |
+
# ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
|
341 |
+
# if 'ds' in columns and 'unique_id' in columns:
|
342 |
+
# columns.pop(columns.index('ds'))
|
343 |
+
# columns.pop(columns.index('unique_id'))
|
344 |
+
# opt = columns
|
345 |
+
# y_col = st.selectbox("Select Target column", options=opt, index=0)
|
346 |
+
|
347 |
+
# df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
348 |
+
|
349 |
+
# st.write(df)
|
350 |
+
# id_col = 'ts_test'
|
351 |
+
# df['unique_id']=id_col
|
352 |
+
# df = df[['unique_id','ds','y']]
|
353 |
+
# st.session_state.df = df
|
354 |
+
|
355 |
+
# st.session_state.ds_col = ds_col
|
356 |
+
# st.session_state.y_col = y_col
|
357 |
+
|
358 |
+
|
359 |
+
# freq = determine_frequency(df)
|
360 |
+
|
361 |
+
# if st.sidebar.button("Submit"):
|
362 |
+
# forecast_df = nixtla_client.forecast(
|
363 |
+
# df=df,
|
364 |
+
# h=7,
|
365 |
+
# time_col='ds',
|
366 |
+
# target_col='y',
|
367 |
+
# freq=freq,
|
368 |
+
# level=[90]
|
369 |
+
# )
|
370 |
+
|
371 |
+
# nixtla_client.plot(
|
372 |
+
# forecast_df,
|
373 |
+
# level=[90],
|
374 |
+
# max_insample_length=365
|
375 |
+
# )
|
376 |
+
|
377 |
def timegpt_fcst():
|
378 |
nixtla_token = os.environ.get("NIXTLA_API_KEY")
|
379 |
+
nixtla_client = NixtlaClient(api_key=nixtla_token)
|
|
|
|
|
|
|
380 |
|
381 |
st.title("TimeGPT Forecasting")
|
382 |
with st.sidebar.expander("Upload and Configure Dataset", expanded=True):
|
|
|
388 |
df = load_default()
|
389 |
st.session_state.df = df
|
390 |
|
391 |
+
columns = df.columns.tolist()
|
392 |
+
st.write("Columns in the uploaded dataset:", columns) # Debug statement
|
393 |
+
|
394 |
ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
|
395 |
+
y_col = st.selectbox("Select Target column", options=[col for col in columns if col != ds_col], index=0)
|
396 |
+
|
|
|
|
|
|
|
|
|
397 |
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
398 |
+
st.write("Renamed DataFrame columns:", df.columns) # Debug statement
|
399 |
|
|
|
400 |
id_col = 'ts_test'
|
401 |
+
df['unique_id'] = id_col
|
402 |
+
freq = determine_frequency(df)
|
|
|
403 |
|
404 |
+
st.write("DataFrame after renaming and adding 'unique_id':", df.head()) # Debug statement
|
|
|
405 |
|
406 |
+
forecast_df = nixtla_client.forecast(
|
407 |
+
df=df,
|
408 |
+
h=7,
|
409 |
+
freq=freq,
|
410 |
+
level=[90]
|
411 |
+
)
|
412 |
|
413 |
+
nixtla_client.plot(
|
414 |
+
forecast_df,
|
415 |
+
level=[90],
|
416 |
+
max_insample_length=365
|
417 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
def timegpt_anom():
|
421 |
nixtla_token = os.environ.get("NIXTLA_API_KEY")
|