azrai99 commited on
Commit
6cb4dbe
·
verified ·
1 Parent(s): c7e43d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -76
app.py CHANGED
@@ -318,65 +318,12 @@ 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):
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,33 +335,87 @@ def timegpt_fcst():
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():
 
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
  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
+
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
+ st.write(df)
362
+ if st.sidebar.button("Submit"):
363
+ forecast_df = nixtla_client.forecast(
364
+ df=df,
365
+ h=7,
366
+ time_col='ds',
367
+ target_col='y',
368
+ freq=freq,
369
+ level=[90]
370
+ )
371
+
372
+ nixtla_client.plot(
373
+ forecast_df,
374
+ level=[90],
375
+ max_insample_length=365
376
+ )
377
+
378
+ # def timegpt_fcst():
379
+ # nixtla_token = os.environ.get("NIXTLA_API_KEY")
380
+ # nixtla_client = NixtlaClient(api_key=nixtla_token)
381
+
382
+ # st.title("TimeGPT Forecasting")
383
+ # with st.sidebar.expander("Upload and Configure Dataset", expanded=True):
384
+ # uploaded_file = st.file_uploader("Upload your time series data (CSV)", type=["csv"])
385
+ # if uploaded_file:
386
+ # df = pd.read_csv(uploaded_file)
387
+ # st.session_state.df = df
388
+ # else:
389
+ # df = load_default()
390
+ # st.session_state.df = df
391
 
392
+ # columns = df.columns.tolist()
393
+ # st.write("Columns in the uploaded dataset:", columns) # Debug statement
394
 
395
+ # ds_col = st.selectbox("Select Date/Time column", options=columns, index=columns.index('ds') if 'ds' in columns else 0)
396
+ # y_col = st.selectbox("Select Target column", options=[col for col in columns if col != ds_col], index=0)
397
+
398
+ # df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
399
+ # st.write("Renamed DataFrame columns:", df.columns) # Debug statement
 
400
 
401
+ # id_col = 'ts_test'
402
+ # df['unique_id'] = id_col
403
+ # freq = determine_frequency(df)
404
+
405
+ # st.write("DataFrame after renaming and adding 'unique_id':", df.head()) # Debug statement
406
+
407
+ # forecast_df = nixtla_client.forecast(
408
+ # df=df,
409
+ # h=7,
410
+ # freq=freq,
411
+ # level=[90]
412
+ # )
413
+
414
+ # nixtla_client.plot(
415
+ # forecast_df,
416
+ # level=[90],
417
+ # max_insample_length=365
418
+ # )
419
 
420
 
421
  def timegpt_anom():