Rehman1603 commited on
Commit
a83cfe4
·
verified ·
1 Parent(s): 00165c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
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=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,25 +64,30 @@ 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'] = 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,7 +98,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 +106,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) # Adjusted line
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'] = farm_future_rate['DOC'].tail(days_option)
68
 
69
  open_output = open_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
70
+ open_output['DOC'] = open_future_rate['DOC'].tail(days_option)
71
 
72
  close_output = close_forecast_rate[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(days_option).copy()
73
+ close_output['DOC'] = close_future_rate['DOC'].tail(days_option)
74
+
75
+ # Round float values to two decimal places
76
+ farm_output[['yhat', 'yhat_lower', 'yhat_upper']] = farm_output[['yhat', 'yhat_lower', 'yhat_upper']].round(2)
77
+ open_output[['yhat', 'yhat_lower', 'yhat_upper']] = open_output[['yhat', 'yhat_lower', 'yhat_upper']].round(2)
78
+ close_output[['yhat', 'yhat_lower', 'yhat_upper']] = close_output[['yhat', 'yhat_lower', 'yhat_upper']].round(2)
79
 
80
  # Create Plotly graphs
81
  fig_farm = go.Figure()
82
+ fig_farm.add_trace(go.Scatter(x=farm_forecast_rate['ds'], y=farm_forecast_rate['yhat'], mode='lines+markers', name='Farm Rate Prediction'))
83
  fig_farm.update_layout(title='Farm Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Farm Rate')
84
 
85
  fig_open = go.Figure()
86
+ fig_open.add_trace(go.Scatter(x=open_forecast_rate['ds'], y=open_forecast_rate['yhat'], mode='lines+markers', name='Open Rate Prediction'))
87
  fig_open.update_layout(title='Open Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Open Rate')
88
 
89
  fig_close = go.Figure()
90
+ fig_close.add_trace(go.Scatter(x=close_forecast_rate['ds'], y=close_forecast_rate['yhat'], mode='lines+markers', name='Close Rate Prediction'))
91
  fig_close.update_layout(title='Close Rate Predictions over Time', xaxis_title='Date', yaxis_title='Predicted Close Rate')
92
 
93
  return farm_output, open_output, close_output, fig_farm, fig_open, fig_close
 
98
  if days_option is None:
99
  return "Please select a valid option for days.", None, None, None, None, None
100
 
101
+ days_map = {'7 days': 7, '10 days': 10, '15 days': 15,'40 days':40}
102
  days_selected = days_map.get(days_option, 7) # Default to 7 days if no valid option is provided
103
  results_farm, results_open, results_close, plot_farm, plot_open, plot_close = predict_values(start_doc, end_doc, days_selected)
104
  return results_farm, results_open, results_close, plot_farm, plot_open, plot_close
 
106
  # Create Gradio inputs and outputs
107
  start_doc_input = gr.components.Number(label="Start DOC Value")
108
  end_doc_input = gr.components.Number(label="End DOC Value")
109
+ days_dropdown = gr.components.Dropdown(choices=['7 days', '10 days', '15 days','40 days'], label="Select Number of Days",value='7 days')
110
 
111
  # Define output components
112
  output_table_farm = gr.components.Dataframe(label="Predicted Farm Rate Values")