Spaces:
Sleeping
Sleeping
Commit
·
b4215f7
1
Parent(s):
246c4f7
upd
Browse files- app.py +39 -146
- tinysql_dataset_viewer.py +14 -131
- tinysql_model_demo.py +28 -61
app.py
CHANGED
|
@@ -3,176 +3,71 @@ from tinysql_dataset_viewer import dataset_viewer
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
custom_css = """
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
--martian-gray-dark: #1A1A1A;
|
| 10 |
-
--martian-gray-medium: #2A2A2A;
|
| 11 |
}
|
| 12 |
|
| 13 |
-
/*
|
| 14 |
-
.
|
| 15 |
-
|
| 16 |
-
html,
|
| 17 |
-
.contain,
|
| 18 |
-
.app,
|
| 19 |
-
#root,
|
| 20 |
-
.main {
|
| 21 |
-
background-color: var(--martian-black) !important;
|
| 22 |
-
color-scheme: dark !important;
|
| 23 |
}
|
| 24 |
|
| 25 |
-
/* Only force black on main structural elements, not everything */
|
| 26 |
-
.gradio-container > div,
|
| 27 |
-
.contain > div,
|
| 28 |
-
.app > div {
|
| 29 |
-
background-color: var(--martian-black) !important;
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
/* Text should NOT have backgrounds */
|
| 33 |
-
h1, h2, h3, h4, h5, h6, p, span, label, strong, text, div > p, div > span {
|
| 34 |
-
background: transparent !important;
|
| 35 |
-
background-color: transparent !important;
|
| 36 |
-
color: #E0E0E0 !important;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
/* Ensure inline styled divs keep their backgrounds */
|
| 40 |
-
div[style*="background"],
|
| 41 |
-
section[style*="background"] {
|
| 42 |
-
/* Keep their inline styles - don't override */
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
/* TABS - Remove gray background, keep dark */
|
| 46 |
.tab-nav {
|
| 47 |
-
background:
|
| 48 |
-
border
|
| 49 |
-
padding: 0.5rem 1rem !important;
|
| 50 |
-
border-radius: 0 !important;
|
| 51 |
}
|
| 52 |
|
| 53 |
.tab-nav button {
|
| 54 |
-
font-size: 1.
|
| 55 |
-
font-weight:
|
| 56 |
-
padding: 1.25rem 2.5rem !important;
|
| 57 |
-
border-radius: 8px !important;
|
| 58 |
-
margin: 0 0.25rem !important;
|
| 59 |
-
transition: all 0.3s ease !important;
|
| 60 |
color: #888 !important;
|
| 61 |
-
border: none !important;
|
| 62 |
background: transparent !important;
|
| 63 |
}
|
| 64 |
|
| 65 |
-
.tab-nav button:hover {
|
| 66 |
-
background: var(--martian-gray-medium) !important;
|
| 67 |
-
color: #E0E0E0 !important;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
.tab-nav button.selected {
|
| 71 |
-
background:
|
| 72 |
color: white !important;
|
| 73 |
-
box-shadow: 0 2px 8px rgba(255, 107, 74, 0.3) !important;
|
| 74 |
}
|
| 75 |
|
| 76 |
-
/*
|
| 77 |
-
label
|
| 78 |
-
background:
|
| 79 |
color: white !important;
|
| 80 |
-
padding: 0.
|
| 81 |
-
border-radius:
|
| 82 |
font-weight: 700 !important;
|
| 83 |
-
font-size: 0.95rem !important;
|
| 84 |
-
display: inline-block !important;
|
| 85 |
}
|
| 86 |
|
| 87 |
-
/*
|
| 88 |
-
|
| 89 |
-
background: var(--martian-gray-medium) !important;
|
| 90 |
-
border: 1px solid #3A3A3A !important;
|
| 91 |
color: #E0E0E0 !important;
|
| 92 |
}
|
| 93 |
|
| 94 |
-
|
| 95 |
-
border-color: var(--martian-orange) !important;
|
| 96 |
-
outline: none !important;
|
| 97 |
-
box-shadow: 0 0 0 2px rgba(255, 107, 74, 0.2) !important;
|
| 98 |
-
}
|
| 99 |
-
|
| 100 |
-
/* Orange sliders */
|
| 101 |
-
input[type="range"]::-webkit-slider-thumb {
|
| 102 |
-
background: var(--martian-orange) !important;
|
| 103 |
-
}
|
| 104 |
-
|
| 105 |
-
input[type="range"]::-moz-range-thumb {
|
| 106 |
-
background: var(--martian-orange) !important;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
input[type="range"]::-webkit-slider-track {
|
| 110 |
-
background: #3A3A3A !important;
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
input[type="range"]::-moz-range-track {
|
| 114 |
-
background: #3A3A3A !important;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
/* Buttons */
|
| 118 |
-
.primary, .primary:hover {
|
| 119 |
-
background: var(--martian-orange) !important;
|
| 120 |
-
border-color: var(--martian-orange) !important;
|
| 121 |
-
color: white !important;
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
button {
|
| 125 |
-
border: none !important;
|
| 126 |
-
background: var(--martian-gray-medium) !important;
|
| 127 |
color: #E0E0E0 !important;
|
| 128 |
}
|
| 129 |
|
| 130 |
-
/*
|
| 131 |
-
.
|
| 132 |
-
background:
|
| 133 |
}
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
/* Dataset info - force white text for CS1, CS2, etc */
|
| 141 |
-
.dataset-info strong {
|
| 142 |
-
color: #E0E0E0 !important;
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
-
/* Dropdown and select */
|
| 146 |
-
select option {
|
| 147 |
-
background: var(--martian-gray-medium) !important;
|
| 148 |
-
color: #E0E0E0 !important;
|
| 149 |
}
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
background: var(--martian-gray-dark) !important;
|
| 154 |
-
color: #D0D0D0 !important;
|
| 155 |
}
|
| 156 |
"""
|
| 157 |
|
| 158 |
-
with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Base(
|
| 159 |
-
body_background_fill="*neutral_950",
|
| 160 |
-
body_background_fill_dark="*neutral_950",
|
| 161 |
-
background_fill_primary="*neutral_950",
|
| 162 |
-
background_fill_primary_dark="*neutral_950",
|
| 163 |
-
background_fill_secondary="*neutral_900",
|
| 164 |
-
background_fill_secondary_dark="*neutral_900",
|
| 165 |
-
block_background_fill="*neutral_950",
|
| 166 |
-
block_background_fill_dark="*neutral_950",
|
| 167 |
-
input_background_fill="*neutral_800",
|
| 168 |
-
input_background_fill_dark="*neutral_800",
|
| 169 |
-
button_primary_background_fill="*primary_600",
|
| 170 |
-
button_primary_background_fill_dark="*primary_600",
|
| 171 |
-
)) as demo:
|
| 172 |
gr.HTML("""
|
| 173 |
-
<div style="text-align: center; padding:
|
| 174 |
-
<h1 style="font-size:
|
| 175 |
-
<p style="color: #999; font-size:
|
| 176 |
</div>
|
| 177 |
""")
|
| 178 |
|
|
@@ -187,10 +82,9 @@ with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Base(primar
|
|
| 187 |
model_components = model_demo(shared_instruction, shared_schema)
|
| 188 |
|
| 189 |
gr.HTML("""
|
| 190 |
-
<div style="border-radius: 12px; padding:
|
| 191 |
-
<div style="
|
| 192 |
-
<
|
| 193 |
-
<pre style="font-family: 'Monaco', monospace; font-size: 0.85rem; overflow-x: auto; background: #1A1A1A; color: #D0D0D0; margin: 0; padding: 1rem; border-radius: 6px;">@misc{harrasse2025tinysqlprogressivetexttosqldataset,
|
| 194 |
title={TinySQL: A Progressive Text-to-SQL Dataset for Mechanistic Interpretability Research},
|
| 195 |
author={Abir Harrasse and Philip Quirke and Clement Neo and Dhruv Nathawani and Luke Marks and Amir Abdullah},
|
| 196 |
year={2025},
|
|
@@ -199,16 +93,15 @@ with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Base(primar
|
|
| 199 |
primaryClass={cs.LG},
|
| 200 |
url={https://arxiv.org/abs/2503.12730}
|
| 201 |
}</pre>
|
| 202 |
-
</div>
|
| 203 |
</div>
|
| 204 |
""")
|
| 205 |
|
| 206 |
gr.HTML("""
|
| 207 |
-
<div style="text-align: center; padding: 2rem 0;
|
| 208 |
-
<p style="font-size: 0.
|
| 209 |
-
<a href="https://arxiv.org/abs/2503.12730" style="color: #FF6B4A;">Paper</a> •
|
| 210 |
-
<a href="https://github.com/withmartian/TinySQL" style="color: #FF6B4A;">Code</a> •
|
| 211 |
-
<a href="https://huggingface.co/collections/withmartian/tinysql-6760e92748b63fa56a6ffc9f" style="color: #FF6B4A;">Dataset</a>
|
| 212 |
</p>
|
| 213 |
</div>
|
| 214 |
""")
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
custom_css = """
|
| 6 |
+
/* Force everything dark */
|
| 7 |
+
.gradio-container {
|
| 8 |
+
background: #0A0A0A !important;
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
+
/* Tabs - black background, bigger bold text */
|
| 12 |
+
.tabs {
|
| 13 |
+
background: #0A0A0A !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
.tab-nav {
|
| 17 |
+
background: #0A0A0A !important;
|
| 18 |
+
border: none !important;
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
.tab-nav button {
|
| 22 |
+
font-size: 1.8rem !important;
|
| 23 |
+
font-weight: 900 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
color: #888 !important;
|
|
|
|
| 25 |
background: transparent !important;
|
| 26 |
}
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
.tab-nav button.selected {
|
| 29 |
+
background: #FF6B4A !important;
|
| 30 |
color: white !important;
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
+
/* Orange labels */
|
| 34 |
+
label > span {
|
| 35 |
+
background: #FF6B4A !important;
|
| 36 |
color: white !important;
|
| 37 |
+
padding: 0.4rem 0.8rem !important;
|
| 38 |
+
border-radius: 6px !important;
|
| 39 |
font-weight: 700 !important;
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
+
/* Force white text everywhere */
|
| 43 |
+
* {
|
|
|
|
|
|
|
| 44 |
color: #E0E0E0 !important;
|
| 45 |
}
|
| 46 |
|
| 47 |
+
h1, h2, h3, h4, h5, h6 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
color: #E0E0E0 !important;
|
| 49 |
}
|
| 50 |
|
| 51 |
+
/* Orange buttons */
|
| 52 |
+
.primary {
|
| 53 |
+
background: #FF6B4A !important;
|
| 54 |
}
|
| 55 |
|
| 56 |
+
/* Orange sliders */
|
| 57 |
+
input[type="range"]::-webkit-slider-thumb {
|
| 58 |
+
background: #FF6B4A !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
+
input[type="range"]::-moz-range-thumb {
|
| 62 |
+
background: #FF6B4A !important;
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
"""
|
| 65 |
|
| 66 |
+
with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Base()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
gr.HTML("""
|
| 68 |
+
<div style="text-align: center; padding: 2rem 0; background: #0A0A0A;">
|
| 69 |
+
<h1 style="font-size: 2.5rem; font-weight: 700; color: #FF6B4A; margin: 0;">TinySQL</h1>
|
| 70 |
+
<p style="color: #999; font-size: 1rem; margin-top: 0.5rem;">Mechanistic Interpretability for Text-to-SQL</p>
|
| 71 |
</div>
|
| 72 |
""")
|
| 73 |
|
|
|
|
| 82 |
model_components = model_demo(shared_instruction, shared_schema)
|
| 83 |
|
| 84 |
gr.HTML("""
|
| 85 |
+
<div style="background: #2A2A2A; border-radius: 12px; padding: 2rem; margin: 3rem auto; max-width: 900px;">
|
| 86 |
+
<div style="color: #FF6B4A; font-weight: 700; font-size: 1.2rem; text-align: center; margin-bottom: 1.5rem;">Cite Our Work</div>
|
| 87 |
+
<pre style="background: #1A1A1A; color: #D0D0D0; padding: 1.5rem; border-radius: 8px; overflow-x: auto; font-family: monospace; font-size: 0.85rem; margin: 0;">@misc{harrasse2025tinysqlprogressivetexttosqldataset,
|
|
|
|
| 88 |
title={TinySQL: A Progressive Text-to-SQL Dataset for Mechanistic Interpretability Research},
|
| 89 |
author={Abir Harrasse and Philip Quirke and Clement Neo and Dhruv Nathawani and Luke Marks and Amir Abdullah},
|
| 90 |
year={2025},
|
|
|
|
| 93 |
primaryClass={cs.LG},
|
| 94 |
url={https://arxiv.org/abs/2503.12730}
|
| 95 |
}</pre>
|
|
|
|
| 96 |
</div>
|
| 97 |
""")
|
| 98 |
|
| 99 |
gr.HTML("""
|
| 100 |
+
<div style="text-align: center; padding: 2rem 0; background: #0A0A0A;">
|
| 101 |
+
<p style="color: #999; font-size: 0.9rem;">
|
| 102 |
+
<a href="https://arxiv.org/abs/2503.12730" style="color: #FF6B4A; text-decoration: none;">Paper</a> •
|
| 103 |
+
<a href="https://github.com/withmartian/TinySQL" style="color: #FF6B4A; text-decoration: none;">Code</a> •
|
| 104 |
+
<a href="https://huggingface.co/collections/withmartian/tinysql-6760e92748b63fa56a6ffc9f" style="color: #FF6B4A; text-decoration: none;">Dataset</a>
|
| 105 |
</p>
|
| 106 |
</div>
|
| 107 |
""")
|
tinysql_dataset_viewer.py
CHANGED
|
@@ -13,11 +13,9 @@ DATASETS = {
|
|
| 13 |
|
| 14 |
COLUMNS = ["create_statement", "english_prompt", "sql_statement"]
|
| 15 |
|
| 16 |
-
# Pre-cache datasets on startup
|
| 17 |
dataset_cache = {}
|
| 18 |
|
| 19 |
def preload_datasets():
|
| 20 |
-
"""Load first 500 rows of all datasets into cache"""
|
| 21 |
for name, path in DATASETS.items():
|
| 22 |
try:
|
| 23 |
ds = load_dataset(path, split="train")
|
|
@@ -30,11 +28,9 @@ def preload_datasets():
|
|
| 30 |
except Exception as e:
|
| 31 |
print(f"✗ Failed to cache {name}: {e}")
|
| 32 |
|
| 33 |
-
# Preload on import
|
| 34 |
preload_datasets()
|
| 35 |
|
| 36 |
def load_preview(dataset_name):
|
| 37 |
-
"""Load from cache instantly"""
|
| 38 |
if dataset_name in dataset_cache:
|
| 39 |
return dataset_cache[dataset_name]
|
| 40 |
return pd.DataFrame({"Error": ["Dataset not found in cache"]})
|
|
@@ -55,19 +51,9 @@ def filter_dataframe(df, search_query, search_column):
|
|
| 55 |
|
| 56 |
def dataset_viewer(shared_instruction, shared_schema):
|
| 57 |
gr.HTML("""
|
| 58 |
-
<div style="text-align: center; padding:
|
| 59 |
-
<h2 style="font-size:
|
| 60 |
-
<p style="font-size:
|
| 61 |
-
Browse, search, and explore TinySQL datasets
|
| 62 |
-
</p>
|
| 63 |
-
</div>
|
| 64 |
-
""")
|
| 65 |
-
|
| 66 |
-
gr.HTML("""
|
| 67 |
-
<div style="background: linear-gradient(135deg, #2A2A2A 0%, #3A3A3A 100%); border-radius: 12px; padding: 1.25rem; margin: 1rem 0; border-left: 4px solid #FF6B4A;">
|
| 68 |
-
<p style="color: #D0D0D0; margin: 0; line-height: 1.6;">
|
| 69 |
-
<strong style="color: #FF6B4A;">Quick Start:</strong> Select a dataset and click Load Dataset. Use search to filter results.
|
| 70 |
-
</p>
|
| 71 |
</div>
|
| 72 |
""")
|
| 73 |
|
|
@@ -78,27 +64,20 @@ def dataset_viewer(shared_instruction, shared_schema):
|
|
| 78 |
dataset_dropdown = gr.Dropdown(
|
| 79 |
choices=list(DATASETS.keys()),
|
| 80 |
value="CS1",
|
| 81 |
-
label="Choose Dataset"
|
| 82 |
-
info="Select complexity level"
|
| 83 |
)
|
| 84 |
|
| 85 |
load_btn = gr.Button("Load Dataset", variant="primary", size="lg")
|
| 86 |
|
| 87 |
gr.HTML("""
|
| 88 |
-
<div style="background: #2A2A2A; border-radius: 12px; padding: 1.
|
| 89 |
-
<h4 style="color: #FF6B4A; font-size:
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
<div><strong>
|
| 93 |
-
<div><strong>
|
| 94 |
-
<div><strong>
|
| 95 |
-
<div><strong>
|
| 96 |
-
<div><strong>CS5:</strong> Multi-table JOINs</div>
|
| 97 |
-
</div>
|
| 98 |
-
|
| 99 |
-
<div style="margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #3A3A3A;">
|
| 100 |
-
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.5rem;">Synonym Variants</div>
|
| 101 |
-
<div style="color: #999; font-size: 0.8rem; line-height: 1.5;">Natural language variations</div>
|
| 102 |
</div>
|
| 103 |
</div>
|
| 104 |
""")
|
|
@@ -108,8 +87,7 @@ def dataset_viewer(shared_instruction, shared_schema):
|
|
| 108 |
label="Row Number",
|
| 109 |
value=0,
|
| 110 |
minimum=0,
|
| 111 |
-
precision=0
|
| 112 |
-
info="Pick a row to test"
|
| 113 |
)
|
| 114 |
|
| 115 |
send_to_model_btn = gr.Button("Run in Model Demo", variant="primary")
|
|
@@ -132,106 +110,11 @@ def dataset_viewer(shared_instruction, shared_schema):
|
|
| 132 |
scale=1
|
| 133 |
)
|
| 134 |
|
| 135 |
-
gr.HTML("""
|
| 136 |
-
<style>
|
| 137 |
-
/* HuggingFace-style table - FORCE DARK MODE */
|
| 138 |
-
.dataframe-container, .dataframe-container * {
|
| 139 |
-
color: #E0E0E0 !important;
|
| 140 |
-
background: var(--martian-black) !important;
|
| 141 |
-
}
|
| 142 |
-
|
| 143 |
-
.dataframe-container label {
|
| 144 |
-
display: none !important;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
.dataframe-container {
|
| 148 |
-
border-radius: 8px !important;
|
| 149 |
-
overflow: hidden !important;
|
| 150 |
-
border: 1px solid #374151 !important;
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
.dataframe table {
|
| 154 |
-
border-collapse: collapse !important;
|
| 155 |
-
width: 100% !important;
|
| 156 |
-
font-size: 0.875rem !important;
|
| 157 |
-
background: #111827 !important;
|
| 158 |
-
}
|
| 159 |
-
|
| 160 |
-
.dataframe thead {
|
| 161 |
-
background: #1f2937 !important;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
.dataframe thead th {
|
| 165 |
-
color: #9ca3af !important;
|
| 166 |
-
font-weight: 600 !important;
|
| 167 |
-
text-align: left !important;
|
| 168 |
-
padding: 0.75rem 1rem !important;
|
| 169 |
-
border-bottom: 1px solid #374151 !important;
|
| 170 |
-
font-size: 0.75rem !important;
|
| 171 |
-
text-transform: uppercase !important;
|
| 172 |
-
letter-spacing: 0.05em !important;
|
| 173 |
-
background: #1f2937 !important;
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
.dataframe tbody tr {
|
| 177 |
-
background: #111827 !important;
|
| 178 |
-
border-bottom: 1px solid #1f2937 !important;
|
| 179 |
-
transition: all 0.15s ease !important;
|
| 180 |
-
position: relative !important;
|
| 181 |
-
}
|
| 182 |
-
|
| 183 |
-
.dataframe tbody tr:hover {
|
| 184 |
-
background: #1f2937 !important;
|
| 185 |
-
box-shadow: 0 2px 8px rgba(255, 107, 74, 0.1) !important;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
.dataframe tbody tr:hover::before {
|
| 189 |
-
content: "Row " attr(data-row-index);
|
| 190 |
-
position: absolute;
|
| 191 |
-
left: -60px;
|
| 192 |
-
top: 50%;
|
| 193 |
-
transform: translateY(-50%);
|
| 194 |
-
background: #FF6B4A;
|
| 195 |
-
color: white;
|
| 196 |
-
padding: 0.25rem 0.5rem;
|
| 197 |
-
border-radius: 4px;
|
| 198 |
-
font-size: 0.75rem;
|
| 199 |
-
font-weight: 600;
|
| 200 |
-
white-space: nowrap;
|
| 201 |
-
opacity: 0.9;
|
| 202 |
-
}
|
| 203 |
-
|
| 204 |
-
.dataframe tbody td {
|
| 205 |
-
padding: 0.75rem 1rem !important;
|
| 206 |
-
color: #d1d5db !important;
|
| 207 |
-
font-size: 0.875rem !important;
|
| 208 |
-
line-height: 1.5 !important;
|
| 209 |
-
max-width: 400px !important;
|
| 210 |
-
overflow: hidden !important;
|
| 211 |
-
text-overflow: ellipsis !important;
|
| 212 |
-
background: #111827 !important;
|
| 213 |
-
}
|
| 214 |
-
|
| 215 |
-
.dataframe tbody tr:last-child {
|
| 216 |
-
border-bottom: none !important;
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
.dataframe tbody td:first-child,
|
| 220 |
-
.dataframe thead th:first-child {
|
| 221 |
-
width: 0 !important;
|
| 222 |
-
padding: 0 !important;
|
| 223 |
-
opacity: 0 !important;
|
| 224 |
-
position: absolute !important;
|
| 225 |
-
}
|
| 226 |
-
</style>
|
| 227 |
-
""")
|
| 228 |
-
|
| 229 |
df_display = gr.Dataframe(
|
| 230 |
headers=["index"] + COLUMNS,
|
| 231 |
datatype=["number", "str", "str", "str"],
|
| 232 |
interactive=False,
|
| 233 |
-
wrap=True
|
| 234 |
-
elem_classes="dataframe-container"
|
| 235 |
)
|
| 236 |
|
| 237 |
stats_display = gr.Markdown("Click **Load Dataset** to begin")
|
|
|
|
| 13 |
|
| 14 |
COLUMNS = ["create_statement", "english_prompt", "sql_statement"]
|
| 15 |
|
|
|
|
| 16 |
dataset_cache = {}
|
| 17 |
|
| 18 |
def preload_datasets():
|
|
|
|
| 19 |
for name, path in DATASETS.items():
|
| 20 |
try:
|
| 21 |
ds = load_dataset(path, split="train")
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
print(f"✗ Failed to cache {name}: {e}")
|
| 30 |
|
|
|
|
| 31 |
preload_datasets()
|
| 32 |
|
| 33 |
def load_preview(dataset_name):
|
|
|
|
| 34 |
if dataset_name in dataset_cache:
|
| 35 |
return dataset_cache[dataset_name]
|
| 36 |
return pd.DataFrame({"Error": ["Dataset not found in cache"]})
|
|
|
|
| 51 |
|
| 52 |
def dataset_viewer(shared_instruction, shared_schema):
|
| 53 |
gr.HTML("""
|
| 54 |
+
<div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #2A2A2A 0%, #3A3A3A 100%); border-radius: 16px; margin-bottom: 2rem;">
|
| 55 |
+
<h2 style="font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; color: #FF6B4A;">Dataset Explorer</h2>
|
| 56 |
+
<p style="font-size: 1rem; color: #D0D0D0; margin: 0;">Browse, search, and explore TinySQL datasets</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</div>
|
| 58 |
""")
|
| 59 |
|
|
|
|
| 64 |
dataset_dropdown = gr.Dropdown(
|
| 65 |
choices=list(DATASETS.keys()),
|
| 66 |
value="CS1",
|
| 67 |
+
label="Choose Dataset"
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
load_btn = gr.Button("Load Dataset", variant="primary", size="lg")
|
| 71 |
|
| 72 |
gr.HTML("""
|
| 73 |
+
<div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0;">
|
| 74 |
+
<h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1rem 0; font-weight: 700;">Dataset Levels</h4>
|
| 75 |
+
<div style="font-size: 0.9rem; line-height: 2;">
|
| 76 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS1:</strong> <span style="color: #FFFFFF;">Basic SELECT-FROM</span></div>
|
| 77 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS2:</strong> <span style="color: #FFFFFF;">Adds ORDER BY</span></div>
|
| 78 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS3:</strong> <span style="color: #FFFFFF;">Aggregations</span></div>
|
| 79 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS4:</strong> <span style="color: #FFFFFF;">WHERE filters</span></div>
|
| 80 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS5:</strong> <span style="color: #FFFFFF;">Multi-table JOINs</span></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
</div>
|
| 82 |
</div>
|
| 83 |
""")
|
|
|
|
| 87 |
label="Row Number",
|
| 88 |
value=0,
|
| 89 |
minimum=0,
|
| 90 |
+
precision=0
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
send_to_model_btn = gr.Button("Run in Model Demo", variant="primary")
|
|
|
|
| 110 |
scale=1
|
| 111 |
)
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
df_display = gr.Dataframe(
|
| 114 |
headers=["index"] + COLUMNS,
|
| 115 |
datatype=["number", "str", "str", "str"],
|
| 116 |
interactive=False,
|
| 117 |
+
wrap=True
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
stats_display = gr.Markdown("Click **Load Dataset** to begin")
|
tinysql_model_demo.py
CHANGED
|
@@ -63,19 +63,9 @@ def generate_sql(model_name, instruction, schema, max_length=256, temperature=0.
|
|
| 63 |
|
| 64 |
def model_demo(shared_instruction, shared_schema):
|
| 65 |
gr.HTML("""
|
| 66 |
-
<div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #3A3A3A 0%, #4A4A4A 100%); border-radius: 16px; margin-bottom:
|
| 67 |
<h2 style="font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; color: white;">Interactive SQL Generation</h2>
|
| 68 |
-
<p style="font-size: 1rem;
|
| 69 |
-
Transform natural language into SQL using <span style="color: #FF6B4A; font-weight: 600;">mechanistically interpretable</span> models
|
| 70 |
-
</p>
|
| 71 |
-
</div>
|
| 72 |
-
""")
|
| 73 |
-
|
| 74 |
-
gr.HTML("""
|
| 75 |
-
<div style="background: linear-gradient(135deg, #2A2A2A 0%, #3A3A3A 100%); border-radius: 12px; padding: 1.5rem; margin: 1rem 0; border-left: 4px solid #FF6B4A;">
|
| 76 |
-
<p style="color: #D0D0D0; margin: 0; line-height: 1.6;">
|
| 77 |
-
<strong style="color: #FF6B4A;">How it works:</strong> Select a model, describe your query in plain English, and watch the model generate SQL.
|
| 78 |
-
</p>
|
| 79 |
</div>
|
| 80 |
""")
|
| 81 |
|
|
@@ -85,37 +75,36 @@ def model_demo(shared_instruction, shared_schema):
|
|
| 85 |
model_dropdown = gr.Dropdown(
|
| 86 |
choices=list(MODELS.keys()),
|
| 87 |
value="BM2_CS2_Syn (0.5B)",
|
| 88 |
-
label="Model Selection"
|
| 89 |
-
info="Larger models = better accuracy"
|
| 90 |
)
|
| 91 |
|
| 92 |
gr.HTML("""
|
| 93 |
-
<div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0;
|
| 94 |
-
<h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.
|
| 95 |
|
| 96 |
<div style="margin-bottom: 1rem;">
|
| 97 |
-
<div style="
|
| 98 |
-
<div style="
|
| 99 |
</div>
|
| 100 |
|
| 101 |
<div style="margin-bottom: 1rem;">
|
| 102 |
-
<div style="
|
| 103 |
-
<div style="
|
| 104 |
</div>
|
| 105 |
|
| 106 |
-
<div style="margin-bottom: 1.
|
| 107 |
-
<div style="
|
| 108 |
-
<div style="
|
| 109 |
</div>
|
| 110 |
|
| 111 |
<div style="padding-top: 1rem; border-top: 1px solid #3A3A3A;">
|
| 112 |
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.75rem;">Dataset Complexity</div>
|
| 113 |
-
<div style="
|
| 114 |
-
<div><strong style="color: #
|
| 115 |
-
<div><strong style="color: #
|
| 116 |
-
<div><strong style="color: #
|
| 117 |
-
<div><strong style="color: #
|
| 118 |
-
<div><strong style="color: #
|
| 119 |
</div>
|
| 120 |
</div>
|
| 121 |
</div>
|
|
@@ -132,45 +121,23 @@ def model_demo(shared_instruction, shared_schema):
|
|
| 132 |
)
|
| 133 |
|
| 134 |
schema = gr.Code(
|
| 135 |
-
label="Database Schema",
|
| 136 |
language="sql",
|
| 137 |
-
value="CREATE TABLE employees (name VARCHAR(100)
|
| 138 |
-
lines=
|
| 139 |
)
|
| 140 |
|
| 141 |
with gr.Row():
|
| 142 |
-
max_length = gr.Slider(64, 512, value=256, step=32, label="Max Length"
|
| 143 |
-
temperature = gr.Slider(0.0, 1.0, value=0.0, step=0.1, label="Temperature"
|
| 144 |
|
| 145 |
generate_btn = gr.Button("Generate SQL", variant="primary", size="lg")
|
| 146 |
|
| 147 |
-
output = gr.Code(
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
gr.HTML("""
|
| 153 |
-
<div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1rem 0; border: 1px solid #3A3A3A;">
|
| 154 |
-
<div style="margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid #3A3A3A;">
|
| 155 |
-
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem;">Model</div>
|
| 156 |
-
<div style="background: #1A1A1A; padding: 0.75rem; border-radius: 6px; color: #D0D0D0; font-family: 'Inter', sans-serif; font-size: 0.9rem;">BM2_CS2_Syn (0.5B)</div>
|
| 157 |
-
</div>
|
| 158 |
-
|
| 159 |
-
<div style="margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid #3A3A3A;">
|
| 160 |
-
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem;">Natural Language Query</div>
|
| 161 |
-
<div style="background: #1A1A1A; padding: 0.75rem; border-radius: 6px; color: #D0D0D0; font-family: 'Inter', sans-serif; font-size: 0.9rem; line-height: 1.5;">List worker earnings from highest to lowest</div>
|
| 162 |
-
</div>
|
| 163 |
-
|
| 164 |
-
<div>
|
| 165 |
-
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.5rem;">Database Schema</div>
|
| 166 |
-
<pre style="background: #1A1A1A; padding: 0.75rem; border-radius: 6px; margin: 0; color: #D0D0D0; font-family: 'Monaco', 'Courier New', monospace; font-size: 0.85rem; line-height: 1.5; overflow-x: auto;">CREATE TABLE employees (
|
| 167 |
-
name VARCHAR(100),
|
| 168 |
-
salary INT,
|
| 169 |
-
department VARCHAR(100)
|
| 170 |
-
)</pre>
|
| 171 |
-
</div>
|
| 172 |
-
</div>
|
| 173 |
-
""")
|
| 174 |
|
| 175 |
shared_instruction.change(
|
| 176 |
fn=lambda x: x,
|
|
|
|
| 63 |
|
| 64 |
def model_demo(shared_instruction, shared_schema):
|
| 65 |
gr.HTML("""
|
| 66 |
+
<div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #3A3A3A 0%, #4A4A4A 100%); border-radius: 16px; margin-bottom: 2rem;">
|
| 67 |
<h2 style="font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; color: white;">Interactive SQL Generation</h2>
|
| 68 |
+
<p style="font-size: 1rem; color: #D0D0D0; margin: 0;">Transform natural language into SQL</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
</div>
|
| 70 |
""")
|
| 71 |
|
|
|
|
| 75 |
model_dropdown = gr.Dropdown(
|
| 76 |
choices=list(MODELS.keys()),
|
| 77 |
value="BM2_CS2_Syn (0.5B)",
|
| 78 |
+
label="Model Selection"
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
gr.HTML("""
|
| 82 |
+
<div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0;">
|
| 83 |
+
<h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.5rem 0; font-weight: 700;">Model Guide</h4>
|
| 84 |
|
| 85 |
<div style="margin-bottom: 1rem;">
|
| 86 |
+
<div style="font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; color: #FFFFFF;">BM1 (33M parameters)</div>
|
| 87 |
+
<div style="font-size: 0.85rem; margin-left: 1rem; color: #FFFFFF;">TinyStories 33M fine-tuned</div>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
<div style="margin-bottom: 1rem;">
|
| 91 |
+
<div style="font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; color: #FFFFFF;">BM2 (0.5B parameters)</div>
|
| 92 |
+
<div style="font-size: 0.85rem; margin-left: 1rem; color: #FFFFFF;">Qwen 2.5 0.5B fine-tuned</div>
|
| 93 |
</div>
|
| 94 |
|
| 95 |
+
<div style="margin-bottom: 1.5rem;">
|
| 96 |
+
<div style="font-weight: 600; font-size: 0.9rem; margin-bottom: 0.4rem; color: #FFFFFF;">BM3 (1B parameters)</div>
|
| 97 |
+
<div style="font-size: 0.85rem; margin-left: 1rem; color: #FFFFFF;">Llama 3.2 1B fine-tuned</div>
|
| 98 |
</div>
|
| 99 |
|
| 100 |
<div style="padding-top: 1rem; border-top: 1px solid #3A3A3A;">
|
| 101 |
<div style="color: #FF6B4A; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.75rem;">Dataset Complexity</div>
|
| 102 |
+
<div style="font-size: 0.9rem; line-height: 2;">
|
| 103 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS1:</strong> <span style="color: #FFFFFF;">Basic SELECT-FROM</span></div>
|
| 104 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS2:</strong> <span style="color: #FFFFFF;">Adds ORDER BY</span></div>
|
| 105 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS3:</strong> <span style="color: #FFFFFF;">Aggregations</span></div>
|
| 106 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS4:</strong> <span style="color: #FFFFFF;">WHERE filters</span></div>
|
| 107 |
+
<div style="color: #FFFFFF;"><strong style="color: #FFFFFF;">CS5:</strong> <span style="color: #FFFFFF;">Multi-table JOINs</span></div>
|
| 108 |
</div>
|
| 109 |
</div>
|
| 110 |
</div>
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
schema = gr.Code(
|
| 124 |
+
label="Database Schema (SQL)",
|
| 125 |
language="sql",
|
| 126 |
+
value="CREATE TABLE employees (\n name VARCHAR(100),\n salary INT,\n department VARCHAR(100)\n);",
|
| 127 |
+
lines=6
|
| 128 |
)
|
| 129 |
|
| 130 |
with gr.Row():
|
| 131 |
+
max_length = gr.Slider(64, 512, value=256, step=32, label="Max Length")
|
| 132 |
+
temperature = gr.Slider(0.0, 1.0, value=0.0, step=0.1, label="Temperature")
|
| 133 |
|
| 134 |
generate_btn = gr.Button("Generate SQL", variant="primary", size="lg")
|
| 135 |
|
| 136 |
+
output = gr.Code(
|
| 137 |
+
label="Generated SQL Query",
|
| 138 |
+
language="sql",
|
| 139 |
+
lines=8
|
| 140 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
shared_instruction.change(
|
| 143 |
fn=lambda x: x,
|