area444 commited on
Commit
e95a4f5
·
verified ·
1 Parent(s): 4a257f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
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), user_text#, 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), user_text#, 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), user_text#, 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), user_text#, gr.update(value=""), gr.update(value="")
29
  else:
30
- return gr.update(visible=False), gr.update(visible=True), user_text#, user_text, input_text # Keep Panel 2 hidden, show Panel 1
31
 
32
  # Function to hide Panel 2
33
  def hide_panel():
@@ -77,7 +77,7 @@ def get_month_label(i):
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, tu):
81
  #############################################################################################
82
  try:
83
  DATABRICKS_INSTANCE = 'https://136286767906206.6.gcp.databricks.com'
@@ -90,7 +90,7 @@ def update_table(start_date, end_date, window, tu):
90
  "month_train_starting": str(start_date),
91
  "month_for_prediction": str(end_date),
92
  "moving_average_period": str(window),
93
- "username": str(tu)
94
  }
95
 
96
  url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/run-now"
@@ -123,7 +123,7 @@ def update_table(start_date, end_date, window, tu):
123
  print(f"Run ID: {run_id}")
124
  #data_payments = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_payments.csv")
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(tu).split('@')[0]+".csv")
127
  #df_payments = pd.read_csv(StringIO(data_payments.decode('utf-8')))
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')))
@@ -161,7 +161,7 @@ with gr.Blocks(fill_height=True) as demo:
161
  # demo.load(update_message, None, gr.Markdown())
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
- tu = gr.Textbox(interactive=False, scale=0)
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():
@@ -172,10 +172,10 @@ with gr.Blocks(fill_height=True) as demo:
172
  table_ = gr.DataFrame(value=df, label="Predictions (consult 'revenue' column):")
173
  btn_update = gr.Button("Run Forecast")
174
 
175
- btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input, tu], outputs=table_)
176
 
177
  # Configure the buttons and the panel visibility
178
- btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1, tu]) # Hide Panel 1 and show Panel 2
179
 
180
  demo.launch()
181
 
 
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)#, user_text#, 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)#, user_text#, 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)#, user_text#, 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)#, user_text#, gr.update(value=""), gr.update(value="")
29
  else:
30
+ return gr.update(visible=False), gr.update(visible=True)#, user_text#, user_text, input_text # Keep Panel 2 hidden, show Panel 1
31
 
32
  # Function to hide Panel 2
33
  def hide_panel():
 
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
  #############################################################################################
82
  try:
83
  DATABRICKS_INSTANCE = 'https://136286767906206.6.gcp.databricks.com'
 
90
  "month_train_starting": str(start_date),
91
  "month_for_prediction": str(end_date),
92
  "moving_average_period": str(window),
93
+ "username": str(user_text)
94
  }
95
 
96
  url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/run-now"
 
123
  print(f"Run ID: {run_id}")
124
  #data_payments = get_databricks_file("dbfs:/dbfs/FileStore/forecast_alleviatetax_payments.csv")
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
  #df_payments = pd.read_csv(StringIO(data_payments.decode('utf-8')))
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')))
 
161
  # demo.load(update_message, None, gr.Markdown())
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
+ #tu = gr.Textbox(interactive=False, scale=0)
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():
 
172
  table_ = gr.DataFrame(value=df, label="Predictions (consult 'revenue' column):")
173
  btn_update = gr.Button("Run Forecast")
174
 
175
+ btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input, user_text], outputs=table_)
176
 
177
  # Configure the buttons and the panel visibility
178
+ btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1])
179
 
180
  demo.launch()
181