Capebm commited on
Commit
d18c6bd
·
verified ·
1 Parent(s): 06fe75a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -59,11 +59,24 @@ def get_forecast(month, processes, n_months):
59
  results = {}
60
  forecasted_month_names = pd.date_range(start=f'2024-{month_num:02d}-01', periods=n_months, freq='M').strftime("%b")
61
  results["Mês"] = forecasted_month_names
 
 
 
 
62
  for process in processes:
63
  forecast_values = forecast_process_ml(data_transposed, process, n_months)
64
  results[process] = forecast_values
 
 
 
 
 
 
 
 
65
  forecast_df = pd.DataFrame(results)
66
- return forecast_df
 
67
 
68
  # Default values
69
  default_month = pd.Timestamp.now().month
@@ -81,10 +94,6 @@ def forecast_interface(month=default_month_name, process=default_processes, n_mo
81
  forecast_df.to_excel("forecast_results.xlsx", index=False) # Export to Excel
82
  return forecast_df
83
 
84
- # Function to display the input data
85
- def display_input_data():
86
- return data
87
-
88
  # Gradio UI with CSS for black background
89
  css = """
90
  body {
@@ -101,12 +110,8 @@ with gr.Blocks(css=css) as iface:
101
  n_months = gr.Slider(minimum=1, maximum=12, step=1, value=9, label="Número de Meses a Prever")
102
 
103
  output = gr.DataFrame()
104
- input_data_display = gr.DataFrame(value=display_input_data())
105
 
106
  btn = gr.Button("Prever")
107
  btn.click(forecast_interface, inputs=[month, process, n_months], outputs=output)
108
 
109
- gr.Markdown("### Dados de Entrada")
110
- gr.DataFrame(data)
111
-
112
  iface.launch()
 
59
  results = {}
60
  forecasted_month_names = pd.date_range(start=f'2024-{month_num:02d}-01', periods=n_months, freq='M').strftime("%b")
61
  results["Mês"] = forecasted_month_names
62
+
63
+ # Create a DataFrame to hold real values and NaNs
64
+ real_values = pd.DataFrame(index=forecasted_month_names, columns=processes)
65
+
66
  for process in processes:
67
  forecast_values = forecast_process_ml(data_transposed, process, n_months)
68
  results[process] = forecast_values
69
+
70
+ # Populate the DataFrame with real values or NaNs
71
+ for i, month_name in enumerate(forecasted_month_names):
72
+ if month_name in data_transposed.index:
73
+ real_values.at[month_name, process] = data_transposed.at[month_name, process]
74
+ else:
75
+ real_values.at[month_name, process] = np.nan
76
+
77
  forecast_df = pd.DataFrame(results)
78
+ combined_df = pd.concat([forecast_df, real_values.add_prefix('Real_')], axis=1)
79
+ return combined_df
80
 
81
  # Default values
82
  default_month = pd.Timestamp.now().month
 
94
  forecast_df.to_excel("forecast_results.xlsx", index=False) # Export to Excel
95
  return forecast_df
96
 
 
 
 
 
97
  # Gradio UI with CSS for black background
98
  css = """
99
  body {
 
110
  n_months = gr.Slider(minimum=1, maximum=12, step=1, value=9, label="Número de Meses a Prever")
111
 
112
  output = gr.DataFrame()
 
113
 
114
  btn = gr.Button("Prever")
115
  btn.click(forecast_interface, inputs=[month, process, n_months], outputs=output)
116
 
 
 
 
117
  iface.launch()