azrai99 commited on
Commit
f932524
·
verified ·
1 Parent(s): 9dd63f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -7
app.py CHANGED
@@ -311,7 +311,7 @@ def dynamic_forecasting():
311
  if st.sidebar.button("Submit"):
312
  forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps,y_col)
313
 
314
- def timegpt():
315
  nixtla_token = os.environ.get("NIXTLA_API_KEY")
316
  nixtla_client = NixtlaClient(
317
  api_key = api_key
@@ -333,12 +333,63 @@ def timegpt():
333
  ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
334
  y_col = st.selectbox("Select Target column", options=columns)
335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
 
337
  nixtla_client.plot(
338
- df,
339
- id_col= y_col,
340
- time_col=ds_col,
341
- target_col=y_col,
342
  max_insample_length=365
343
  )
344
 
@@ -354,8 +405,8 @@ pg = st.navigation({
354
  ],
355
  "TimeGPT": [
356
  # Load pages from functions
357
- st.Page(timegpt, title="TimeGPT Forecast", icon=":material/smart_toy:"),
358
- st.Page(timegpt, title="TimeGPT Anomalies Detection", icon=":material/detector_offline:")
359
  ]
360
  })
361
 
 
311
  if st.sidebar.button("Submit"):
312
  forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps,y_col)
313
 
314
+ def timegpt_fcst():
315
  nixtla_token = os.environ.get("NIXTLA_API_KEY")
316
  nixtla_client = NixtlaClient(
317
  api_key = api_key
 
333
  ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
334
  y_col = st.selectbox("Select Target column", options=columns)
335
 
336
+ df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
337
+
338
+ id_col = 'ts_test'
339
+ df['unique_id']=id_col
340
+ freq = determine_frequency(df)
341
+
342
+ forecast_df = nixtla_client.forecast(
343
+ df=df,
344
+ h=7,
345
+ freq=freq,
346
+ level=[90]
347
+ )
348
+
349
+ nixtla_client.plot(
350
+ forecast_df,
351
+ level=[90],
352
+ max_insample_length=365
353
+ )
354
+
355
+ def timegpt_anom():
356
+ nixtla_token = os.environ.get("NIXTLA_API_KEY")
357
+ nixtla_client = NixtlaClient(
358
+ api_key = api_key
359
+ )
360
+
361
+
362
+ st.title("TimeGPT Forecasting")
363
+ with st.sidebar.expander("Upload and Configure Dataset", expanded=True):
364
+ uploaded_file = st.file_uploader("Upload your time series data (CSV)", type=["csv"])
365
+ if uploaded_file:
366
+ df = pd.read_csv(uploaded_file)
367
+ st.session_state.df = df
368
+ else:
369
+ df = load_default()
370
+ st.session_state.df = df
371
+
372
+ # Column selection
373
+ columns = df.columns.tolist() # Convert Index to list
374
+ ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
375
+ y_col = st.selectbox("Select Target column", options=columns)
376
+
377
+ df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
378
+
379
+ id_col = 'ts_test'
380
+ df['unique_id']=id_col
381
+ freq = determine_frequency(df)
382
+
383
+ forecast_df = nixtla_client.forecast(
384
+ df=df,
385
+ h=7,
386
+ freq=freq,
387
+ level=[90]
388
+ )
389
 
390
  nixtla_client.plot(
391
+ forecast_df,
392
+ level=[90],
 
 
393
  max_insample_length=365
394
  )
395
 
 
405
  ],
406
  "TimeGPT": [
407
  # Load pages from functions
408
+ st.Page(timegpt_fcst, title="TimeGPT Forecast", icon=":material/smart_toy:"),
409
+ st.Page(timegpt_anom, title="TimeGPT Anomalies Detection", icon=":material/detector_offline:")
410
  ]
411
  })
412