Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,17 +16,43 @@ DATABRICKS_INSTANCE = 'https://136286767906206.6.gcp.databricks.com'
|
|
16 |
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN_")
|
17 |
JOB_ID = os.getenv("JOB_ID_")
|
18 |
|
19 |
-
user_1 = os.getenv("USER_1_")
|
20 |
-
user_2 = os.getenv("USER_2_")
|
21 |
-
user_3 = os.getenv("USER_3_")
|
22 |
-
user_4 = os.getenv("USER_4_")
|
23 |
-
pass_1 = os.getenv("PASS_1_")
|
24 |
-
pass_2 = os.getenv("PASS_2_")
|
25 |
-
pass_3 = os.getenv("PASS_3_")
|
26 |
-
pass_4 = os.getenv("PASS_4_")
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def get_run_status(run_id):
|
32 |
url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/runs/get?run_id={run_id}"
|
@@ -132,25 +158,39 @@ def save_csv(file_name):
|
|
132 |
|
133 |
|
134 |
with gr.Blocks() as demo:
|
135 |
-
#
|
136 |
-
with gr.
|
137 |
-
|
138 |
-
|
139 |
-
with gr.Row():
|
140 |
-
start_input = gr.Textbox(label="Start Date:", placeholder="Enter date (e.g., 2023-09-01)", max_lines=1)
|
141 |
-
prediction_input = gr.Text(label="Month Prediction:", placeholder="Enter date (e.g., 2024-10-31)", max_lines=1)
|
142 |
-
range_input = gr.Slider(1, 100, 6, label="Window / Moving Average Period")
|
143 |
|
144 |
-
|
145 |
-
|
146 |
|
147 |
-
#with gr.Row():
|
148 |
-
# file_name_input = gr.Textbox(label="CSV Name", placeholder="Predictions.csv")
|
149 |
-
# btn_guardar = gr.Button("Save CSV")
|
150 |
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
demo.launch()
|
155 |
-
|
156 |
-
#demo.launch(auth=[("Pete", "123"), ("Da", "abc")])
|
|
|
16 |
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN_")
|
17 |
JOB_ID = os.getenv("JOB_ID_")
|
18 |
|
19 |
+
#user_1 = os.getenv("USER_1_")
|
20 |
+
#user_2 = os.getenv("USER_2_")
|
21 |
+
#user_3 = os.getenv("USER_3_")
|
22 |
+
#user_4 = os.getenv("USER_4_")
|
23 |
+
#pass_1 = os.getenv("PASS_1_")
|
24 |
+
#pass_2 = os.getenv("PASS_2_")
|
25 |
+
#pass_3 = os.getenv("PASS_3_")
|
26 |
+
#pass_4 = os.getenv("PASS_4_")
|
27 |
+
|
28 |
+
# Function that controls the visibility of the panels
|
29 |
+
def check_words(user_text, input_text):
|
30 |
+
# If the entered text is "user" and "casa", show Panel 2 and hide Panel 1
|
31 |
+
if user_text == os.getenv("USER_1_") and input_text == os.getenv("PASS_1_"):
|
32 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=""), gr.update(value="")
|
33 |
+
elif user_text == os.getenv("USER_2_") and input_text == os.getenv("PASS_2_"):
|
34 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=""), gr.update(value="")
|
35 |
+
elif user_text == os.getenv("USER_3_") and input_text == os.getenv("PASS_3_"):
|
36 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=""), gr.update(value="")
|
37 |
+
elif user_text == os.getenv("USER_4_") and input_text == os.getenv("PASS_4_"):
|
38 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=""), gr.update(value="")
|
39 |
+
else:
|
40 |
+
return gr.update(visible=False), gr.update(visible=True), user_text, input_text # Keep Panel 2 hidden, show Panel 1
|
41 |
+
|
42 |
+
# Function to hide Panel 2
|
43 |
+
def hide_panel():
|
44 |
+
return gr.update(visible=False) # Hide Panel 2
|
45 |
+
|
46 |
+
# Function to show Panel 1
|
47 |
+
def show_panel_1():
|
48 |
+
return gr.update(visible=True) # Show Panel 1
|
49 |
+
|
50 |
+
# Wrapper function to hide Panel 2 and show Panel 1 when btn_2 is clicked
|
51 |
+
def hide_and_show_panel():
|
52 |
+
return hide_panel(), show_panel_1()
|
53 |
+
|
54 |
+
#def update_message(request: gr.Request):
|
55 |
+
# return f"Welcome, {request.username}"
|
56 |
|
57 |
def get_run_status(run_id):
|
58 |
url = f"{DATABRICKS_INSTANCE}/api/2.1/jobs/runs/get?run_id={run_id}"
|
|
|
158 |
|
159 |
|
160 |
with gr.Blocks() as demo:
|
161 |
+
# Create the first panel (visible from the start)
|
162 |
+
with gr.Column(visible=True) as panel_1:
|
163 |
+
user_text = gr.Textbox(label="User name:", placeholder="Type here...", max_lines=1)
|
164 |
+
input_text = gr.Textbox(label="Password:", placeholder="Type here...", max_lines=1, type="password")
|
|
|
|
|
|
|
|
|
165 |
|
166 |
+
# First button, visible from the start
|
167 |
+
btn_1 = gr.Button("Login")
|
168 |
|
|
|
|
|
|
|
169 |
|
170 |
+
with gr.Column(visible=False) as panel_2:
|
171 |
+
#m = gr.Markdown()
|
172 |
+
#with gr.Row():
|
173 |
+
# demo.load(update_message, None, gr.Markdown())
|
174 |
+
# logout_button = gr.Button("Logout", link="/logout", scale=0)
|
175 |
+
with gr.Row():
|
176 |
+
start_input = gr.Textbox(label="Start Date:", placeholder="Enter date (e.g., 2023-09-01)", max_lines=1)
|
177 |
+
prediction_input = gr.Text(label="Month Prediction:", placeholder="Enter date (e.g., 2024-10-31)", max_lines=1)
|
178 |
+
range_input = gr.Slider(1, 10, 6, label="Window / Moving Average Period")
|
179 |
+
|
180 |
+
table_ = gr.DataFrame(value=df, label="Predictions (consult 'revenue' column):")
|
181 |
+
btn_update = gr.Button("Run Forecast")
|
182 |
+
|
183 |
+
#with gr.Row():
|
184 |
+
# file_name_input = gr.Textbox(label="CSV Name", placeholder="Predictions.csv")
|
185 |
+
# btn_saving = gr.Button("Save CSV")
|
186 |
+
|
187 |
+
btn_update.click(fn=update_table, inputs=[start_input, prediction_input, range_input], outputs=table_)
|
188 |
+
#btn_saving.click(fn=save_csv, inputs=file_name_input, outputs=gr.Textbox(label="File Status:"))
|
189 |
+
|
190 |
+
|
191 |
+
# Configure the buttons and the panel visibility
|
192 |
+
btn_1.click(check_words, inputs=[user_text, input_text], outputs=[panel_2, panel_1, user_text, input_text]) # Hide Panel 1 and show Panel 2
|
193 |
+
|
194 |
|
195 |
demo.launch()
|
196 |
+
|
|