Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,6 +76,7 @@ def get_month_label(i):
|
|
| 76 |
#df['revenue'] = (df['vintage_unique_cases'] / df['predicted_monthly_payment_rate']).round(2)
|
| 77 |
#df['Month'] = [get_month_label(i) for i in range(len(df))]
|
| 78 |
df = pd.DataFrame()
|
|
|
|
| 79 |
|
| 80 |
def update_table(start_date, end_date, window, user_text):
|
| 81 |
#############################################################################################
|
|
@@ -121,10 +122,10 @@ def update_table(start_date, end_date, window, user_text):
|
|
| 121 |
time.sleep(30)
|
| 122 |
|
| 123 |
print(f"Run ID: {run_id}")
|
| 124 |
-
|
| 125 |
#data_metrics = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_metrics.csv")
|
| 126 |
data_predictions = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_predictions_"+str(user_text).split('@')[0]+".csv")
|
| 127 |
-
|
| 128 |
#new_columns = ['vintage', 'vintage_unique_cases'] + [f'M{col}' for col in df_payments.columns[2:]]
|
| 129 |
#df_metrics = pd.read_csv(StringIO(data_metrics.decode('utf-8')))
|
| 130 |
df_predictions = pd.read_csv(StringIO(data_predictions.decode('utf-8')))
|
|
@@ -134,8 +135,10 @@ def update_table(start_date, end_date, window, user_text):
|
|
| 134 |
return {error: str(e)}
|
| 135 |
#############################################################################################
|
| 136 |
global df # Use global variable
|
|
|
|
| 137 |
df = df_predictions.copy()
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
def save_csv(file_name):
|
| 141 |
global df # Use global variable
|
|
@@ -177,10 +180,11 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 177 |
range_input = gr.Slider(3, 12, 6, label="Window / Moving Average Period")
|
| 178 |
gr.Markdown("##### Window = 3-period/months, the predictive model reacts more quickly to recent monthly payment fluctuations, but it may also include more noise.<br><br>Window = 12-period/months, the Forecast adjusts more slowly and is less sensitive to small fluctuations, making it more reliable, but also slower to react to sharp changes.")
|
| 179 |
|
| 180 |
-
|
| 181 |
btn_update = gr.Button("Run Forecast")
|
|
|
|
| 182 |
|
| 183 |
-
btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input, user_text], outputs=
|
| 184 |
|
| 185 |
# Configure the buttons and the panel visibility
|
| 186 |
btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1])
|
|
|
|
| 76 |
#df['revenue'] = (df['vintage_unique_cases'] / df['predicted_monthly_payment_rate']).round(2)
|
| 77 |
#df['Month'] = [get_month_label(i) for i in range(len(df))]
|
| 78 |
df = pd.DataFrame()
|
| 79 |
+
df_2 = pd.DataFrame()
|
| 80 |
|
| 81 |
def update_table(start_date, end_date, window, user_text):
|
| 82 |
#############################################################################################
|
|
|
|
| 122 |
time.sleep(30)
|
| 123 |
|
| 124 |
print(f"Run ID: {run_id}")
|
| 125 |
+
data_payments = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_payments_"+str(user_text).split('@')[0]+".csv")
|
| 126 |
#data_metrics = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_metrics.csv")
|
| 127 |
data_predictions = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_predictions_"+str(user_text).split('@')[0]+".csv")
|
| 128 |
+
df_payments = pd.read_csv(StringIO(data_payments.decode('utf-8')))
|
| 129 |
#new_columns = ['vintage', 'vintage_unique_cases'] + [f'M{col}' for col in df_payments.columns[2:]]
|
| 130 |
#df_metrics = pd.read_csv(StringIO(data_metrics.decode('utf-8')))
|
| 131 |
df_predictions = pd.read_csv(StringIO(data_predictions.decode('utf-8')))
|
|
|
|
| 135 |
return {error: str(e)}
|
| 136 |
#############################################################################################
|
| 137 |
global df # Use global variable
|
| 138 |
+
global df_2
|
| 139 |
df = df_predictions.copy()
|
| 140 |
+
df_2 = df_payments.copy()
|
| 141 |
+
return df, df_2
|
| 142 |
|
| 143 |
def save_csv(file_name):
|
| 144 |
global df # Use global variable
|
|
|
|
| 180 |
range_input = gr.Slider(3, 12, 6, label="Window / Moving Average Period")
|
| 181 |
gr.Markdown("##### Window = 3-period/months, the predictive model reacts more quickly to recent monthly payment fluctuations, but it may also include more noise.<br><br>Window = 12-period/months, the Forecast adjusts more slowly and is less sensitive to small fluctuations, making it more reliable, but also slower to react to sharp changes.")
|
| 182 |
|
| 183 |
+
table_1 = gr.DataFrame(value=df, label="Predictions (consult 'revenue' column):")
|
| 184 |
btn_update = gr.Button("Run Forecast")
|
| 185 |
+
table_2 = gr.DataFrame(value=df_2, label="Forecast Inputs:")
|
| 186 |
|
| 187 |
+
btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input, user_text], outputs=[table_1,table_2])
|
| 188 |
|
| 189 |
# Configure the buttons and the panel visibility
|
| 190 |
btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1])
|