Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -438,7 +438,6 @@ def install_schema(con: sqlite3.Connection, schema: Dict[str,Any]):
|
|
| 438 |
cols_sql.append(f"PRIMARY KEY ({', '.join(pk)})")
|
| 439 |
create_sql = f"CREATE TABLE {t['name']} ({', '.join(cols_sql)})"
|
| 440 |
cur.execute(create_sql)
|
| 441 |
-
# Add FKs (SQLite requires them inline on create; to be safe, we validate only)
|
| 442 |
# Insert rows
|
| 443 |
for t in schema.get("tables", []):
|
| 444 |
if not t.get("rows"):
|
|
@@ -732,7 +731,14 @@ def log_attempt(user_id: str, qid: str, category: str, correct: bool, sql_text:
|
|
| 732 |
def start_session(name: str, session: dict):
|
| 733 |
name = (name or "").strip()
|
| 734 |
if not name:
|
| 735 |
-
return session,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
|
| 737 |
slug = "-".join(name.lower().split())
|
| 738 |
user_id = slug[:64] if slug else f"user-{int(time.time())}"
|
|
@@ -869,6 +875,7 @@ with gr.Blocks(title="Adaptive SQL Trainer — Randomized Domains") as demo:
|
|
| 869 |
)
|
| 870 |
|
| 871 |
with gr.Row():
|
|
|
|
| 872 |
with gr.Column(scale=1):
|
| 873 |
name_box = gr.Textbox(label="Your Name", placeholder="e.g., Jordan Alvarez")
|
| 874 |
start_btn = gr.Button("Start / Resume Session", variant="primary")
|
|
@@ -890,18 +897,8 @@ with gr.Blocks(title="Adaptive SQL Trainer — Randomized Domains") as demo:
|
|
| 890 |
tbl_dd = gr.Dropdown(choices=list_tables_for_preview(), label="Pick table/view", interactive=True)
|
| 891 |
tbl_btn = gr.Button("Preview")
|
| 892 |
preview_df = gr.Dataframe(value=pd.DataFrame(), interactive=False)
|
| 893 |
-
|
| 894 |
-
# Progress by Category (labeled)
|
| 895 |
-
mastery_df = gr.Dataframe(
|
| 896 |
-
headers=["category","attempts","correct","accuracy"],
|
| 897 |
-
col_count=(4, "dynamic"),
|
| 898 |
-
row_count=(0, "dynamic"),
|
| 899 |
-
interactive=False
|
| 900 |
-
)
|
| 901 |
-
|
| 902 |
-
# Result Preview (always show query results here)
|
| 903 |
-
result_df = gr.Dataframe(value=pd.DataFrame(), interactive=False)
|
| 904 |
|
|
|
|
| 905 |
with gr.Column(scale=2):
|
| 906 |
prompt_md = gr.Markdown(visible=False)
|
| 907 |
sql_input = gr.Textbox(label="Your SQL", placeholder="Type SQL here (end ; optional).", lines=6, visible=False)
|
|
@@ -918,11 +915,16 @@ with gr.Blocks(title="Adaptive SQL Trainer — Randomized Domains") as demo:
|
|
| 918 |
|
| 919 |
gr.Markdown("---")
|
| 920 |
gr.Markdown("### Your Progress by Category")
|
| 921 |
-
mastery_df = gr.Dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
|
| 923 |
gr.Markdown("---")
|
| 924 |
gr.Markdown("### Result Preview")
|
| 925 |
-
result_df = gr.Dataframe(
|
| 926 |
|
| 927 |
# Wire events
|
| 928 |
start_btn.click(
|
|
|
|
| 438 |
cols_sql.append(f"PRIMARY KEY ({', '.join(pk)})")
|
| 439 |
create_sql = f"CREATE TABLE {t['name']} ({', '.join(cols_sql)})"
|
| 440 |
cur.execute(create_sql)
|
|
|
|
| 441 |
# Insert rows
|
| 442 |
for t in schema.get("tables", []):
|
| 443 |
if not t.get("rows"):
|
|
|
|
| 731 |
def start_session(name: str, session: dict):
|
| 732 |
name = (name or "").strip()
|
| 733 |
if not name:
|
| 734 |
+
return (session,
|
| 735 |
+
gr.update(value="Please enter your name to begin.", visible=True),
|
| 736 |
+
gr.update(visible=False),
|
| 737 |
+
gr.update(visible=False),
|
| 738 |
+
None,
|
| 739 |
+
gr.update(visible=False),
|
| 740 |
+
pd.DataFrame(),
|
| 741 |
+
pd.DataFrame())
|
| 742 |
|
| 743 |
slug = "-".join(name.lower().split())
|
| 744 |
user_id = slug[:64] if slug else f"user-{int(time.time())}"
|
|
|
|
| 875 |
)
|
| 876 |
|
| 877 |
with gr.Row():
|
| 878 |
+
# -------- Left column: controls + quick preview ----------
|
| 879 |
with gr.Column(scale=1):
|
| 880 |
name_box = gr.Textbox(label="Your Name", placeholder="e.g., Jordan Alvarez")
|
| 881 |
start_btn = gr.Button("Start / Resume Session", variant="primary")
|
|
|
|
| 897 |
tbl_dd = gr.Dropdown(choices=list_tables_for_preview(), label="Pick table/view", interactive=True)
|
| 898 |
tbl_btn = gr.Button("Preview")
|
| 899 |
preview_df = gr.Dataframe(value=pd.DataFrame(), interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
|
| 901 |
+
# -------- Right column: task + feedback + mastery + results ----------
|
| 902 |
with gr.Column(scale=2):
|
| 903 |
prompt_md = gr.Markdown(visible=False)
|
| 904 |
sql_input = gr.Textbox(label="Your SQL", placeholder="Type SQL here (end ; optional).", lines=6, visible=False)
|
|
|
|
| 915 |
|
| 916 |
gr.Markdown("---")
|
| 917 |
gr.Markdown("### Your Progress by Category")
|
| 918 |
+
mastery_df = gr.Dataframe(
|
| 919 |
+
headers=["category","attempts","correct","accuracy"],
|
| 920 |
+
col_count=(4, "dynamic"),
|
| 921 |
+
row_count=(0, "dynamic"),
|
| 922 |
+
interactive=False
|
| 923 |
+
)
|
| 924 |
|
| 925 |
gr.Markdown("---")
|
| 926 |
gr.Markdown("### Result Preview")
|
| 927 |
+
result_df = gr.Dataframe(value=pd.DataFrame(), interactive=False)
|
| 928 |
|
| 929 |
# Wire events
|
| 930 |
start_btn.click(
|