LeonceNsh commited on
Commit
63ee7c3
Β·
verified Β·
1 Parent(s): 86317c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -21
app.py CHANGED
@@ -125,7 +125,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
125
 
126
  with gr.Column(scale=2):
127
  gr.Markdown("### πŸ“Š Query Results")
128
- results_out = gr.DataFrame(label="", interactive=False, row_count=10, max_rows=100)
129
  status_info = gr.Markdown("", visible=False, elem_id="status_info")
130
 
131
  # =========================
@@ -153,11 +153,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
153
  def handle_example_click(example_query):
154
  sql_query, error = parse_query(example_query)
155
  if error:
156
- return "", f"❌ {error}", None, f"❌ {error}"
157
  result_df, exec_error = execute_sql_query(sql_query)
158
  if exec_error:
159
- return sql_query, f"❌ {exec_error}", None, f"❌ {exec_error}"
160
- return sql_query, "", result_df, ""
161
 
162
  # =========================
163
  # Button Click Event Handlers
@@ -176,27 +176,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
176
  )
177
 
178
  # Assign click events to example buttons
179
- for btn in example_buttons:
180
- btn.click(
181
- fn=handle_example_click,
182
- inputs=None, # We'll pass the query via lambda
183
- outputs=[sql_query_out, error_out, results_out, error_out],
184
- _js=None,
185
- # Use a lambda to pass the button's value as the example_query
186
- # Note: Gradio passes the button's value as the first input if inputs are not specified
187
- # To ensure the correct query is passed, we use a lambda with no inputs
188
- # and retrieve the button's value within the function
189
- # However, Gradio does not support passing the button's value directly here
190
- # So, we need to create a partial function or use lambda with default argument
191
- # Here, we use a lambda with a default argument
192
- )
193
-
194
- # To properly assign each button's click event with its specific query, redefine the loop:
195
  for btn, query in zip(example_buttons, example_queries):
196
  btn.click(
197
  fn=lambda q=query: handle_example_click(q),
198
  inputs=None,
199
- outputs=[sql_query_out, error_out, results_out, error_out]
200
  )
201
 
202
  # Launch the Gradio App
 
125
 
126
  with gr.Column(scale=2):
127
  gr.Markdown("### πŸ“Š Query Results")
128
+ results_out = gr.DataFrame(label="", interactive=False, row_count=10)
129
  status_info = gr.Markdown("", visible=False, elem_id="status_info")
130
 
131
  # =========================
 
153
  def handle_example_click(example_query):
154
  sql_query, error = parse_query(example_query)
155
  if error:
156
+ return "", f"❌ {error}", None
157
  result_df, exec_error = execute_sql_query(sql_query)
158
  if exec_error:
159
+ return sql_query, f"❌ {exec_error}", None
160
+ return sql_query, "", result_df
161
 
162
  # =========================
163
  # Button Click Event Handlers
 
176
  )
177
 
178
  # Assign click events to example buttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  for btn, query in zip(example_buttons, example_queries):
180
  btn.click(
181
  fn=lambda q=query: handle_example_click(q),
182
  inputs=None,
183
+ outputs=[sql_query_out, error_out, results_out]
184
  )
185
 
186
  # Launch the Gradio App