Spaces:
Sleeping
Sleeping
Commit ·
3083fb8
1
Parent(s): a8c82e8
Remove warmup and add strict error handling to catch infinite loading again
Browse files
app.py
CHANGED
|
@@ -108,9 +108,11 @@ def run_query(method, sample_q, custom_q, db_id):
|
|
| 108 |
return final_sql, df, explanation
|
| 109 |
|
| 110 |
|
| 111 |
-
def toggle_input_method(method):
|
| 112 |
if method == "💡 Pick a Sample":
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
else:
|
| 115 |
return gr.update(visible=False), gr.update(visible=True), gr.update(interactive=True)
|
| 116 |
|
|
@@ -125,7 +127,7 @@ def load_sample(selected_question):
|
|
| 125 |
def clear_inputs():
|
| 126 |
return (
|
| 127 |
gr.update(value="💡 Pick a Sample"),
|
| 128 |
-
gr.update(value=
|
| 129 |
gr.update(value="", visible=False),
|
| 130 |
gr.update(value="chinook_1", interactive=False),
|
| 131 |
"", pd.DataFrame(), ""
|
|
@@ -189,6 +191,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Text-to-SQL RLHF") as demo:
|
|
| 189 |
|
| 190 |
sample_dropdown = gr.Dropdown(
|
| 191 |
choices=SAMPLE_QUESTIONS,
|
|
|
|
| 192 |
label="Select a Sample Question",
|
| 193 |
info="The database will be selected automatically.",
|
| 194 |
visible=True
|
|
@@ -225,7 +228,14 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Text-to-SQL RLHF") as demo:
|
|
| 225 |
explanation = gr.Textbox(label="AI Explanation + Execution Details", lines=8)
|
| 226 |
|
| 227 |
# EVENT LISTENERS
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
sample_dropdown.change(fn=load_sample, inputs=[sample_dropdown], outputs=[db_id])
|
| 230 |
db_id.change(fn=update_schema, inputs=[db_id], outputs=[schema_display])
|
| 231 |
|
|
|
|
| 108 |
return final_sql, df, explanation
|
| 109 |
|
| 110 |
|
| 111 |
+
def toggle_input_method(method, current_sample):
|
| 112 |
if method == "💡 Pick a Sample":
|
| 113 |
+
# Find the DB matching the current sample (fallback to 'chinook_1')
|
| 114 |
+
db = next((db for q, db in SAMPLES if q == current_sample), "chinook_1")
|
| 115 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=db, interactive=False)
|
| 116 |
else:
|
| 117 |
return gr.update(visible=False), gr.update(visible=True), gr.update(interactive=True)
|
| 118 |
|
|
|
|
| 127 |
def clear_inputs():
|
| 128 |
return (
|
| 129 |
gr.update(value="💡 Pick a Sample"),
|
| 130 |
+
gr.update(value=SAMPLE_QUESTIONS[0], visible=True), # Reset correctly to first sample
|
| 131 |
gr.update(value="", visible=False),
|
| 132 |
gr.update(value="chinook_1", interactive=False),
|
| 133 |
"", pd.DataFrame(), ""
|
|
|
|
| 191 |
|
| 192 |
sample_dropdown = gr.Dropdown(
|
| 193 |
choices=SAMPLE_QUESTIONS,
|
| 194 |
+
value=SAMPLE_QUESTIONS[0], # Added default value here
|
| 195 |
label="Select a Sample Question",
|
| 196 |
info="The database will be selected automatically.",
|
| 197 |
visible=True
|
|
|
|
| 228 |
explanation = gr.Textbox(label="AI Explanation + Execution Details", lines=8)
|
| 229 |
|
| 230 |
# EVENT LISTENERS
|
| 231 |
+
|
| 232 |
+
# Updated listener to pass sample_dropdown
|
| 233 |
+
input_method.change(
|
| 234 |
+
fn=toggle_input_method,
|
| 235 |
+
inputs=[input_method, sample_dropdown],
|
| 236 |
+
outputs=[sample_dropdown, custom_question, db_id]
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
sample_dropdown.change(fn=load_sample, inputs=[sample_dropdown], outputs=[db_id])
|
| 240 |
db_id.change(fn=update_schema, inputs=[db_id], outputs=[schema_display])
|
| 241 |
|