Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,15 +19,15 @@ JOB_ID = os.getenv("JOB_ID_")
|
|
| 19 |
def check_words(user_text, input_text):
|
| 20 |
# If the entered text is "user" and "casa", show Panel 2 and hide Panel 1
|
| 21 |
if user_text == os.getenv("USER_1_") and input_text == os.getenv("PASS_1_"):
|
| 22 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 23 |
elif user_text == os.getenv("USER_2_") and input_text == os.getenv("PASS_2_"):
|
| 24 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 25 |
elif user_text == os.getenv("USER_3_") and input_text == os.getenv("PASS_3_"):
|
| 26 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 27 |
elif user_text == os.getenv("USER_4_") and input_text == os.getenv("PASS_4_"):
|
| 28 |
-
return gr.update(visible=True), gr.update(visible=False)
|
| 29 |
else:
|
| 30 |
-
return gr.update(visible=False), gr.update(visible=True)
|
| 31 |
|
| 32 |
# Function to hide Panel 2
|
| 33 |
def hide_panel():
|
|
@@ -39,7 +39,7 @@ def show_panel_1():
|
|
| 39 |
|
| 40 |
# Wrapper function to hide Panel 2 and show Panel 1 when btn_2 is clicked
|
| 41 |
def hide_and_show_panel():
|
| 42 |
-
return hide_panel(), show_panel_1()
|
| 43 |
|
| 44 |
#def update_message(request: gr.Request):
|
| 45 |
# return f"Welcome, {request.username}"
|
|
@@ -76,7 +76,7 @@ df = pd.read_csv(StringIO(data_predictions_.decode('utf-8')))
|
|
| 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 |
|
| 79 |
-
def update_table(start_date, end_date, window):
|
| 80 |
#############################################################################################
|
| 81 |
try:
|
| 82 |
DATABRICKS_INSTANCE = 'https://136286767906206.6.gcp.databricks.com'
|
|
@@ -88,7 +88,8 @@ def update_table(start_date, end_date, window):
|
|
| 88 |
"events_api_base_url": "https://beta.datascore.ai",
|
| 89 |
"month_train_starting": str(start_date),
|
| 90 |
"month_for_prediction": str(end_date),
|
| 91 |
-
"moving_average_period": str(window)
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/run-now"
|
|
@@ -162,7 +163,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 162 |
# logout_button = gr.Button("Logout", link="/logout", scale=0)
|
| 163 |
# Add a second button inside Panel 2 to hide the panel and show Panel 1 again
|
| 164 |
btn_2 = gr.Button("Logout", visible=True, scale=0)
|
| 165 |
-
btn_2.click(hide_and_show_panel, outputs=[panel_2, panel_1]) # Hide Panel 2 and show Panel 1
|
| 166 |
with gr.Row():
|
| 167 |
start_input = gr.Textbox(label="Start Date:", placeholder="Enter date (e.g., 2023-09-01)", max_lines=1)
|
| 168 |
prediction_input = gr.Text(label="Month Prediction:", placeholder="Enter date (e.g., 2024-10-31)", max_lines=1)
|
|
@@ -175,12 +176,12 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 175 |
# file_name_input = gr.Textbox(label="CSV Name", placeholder="Predictions.csv")
|
| 176 |
# btn_saving = gr.Button("Save CSV")
|
| 177 |
|
| 178 |
-
btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input], outputs=table_)
|
| 179 |
#btn_saving.click(fn=save_csv, inputs=file_name_input, outputs=gr.Textbox(label="File Status:"))
|
| 180 |
|
| 181 |
|
| 182 |
# Configure the buttons and the panel visibility
|
| 183 |
-
btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1
|
| 184 |
|
| 185 |
demo.launch()
|
| 186 |
|
|
|
|
| 19 |
def check_words(user_text, input_text):
|
| 20 |
# If the entered text is "user" and "casa", show Panel 2 and hide Panel 1
|
| 21 |
if user_text == os.getenv("USER_1_") and input_text == os.getenv("PASS_1_"):
|
| 22 |
+
return gr.update(visible=True), gr.update(visible=False)#, gr.update(value=""), gr.update(value="")
|
| 23 |
elif user_text == os.getenv("USER_2_") and input_text == os.getenv("PASS_2_"):
|
| 24 |
+
return gr.update(visible=True), gr.update(visible=False)#, gr.update(value=""), gr.update(value="")
|
| 25 |
elif user_text == os.getenv("USER_3_") and input_text == os.getenv("PASS_3_"):
|
| 26 |
+
return gr.update(visible=True), gr.update(visible=False)#, gr.update(value=""), gr.update(value="")
|
| 27 |
elif user_text == os.getenv("USER_4_") and input_text == os.getenv("PASS_4_"):
|
| 28 |
+
return gr.update(visible=True), gr.update(visible=False)#, gr.update(value=""), gr.update(value="")
|
| 29 |
else:
|
| 30 |
+
return gr.update(visible=False), gr.update(visible=True)#, user_text, input_text # Keep Panel 2 hidden, show Panel 1
|
| 31 |
|
| 32 |
# Function to hide Panel 2
|
| 33 |
def hide_panel():
|
|
|
|
| 39 |
|
| 40 |
# Wrapper function to hide Panel 2 and show Panel 1 when btn_2 is clicked
|
| 41 |
def hide_and_show_panel():
|
| 42 |
+
return hide_panel(), show_panel_1(), gr.update(value=""), gr.update(value="")
|
| 43 |
|
| 44 |
#def update_message(request: gr.Request):
|
| 45 |
# return f"Welcome, {request.username}"
|
|
|
|
| 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 |
|
| 79 |
+
def update_table(start_date, end_date, window, user_text):
|
| 80 |
#############################################################################################
|
| 81 |
try:
|
| 82 |
DATABRICKS_INSTANCE = 'https://136286767906206.6.gcp.databricks.com'
|
|
|
|
| 88 |
"events_api_base_url": "https://beta.datascore.ai",
|
| 89 |
"month_train_starting": str(start_date),
|
| 90 |
"month_for_prediction": str(end_date),
|
| 91 |
+
"moving_average_period": str(window),
|
| 92 |
+
"username": str(user_text)
|
| 93 |
}
|
| 94 |
|
| 95 |
url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/run-now"
|
|
|
|
| 163 |
# logout_button = gr.Button("Logout", link="/logout", scale=0)
|
| 164 |
# Add a second button inside Panel 2 to hide the panel and show Panel 1 again
|
| 165 |
btn_2 = gr.Button("Logout", visible=True, scale=0)
|
| 166 |
+
btn_2.click(hide_and_show_panel, outputs=[panel_2, panel_1, user_text, input_text]) # Hide Panel 2 and show Panel 1
|
| 167 |
with gr.Row():
|
| 168 |
start_input = gr.Textbox(label="Start Date:", placeholder="Enter date (e.g., 2023-09-01)", max_lines=1)
|
| 169 |
prediction_input = gr.Text(label="Month Prediction:", placeholder="Enter date (e.g., 2024-10-31)", max_lines=1)
|
|
|
|
| 176 |
# file_name_input = gr.Textbox(label="CSV Name", placeholder="Predictions.csv")
|
| 177 |
# btn_saving = gr.Button("Save CSV")
|
| 178 |
|
| 179 |
+
btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input, user_text], outputs=table_)
|
| 180 |
#btn_saving.click(fn=save_csv, inputs=file_name_input, outputs=gr.Textbox(label="File Status:"))
|
| 181 |
|
| 182 |
|
| 183 |
# Configure the buttons and the panel visibility
|
| 184 |
+
btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1]) # Hide Panel 1 and show Panel 2
|
| 185 |
|
| 186 |
demo.launch()
|
| 187 |
|