azrai99 commited on
Commit
cb9ca26
·
verified ·
1 Parent(s): e983327

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -414,7 +414,7 @@ def timegpt_fcst():
414
 
415
  df = df.drop_duplicates(subset=['ds']).reset_index(drop=True)
416
 
417
-
418
  if st.sidebar.button("Submit"):
419
  start_time = time.time()
420
  forecast_df = nixtla_client.forecast(
@@ -428,7 +428,17 @@ def timegpt_fcst():
428
 
429
  if 'forecast_df' in st.session_state:
430
  forecast_df = st.session_state.forecast_df
431
- st.pyplot(nixtla_client.plot(df, forecast_df, level=[90], engine='plotly'))
 
 
 
 
 
 
 
 
 
 
432
 
433
  end_time = time.time() # End timing
434
  time_taken = end_time - start_time
@@ -483,6 +493,8 @@ def timegpt_anom():
483
  freq = determine_frequency(df)
484
 
485
  df = df.drop_duplicates(subset=['ds']).reset_index(drop=True)
 
 
486
  if st.sidebar.button("Submit"):
487
  start_time=time.time()
488
  anom_df = nixtla_client.detect_anomalies(
@@ -494,7 +506,17 @@ def timegpt_anom():
494
 
495
  if 'anom_df' in st.session_state:
496
  anom_df = st.session_state.anom_df
497
- st.pyplot(nixtla_client.plot(df, anom_df, engine='plotly'))
 
 
 
 
 
 
 
 
 
 
498
 
499
  end_time = time.time() # End timing
500
  time_taken = end_time - start_time
 
414
 
415
  df = df.drop_duplicates(subset=['ds']).reset_index(drop=True)
416
 
417
+ plot_type = st.sidebar.selectbox("Select Visualization", ["Matplotlib", "Plotly"])
418
  if st.sidebar.button("Submit"):
419
  start_time = time.time()
420
  forecast_df = nixtla_client.forecast(
 
428
 
429
  if 'forecast_df' in st.session_state:
430
  forecast_df = st.session_state.forecast_df
431
+
432
+ if plot_type == "Matplotlib":
433
+ # Convert the Plotly figure to a Matplotlib figure if needed
434
+ # Note: You may need to handle this conversion depending on your specific use case
435
+ # For now, this example assumes that you are using a Matplotlib figure
436
+ fig = nixtla_client.plot(df, forecast_df, level=[90], engine='matplotlib')
437
+ st.pyplot(fig)
438
+ elif plot_type == "Plotly":
439
+ # Plotly figure directly
440
+ fig = nixtla_client.plot(df, forecast_df, level=[90], engine='plotly')
441
+ st.plotly_chart(fig)
442
 
443
  end_time = time.time() # End timing
444
  time_taken = end_time - start_time
 
493
  freq = determine_frequency(df)
494
 
495
  df = df.drop_duplicates(subset=['ds']).reset_index(drop=True)
496
+
497
+ plot_type = st.sidebar.selectbox("Select Visualization", ["Matplotlib", "Plotly"])
498
  if st.sidebar.button("Submit"):
499
  start_time=time.time()
500
  anom_df = nixtla_client.detect_anomalies(
 
506
 
507
  if 'anom_df' in st.session_state:
508
  anom_df = st.session_state.anom_df
509
+
510
+ if plot_type == "Matplotlib":
511
+ # Convert the Plotly figure to a Matplotlib figure if needed
512
+ # Note: You may need to handle this conversion depending on your specific use case
513
+ # For now, this example assumes that you are using a Matplotlib figure
514
+ fig = nixtla_client.plot(df, forecast_df, level=[90], engine='matplotlib')
515
+ st.pyplot(fig)
516
+ elif plot_type == "Plotly":
517
+ # Plotly figure directly
518
+ fig = nixtla_client.plot(df, forecast_df, level=[90], engine='plotly')
519
+ st.plotly_chart(fig)
520
 
521
  end_time = time.time() # End timing
522
  time_taken = end_time - start_time