Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def predict_values(start_doc, end_doc, days_option):
|
|
50 |
close_future_rate = close_rate_model.make_future_dataframe(periods=days_option, freq='D')
|
51 |
|
52 |
# Generate DOC values within the specified range
|
53 |
-
doc_values = np.linspace(start_doc, end_doc, num=
|
54 |
|
55 |
# Assign the generated DOC values to the future dataframes
|
56 |
farm_future_rate['DOC'] = doc_values
|
@@ -64,25 +64,25 @@ def predict_values(start_doc, end_doc, days_option):
|
|
64 |
|
65 |
# Filter to get only the future predictions (last `days_option` days)
|
66 |
farm_output = farm_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
67 |
-
farm_output['DOC'] =
|
68 |
|
69 |
open_output = open_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
70 |
-
open_output['DOC'] =
|
71 |
|
72 |
close_output = close_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
73 |
-
close_output['DOC'] =
|
74 |
|
75 |
# Create Plotly graphs
|
76 |
fig_farm = go.Figure()
|
77 |
-
fig_farm.add_trace(go.Scatter(x=farm_forecast_rate['ds'], y=farm_forecast_rate['yhat'], mode='lines+markers', name='Farm Rate Prediction'))
|
78 |
fig_farm.update_layout(title='Farm Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Farm Rate')
|
79 |
|
80 |
fig_open = go.Figure()
|
81 |
-
fig_open.add_trace(go.Scatter(x=open_forecast_rate['ds'], y=open_forecast_rate['yhat'], mode='lines+markers', name='Open Rate Prediction'))
|
82 |
fig_open.update_layout(title='Open Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Open Rate')
|
83 |
|
84 |
fig_close = go.Figure()
|
85 |
-
fig_close.add_trace(go.Scatter(x=close_forecast_rate['ds'], y=close_forecast_rate['yhat'], mode='lines+markers', name='Close Rate Prediction'))
|
86 |
fig_close.update_layout(title='Close Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Close Rate')
|
87 |
|
88 |
return farm_output, open_output, close_output, fig_farm, fig_open, fig_close
|
@@ -93,7 +93,7 @@ def interface(start_doc, end_doc, days_option):
|
|
93 |
if days_option is None:
|
94 |
return "Please select a valid option for days.", None, None, None, None, None
|
95 |
|
96 |
-
days_map = {'7 days': 7, '10 days': 10, '15 days': 15,'40 days':40}
|
97 |
days_selected = days_map.get(days_option, 7) # Default to 7 days if no valid option is provided
|
98 |
results_farm, results_open, results_close, plot_farm, plot_open, plot_close = predict_values(start_doc, end_doc, days_selected)
|
99 |
return results_farm, results_open, results_close, plot_farm, plot_open, plot_close
|
@@ -101,7 +101,7 @@ def interface(start_doc, end_doc, days_option):
|
|
101 |
# Create Gradio inputs and outputs
|
102 |
start_doc_input = gr.components.Number(label="Start DOC Value")
|
103 |
end_doc_input = gr.components.Number(label="End DOC Value")
|
104 |
-
days_dropdown = gr.components.Dropdown(choices=['7 days', '10 days', '15 days','40 days'], label="Select Number of Days",value='7 days')
|
105 |
|
106 |
# Define output components
|
107 |
output_table_farm = gr.components.Dataframe(label="Predicted Farm Rate Values")
|
|
|
50 |
close_future_rate = close_rate_model.make_future_dataframe(periods=days_option, freq='D')
|
51 |
|
52 |
# Generate DOC values within the specified range
|
53 |
+
doc_values = np.linspace(start_doc, end_doc, num=days_option) # Generate DOC values for the number of days
|
54 |
|
55 |
# Assign the generated DOC values to the future dataframes
|
56 |
farm_future_rate['DOC'] = doc_values
|
|
|
64 |
|
65 |
# Filter to get only the future predictions (last `days_option` days)
|
66 |
farm_output = farm_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
67 |
+
farm_output['DOC'] = np.round(doc_values, 1) # Round DOC values
|
68 |
|
69 |
open_output = open_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
70 |
+
open_output['DOC'] = np.round(doc_values, 1) # Round DOC values
|
71 |
|
72 |
close_output = close_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
|
73 |
+
close_output['DOC'] = np.round(doc_values, 1) # Round DOC values
|
74 |
|
75 |
# Create Plotly graphs
|
76 |
fig_farm = go.Figure()
|
77 |
+
fig_farm.add_trace(go.Scatter(x=farm_forecast_rate['ds'], y=farm_forecast_rate['yhat'].round(1), mode='lines+markers', name='Farm Rate Prediction'))
|
78 |
fig_farm.update_layout(title='Farm Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Farm Rate')
|
79 |
|
80 |
fig_open = go.Figure()
|
81 |
+
fig_open.add_trace(go.Scatter(x=open_forecast_rate['ds'], y=open_forecast_rate['yhat'].round(1), mode='lines+markers', name='Open Rate Prediction'))
|
82 |
fig_open.update_layout(title='Open Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Open Rate')
|
83 |
|
84 |
fig_close = go.Figure()
|
85 |
+
fig_close.add_trace(go.Scatter(x=close_forecast_rate['ds'], y=close_forecast_rate['yhat'].round(1), mode='lines+markers', name='Close Rate Prediction'))
|
86 |
fig_close.update_layout(title='Close Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Close Rate')
|
87 |
|
88 |
return farm_output, open_output, close_output, fig_farm, fig_open, fig_close
|
|
|
93 |
if days_option is None:
|
94 |
return "Please select a valid option for days.", None, None, None, None, None
|
95 |
|
96 |
+
days_map = {'7 days': 7, '10 days': 10, '15 days': 15, '40 days': 40}
|
97 |
days_selected = days_map.get(days_option, 7) # Default to 7 days if no valid option is provided
|
98 |
results_farm, results_open, results_close, plot_farm, plot_open, plot_close = predict_values(start_doc, end_doc, days_selected)
|
99 |
return results_farm, results_open, results_close, plot_farm, plot_open, plot_close
|
|
|
101 |
# Create Gradio inputs and outputs
|
102 |
start_doc_input = gr.components.Number(label="Start DOC Value")
|
103 |
end_doc_input = gr.components.Number(label="End DOC Value")
|
104 |
+
days_dropdown = gr.components.Dropdown(choices=['7 days', '10 days', '15 days', '40 days'], label="Select Number of Days", value='7 days')
|
105 |
|
106 |
# Define output components
|
107 |
output_table_farm = gr.components.Dataframe(label="Predicted Farm Rate Values")
|