Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
from core.data import load_data
|
| 4 |
from core.model_runner import get_model
|
| 5 |
-
from core.plot import plot_forecast, plot_metrics_precision, plot_metrics_risk, plot_loss_curve, plot_future_forecast
|
| 6 |
from config import AVAILABLE_MODELS, DEFAULT_TICKERS
|
| 7 |
|
| 8 |
|
|
@@ -31,6 +31,7 @@ def main_interface():
|
|
| 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)
|
|
|
|
| 34 |
|
| 35 |
run_btn = gr.Button("๐ Train & Predict")
|
| 36 |
status = gr.Textbox(label="Status", interactive=False, lines=2)
|
|
@@ -39,13 +40,14 @@ def main_interface():
|
|
| 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 |
-
precision_plot = gr.Plot(label="๐ Precision Metrics (Model Accuracy: Rยฒ, Explained Variance, MDA)")
|
| 43 |
-
risk_plot = gr.Plot(label="๐ Risk Metrics (Error Magnitude: RMSE, MAE, MAPE, MASE)")
|
| 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,
|
| 47 |
hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay,
|
| 48 |
-
dropout, window_size, test_split):
|
| 49 |
try:
|
| 50 |
pd.to_datetime(start_date)
|
| 51 |
pd.to_datetime(end_date)
|
|
@@ -54,7 +56,7 @@ def main_interface():
|
|
| 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,
|
|
@@ -70,13 +72,15 @@ def main_interface():
|
|
| 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)
|
| 77 |
precision_plot = plot_metrics_precision(result)
|
| 78 |
risk_plot = plot_metrics_risk(result)
|
| 79 |
loss_plot = plot_loss_curve(result)
|
|
|
|
| 80 |
|
| 81 |
msg = "โ
Done."
|
| 82 |
if "latest_prediction" in result:
|
|
@@ -90,9 +94,9 @@ def main_interface():
|
|
| 90 |
else:
|
| 91 |
future_df_out = pd.DataFrame()
|
| 92 |
|
| 93 |
-
return forecast_plot, future_plot, future_df_out, precision_plot, risk_plot, loss_plot, msg
|
| 94 |
except Exception as e:
|
| 95 |
-
return None, None, None, None, None, None, f"โ Error: {str(e)}"
|
| 96 |
|
| 97 |
run_btn.click(
|
| 98 |
fn=run_pipeline,
|
|
@@ -100,9 +104,9 @@ def main_interface():
|
|
| 100 |
data_src, ticker, file_upload,
|
| 101 |
start_date, end_date, horizon, model,
|
| 102 |
hidden_units, n_layers, epochs, learning_rate,
|
| 103 |
-
beta1, beta2, weight_decay, dropout, window_size, test_split
|
| 104 |
],
|
| 105 |
-
outputs=[backtest_plot, future_plot, future_table, precision_plot, risk_plot, loss_plot, status]
|
| 106 |
)
|
| 107 |
|
| 108 |
def toggle_file(src):
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from core.data import load_data
|
| 4 |
from core.model_runner import get_model
|
| 5 |
+
from core.plot import plot_forecast, plot_metrics_precision, plot_metrics_risk, plot_loss_curve, plot_future_forecast, plot_model_architecture
|
| 6 |
from config import AVAILABLE_MODELS, DEFAULT_TICKERS
|
| 7 |
|
| 8 |
|
|
|
|
| 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)
|
| 34 |
+
scheduler_factor = gr.Slider(0.1, 0.9, label="Scheduler Factor (LR Reduction)", value=0.5, step=0.1)
|
| 35 |
|
| 36 |
run_btn = gr.Button("๐ Train & Predict")
|
| 37 |
status = gr.Textbox(label="Status", interactive=False, lines=2)
|
|
|
|
| 40 |
backtest_plot = gr.Plot(label="๐ Backtesting: Actual vs Forecast")
|
| 41 |
future_plot = gr.Plot(label="๐ฎ Future Forecast with Actuals")
|
| 42 |
future_table = gr.Dataframe(label="๐ Future Predictions")
|
| 43 |
+
precision_plot = gr.Plot(label="๐ Precision Metrics (Model Accuracy: Rยฒ (%), Explained Variance (%), MDA (%))")
|
| 44 |
+
risk_plot = gr.Plot(label="๐ Risk Metrics (Error Magnitude: RMSE, MAE, MAPE (%), MASE)")
|
| 45 |
loss_plot = gr.Plot(label="๐ Training Loss Curve")
|
| 46 |
+
architecture_plot = gr.Plot(label="๐ง Model Architecture")
|
| 47 |
|
| 48 |
def run_pipeline(data_src, ticker, file_upload, start_date, end_date, horizon, model,
|
| 49 |
hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay,
|
| 50 |
+
dropout, window_size, test_split, scheduler_factor):
|
| 51 |
try:
|
| 52 |
pd.to_datetime(start_date)
|
| 53 |
pd.to_datetime(end_date)
|
|
|
|
| 56 |
main_df, future_df = load_data(data_src=source_key, ticker=ticker, file_upload=file_upload,
|
| 57 |
start=start_date, end=end_date, horizon=horizon)
|
| 58 |
if main_df is None or main_df.empty:
|
| 59 |
+
return None, None, None, None, None, None, None, "โ Failed to load data. Please check input."
|
| 60 |
|
| 61 |
result = get_model(
|
| 62 |
df=main_df,
|
|
|
|
| 72 |
weight_decay=weight_decay,
|
| 73 |
dropout=dropout,
|
| 74 |
window_size=window_size,
|
| 75 |
+
test_split=test_split,
|
| 76 |
+
scheduler_factor=scheduler_factor
|
| 77 |
)
|
| 78 |
forecast_plot = plot_forecast(result)
|
| 79 |
future_plot = plot_future_forecast(main_df, result, future_df)
|
| 80 |
precision_plot = plot_metrics_precision(result)
|
| 81 |
risk_plot = plot_metrics_risk(result)
|
| 82 |
loss_plot = plot_loss_curve(result)
|
| 83 |
+
architecture_plot = plot_model_architecture(result)
|
| 84 |
|
| 85 |
msg = "โ
Done."
|
| 86 |
if "latest_prediction" in result:
|
|
|
|
| 94 |
else:
|
| 95 |
future_df_out = pd.DataFrame()
|
| 96 |
|
| 97 |
+
return forecast_plot, future_plot, future_df_out, precision_plot, risk_plot, loss_plot, architecture_plot, msg
|
| 98 |
except Exception as e:
|
| 99 |
+
return None, None, None, None, None, None, None, f"โ Error: {str(e)}"
|
| 100 |
|
| 101 |
run_btn.click(
|
| 102 |
fn=run_pipeline,
|
|
|
|
| 104 |
data_src, ticker, file_upload,
|
| 105 |
start_date, end_date, horizon, model,
|
| 106 |
hidden_units, n_layers, epochs, learning_rate,
|
| 107 |
+
beta1, beta2, weight_decay, dropout, window_size, test_split, scheduler_factor
|
| 108 |
],
|
| 109 |
+
outputs=[backtest_plot, future_plot, future_table, precision_plot, risk_plot, loss_plot, architecture_plot, status]
|
| 110 |
)
|
| 111 |
|
| 112 |
def toggle_file(src):
|