Aliazimi00 commited on
Commit
89542d9
ยท
verified ยท
1 Parent(s): ca5f787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -25,9 +25,9 @@ def main_interface():
25
  n_layers = gr.Slider(1, 5, step=1, label="# Hidden Layers", value=2)
26
  epochs = gr.Slider(10, 300, label="Epochs", value=100)
27
  learning_rate = gr.Slider(1e-5, 0.01, label="Learning Rate", value=0.001)
28
- beta1 = gr.Slider(0.8, 0.95, label="AdamW Beta1", value=0.9, step=0.01) # Added
29
- beta2 = gr.Slider(0.9, 0.999, label="AdamW Beta2", value=0.999, step=0.001) # Added
30
- weight_decay = gr.Slider(0.0, 0.1, label="Weight Decay", value=0.01, step=0.001) # Added
31
  dropout = gr.Slider(0.0, 0.3, label="Drop Out", value=0.2)
32
  window_size = gr.Slider(5, 90, label="Window Size", value=30)
33
  test_split = gr.Slider(0.05, 0.5, label="Test Split", value=0.2)
@@ -37,10 +37,10 @@ def main_interface():
37
 
38
  with gr.Column(scale=2):
39
  backtest_plot = gr.Plot(label="๐Ÿ“Š Backtesting: Actual vs Forecast")
40
- future_plot = gr.Plot(label="๐Ÿ”ฎ Future Forecast")
41
  future_table = gr.Dataframe(label="๐Ÿ“‹ Future Predictions")
42
- r2_plot = gr.Plot(label="๐Ÿ“‰ Rยฒ and MAPE Metrics") # Updated
43
- error_plot = gr.Plot(label="๐Ÿ“‰ RMSE and MAE Metrics") # Updated
44
  loss_plot = gr.Plot(label="๐Ÿ“ˆ Training Loss Curve")
45
 
46
  def run_pipeline(data_src, ticker, file_upload, start_date, end_date, horizon, model,
@@ -51,41 +51,46 @@ def main_interface():
51
  pd.to_datetime(end_date)
52
 
53
  source_key = "csv" if data_src == "Upload CSV" else "yahoo"
54
- df = load_data(data_src=source_key, ticker=ticker, file_upload=file_upload, start=start_date, end=end_date)
55
- if df is None or df.empty:
 
56
  return None, None, None, None, None, None, "โŒ Failed to load data. Please check input."
57
 
58
  result = get_model(
59
- df=df,
 
60
  model_name=model,
61
  horizon=horizon,
62
  hidden_units=hidden_units,
63
  n_layers=n_layers,
64
  epochs=epochs,
65
  learning_rate=learning_rate,
66
- beta1=beta1, # Added
67
- beta2=beta2, # Added
68
- weight_decay=weight_decay, # Added
69
  dropout=dropout,
70
  window_size=window_size,
71
  test_split=test_split
72
  )
73
  forecast_plot = plot_forecast(result)
74
- future_plot = plot_future_forecast(df, result)
75
- r2_plot = plot_metrics_r2(result) # Updated
76
- error_plot = plot_metrics_errors(result) # Updated
77
  loss_plot = plot_loss_curve(result)
78
 
79
  msg = "โœ… Done."
80
  if "latest_prediction" in result:
81
- last_date = df['Date'].iloc[-1]
82
  future_dates = pd.date_range(start=last_date + pd.Timedelta(days=1), periods=horizon, freq='B')
83
- future_df = pd.DataFrame({'Date': future_dates, 'Predicted Value': result["latest_prediction"]})
 
 
 
84
  msg += f" Next predicted value(s): {[f'{val:.2f}' for val in result['latest_prediction']]}"
85
  else:
86
- future_df = pd.DataFrame()
87
 
88
- return forecast_plot, future_plot, future_df, r2_plot, error_plot, loss_plot, msg
89
  except Exception as e:
90
  return None, None, None, None, None, None, f"โŒ Error: {str(e)}"
91
 
 
25
  n_layers = gr.Slider(1, 5, step=1, label="# Hidden Layers", value=2)
26
  epochs = gr.Slider(10, 300, label="Epochs", value=100)
27
  learning_rate = gr.Slider(1e-5, 0.01, label="Learning Rate", value=0.001)
28
+ beta1 = gr.Slider(0.8, 0.95, label="AdamW Beta1", value=0.9, step=0.01)
29
+ beta2 = gr.Slider(0.9, 0.999, label="AdamW Beta2", value=0.999, step=0.001)
30
+ weight_decay = gr.Slider(0.0, 0.1, label="Weight Decay", value=0.01, step=0.001)
31
  dropout = gr.Slider(0.0, 0.3, label="Drop Out", value=0.2)
32
  window_size = gr.Slider(5, 90, label="Window Size", value=30)
33
  test_split = gr.Slider(0.05, 0.5, label="Test Split", value=0.2)
 
37
 
38
  with gr.Column(scale=2):
39
  backtest_plot = gr.Plot(label="๐Ÿ“Š Backtesting: Actual vs Forecast")
40
+ future_plot = gr.Plot(label="๐Ÿ”ฎ Future Forecast with Actuals")
41
  future_table = gr.Dataframe(label="๐Ÿ“‹ Future Predictions")
42
+ r2_plot = gr.Plot(label="๐Ÿ“‰ Rยฒ and MAPE Metrics")
43
+ error_plot = gr.Plot(label="๐Ÿ“‰ RMSE and MAE Metrics")
44
  loss_plot = gr.Plot(label="๐Ÿ“ˆ Training Loss Curve")
45
 
46
  def run_pipeline(data_src, ticker, file_upload, start_date, end_date, horizon, model,
 
51
  pd.to_datetime(end_date)
52
 
53
  source_key = "csv" if data_src == "Upload CSV" else "yahoo"
54
+ main_df, future_df = load_data(data_src=source_key, ticker=ticker, file_upload=file_upload,
55
+ start=start_date, end=end_date, horizon=horizon)
56
+ if main_df is None or main_df.empty:
57
  return None, None, None, None, None, None, "โŒ Failed to load data. Please check input."
58
 
59
  result = get_model(
60
+ df=main_df,
61
+ future_df=future_df, # Pass future_df
62
  model_name=model,
63
  horizon=horizon,
64
  hidden_units=hidden_units,
65
  n_layers=n_layers,
66
  epochs=epochs,
67
  learning_rate=learning_rate,
68
+ beta1=beta1,
69
+ beta2=beta2,
70
+ weight_decay=weight_decay,
71
  dropout=dropout,
72
  window_size=window_size,
73
  test_split=test_split
74
  )
75
  forecast_plot = plot_forecast(result)
76
+ future_plot = plot_future_forecast(main_df, result, future_df) # Pass future_df
77
+ r2_plot = plot_metrics_r2(result)
78
+ error_plot = plot_metrics_errors(result)
79
  loss_plot = plot_loss_curve(result)
80
 
81
  msg = "โœ… Done."
82
  if "latest_prediction" in result:
83
+ last_date = main_df['Date'].iloc[-1]
84
  future_dates = pd.date_range(start=last_date + pd.Timedelta(days=1), periods=horizon, freq='B')
85
+ future_data = {'Date': future_dates, 'Predicted Value': result["latest_prediction"]}
86
+ if not future_df.empty and "future_actuals" in result:
87
+ future_data['Actual Value'] = result["future_actuals"] + [None] * (horizon - len(result["future_actuals"]))
88
+ future_df_out = pd.DataFrame(future_data)
89
  msg += f" Next predicted value(s): {[f'{val:.2f}' for val in result['latest_prediction']]}"
90
  else:
91
+ future_df_out = pd.DataFrame()
92
 
93
+ return forecast_plot, future_plot, future_df_out, r2_plot, error_plot, loss_plot, msg
94
  except Exception as e:
95
  return None, None, None, None, None, None, f"โŒ Error: {str(e)}"
96