Melika Kheirieh commited on
Commit
c9bbfcd
·
1 Parent(s): 6004317

refactor(ui): clean up Repair tab, sync outputs with backend and add examples

Browse files
Files changed (1) hide show
  1. demo/app.py +36 -7
demo/app.py CHANGED
@@ -110,7 +110,7 @@ def upload_db(file_obj):
110
 
111
  def query_to_sql(user_query: str, db_id: str | None, _debug_flag: bool):
112
  if not user_query.strip():
113
- return "❌ Please enter a query.", "", "", {}, [], [], "", []
114
 
115
  data = call_pipeline_api_or_mock(user_query, db_id)
116
  sql = data.get("sql") or ""
@@ -128,7 +128,8 @@ def query_to_sql(user_query: str, db_id: str | None, _debug_flag: bool):
128
  if trace_list and all("duration_ms" in t for t in trace_list):
129
  timings_table = [[t["stage"], t["duration_ms"]] for t in trace_list]
130
 
131
- return badges_text, sql, explanation, result, trace_list, [], "", timings_table
 
132
 
133
 
134
  def build_ui() -> gr.Blocks:
@@ -149,6 +150,18 @@ def build_ui() -> gr.Blocks:
149
  debug = gr.Checkbox(label="Debug (UI only)", value=True, scale=1)
150
  run = gr.Button("Run")
151
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  badges = gr.Markdown()
153
  sql_out = gr.Code(label="Final SQL", language="sql")
154
  exp_out = gr.Textbox(label="Explanation", lines=3)
@@ -160,11 +173,29 @@ def build_ui() -> gr.Blocks:
160
  trace = gr.JSON(label="Stage trace")
161
 
162
  with gr.Tab("Repair"):
163
- repair_candidates = gr.JSON(label="Candidates")
164
- repair_diff = gr.Textbox(label="Diff (if any)", lines=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
  with gr.Tab("Timings"):
167
- timings = gr.Dataframe(headers=["metric", "ms"], datatype=["str", "number"])
 
 
168
 
169
  run.click(
170
  query_to_sql,
@@ -175,8 +206,6 @@ def build_ui() -> gr.Blocks:
175
  exp_out,
176
  res_out,
177
  trace,
178
- repair_candidates,
179
- repair_diff,
180
  timings,
181
  ],
182
  )
 
110
 
111
  def query_to_sql(user_query: str, db_id: str | None, _debug_flag: bool):
112
  if not user_query.strip():
113
+ return "❌ Please enter a query.", "", "", {}, [], []
114
 
115
  data = call_pipeline_api_or_mock(user_query, db_id)
116
  sql = data.get("sql") or ""
 
128
  if trace_list and all("duration_ms" in t for t in trace_list):
129
  timings_table = [[t["stage"], t["duration_ms"]] for t in trace_list]
130
 
131
+ # Note: repair candidates / diff are not exposed in the UI yet.
132
+ return badges_text, sql, explanation, result, trace_list, timings_table
133
 
134
 
135
  def build_ui() -> gr.Blocks:
 
150
  debug = gr.Checkbox(label="Debug (UI only)", value=True, scale=1)
151
  run = gr.Button("Run")
152
 
153
+ # Example queries to make the demo easier to explore
154
+ gr.Examples(
155
+ examples=[
156
+ ["List all artists"],
157
+ ["Top 5 customers by total invoice amount"],
158
+ ["Total number of tracks per genre"],
159
+ ["Top 3 albums by total sales"],
160
+ ],
161
+ inputs=[q],
162
+ label="Try these example queries",
163
+ )
164
+
165
  badges = gr.Markdown()
166
  sql_out = gr.Code(label="Final SQL", language="sql")
167
  exp_out = gr.Textbox(label="Explanation", lines=3)
 
173
  trace = gr.JSON(label="Stage trace")
174
 
175
  with gr.Tab("Repair"):
176
+ gr.Markdown(
177
+ """
178
+ ### Repair & self-healing (pipeline-level)
179
+
180
+ The repair loop is fully implemented in the backend:
181
+
182
+ * If a candidate SQL fails safety or execution checks,
183
+ the pipeline attempts to **repair** it.
184
+ * All repair attempts and outcomes are tracked in Prometheus
185
+ (for example, `nl2sql_repair_attempts_total` and related rates).
186
+
187
+ For now, detailed before/after SQL diff and repair candidates
188
+ are exposed via trace logs and metrics dashboards.
189
+
190
+ This tab is reserved for a future, richer UI:
191
+ side-by-side SQL diff, repair candidates, and explanations.
192
+ """
193
+ )
194
 
195
  with gr.Tab("Timings"):
196
+ timings = gr.Dataframe(
197
+ headers=["stage", "duration_ms"], datatype=["str", "number"]
198
+ )
199
 
200
  run.click(
201
  query_to_sql,
 
206
  exp_out,
207
  res_out,
208
  trace,
 
 
209
  timings,
210
  ],
211
  )