abir-hr196 commited on
Commit
f72a9c9
·
1 Parent(s): 599e176
Files changed (3) hide show
  1. app.py +88 -6
  2. tinysql_dataset_viewer.py +45 -28
  3. tinysql_model_demo.py +16 -21
app.py CHANGED
@@ -15,7 +15,7 @@ custom_css = """
15
  background-color: var(--martian-black) !important;
16
  }
17
 
18
- /* Better tabs - bold, bigger, no icons */
19
  .tab-nav {
20
  border-bottom: 2px solid var(--martian-gray-dark) !important;
21
  background: var(--martian-gray-dark) !important;
@@ -31,6 +31,7 @@ custom_css = """
31
  margin: 0 0.25rem !important;
32
  transition: all 0.3s ease !important;
33
  color: #888 !important;
 
34
  }
35
 
36
  .tab-nav button:hover {
@@ -44,7 +45,7 @@ custom_css = """
44
  box-shadow: 0 2px 8px rgba(255, 107, 74, 0.3) !important;
45
  }
46
 
47
- /* Orange labels - remove all purple */
48
  label, .label-wrap {
49
  color: #E0E0E0 !important;
50
  }
@@ -58,23 +59,56 @@ label, .label-wrap {
58
  font-size: 0.9rem !important;
59
  }
60
 
61
- /* Orange sliders */
62
- input[type="range"] {
63
  background: var(--martian-gray-medium) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
  input[type="range"]::-webkit-slider-thumb {
67
  background: var(--martian-orange) !important;
68
  cursor: pointer !important;
 
 
 
69
  }
70
 
71
  input[type="range"]::-moz-range-thumb {
72
  background: var(--martian-orange) !important;
73
  cursor: pointer !important;
 
 
 
74
  }
75
 
76
  input[type="range"]::-webkit-slider-runnable-track {
77
- background: linear-gradient(to right, var(--martian-orange) 0%, var(--martian-gray-light) 100%) !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
 
80
  /* Remove any purple/blue colors */
@@ -83,6 +117,10 @@ input[type="range"]::-webkit-slider-runnable-track {
83
  border-color: var(--martian-orange) !important;
84
  }
85
 
 
 
 
 
86
  /* Footer */
87
  .footer {
88
  text-align: center;
@@ -119,6 +157,34 @@ input[type="range"]::-webkit-slider-runnable-track {
119
  0%, 100% { transform: scale(1); }
120
  50% { transform: scale(1.1); }
121
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  """
123
 
124
  with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Soft()) as demo:
@@ -142,6 +208,22 @@ with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Soft()) as
142
  with gr.Tab("Model Demo"):
143
  model_components = model_demo(shared_instruction, shared_schema)
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  # Footer with Martian branding
146
  gr.HTML("""
147
  <div class="footer">
@@ -152,7 +234,7 @@ with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Soft()) as
152
  <p class="footer-text" style="font-size: 0.85rem; margin-top: 1rem;">
153
  <a href="https://arxiv.org/abs/2503.12730" style="color: #FF6B4A; text-decoration: none;">Paper</a> •
154
  <a href="https://github.com/withmartian/TinySQL" style="color: #FF6B4A; text-decoration: none;">Code</a> •
155
- <a href="https://huggingface.co/collections/withmartian/tinysql-6760e92748b63fa56a6ffc9f" style="color: #FF6B4A; text-decoration: none;">Dataset</a>
156
  </p>
157
  </div>
158
  """)
 
15
  background-color: var(--martian-black) !important;
16
  }
17
 
18
+ /* Better tabs - bold, bigger, no icons, ORANGE selection */
19
  .tab-nav {
20
  border-bottom: 2px solid var(--martian-gray-dark) !important;
21
  background: var(--martian-gray-dark) !important;
 
31
  margin: 0 0.25rem !important;
32
  transition: all 0.3s ease !important;
33
  color: #888 !important;
34
+ border: none !important;
35
  }
36
 
37
  .tab-nav button:hover {
 
45
  box-shadow: 0 2px 8px rgba(255, 107, 74, 0.3) !important;
46
  }
47
 
48
+ /* REMOVE ALL PURPLE - Replace with orange */
49
  label, .label-wrap {
50
  color: #E0E0E0 !important;
51
  }
 
59
  font-size: 0.9rem !important;
60
  }
61
 
62
+ /* Orange dropdown and inputs - NO PURPLE */
63
+ select, input, textarea {
64
  background: var(--martian-gray-medium) !important;
65
+ border: 1px solid #3A3A3A !important;
66
+ color: #E0E0E0 !important;
67
+ }
68
+
69
+ select:focus, input:focus, textarea:focus {
70
+ border-color: var(--martian-orange) !important;
71
+ outline: none !important;
72
+ box-shadow: 0 0 0 2px rgba(255, 107, 74, 0.2) !important;
73
+ }
74
+
75
+ /* Orange sliders - selected area is orange */
76
+ input[type="range"] {
77
+ background: transparent !important;
78
  }
79
 
80
  input[type="range"]::-webkit-slider-thumb {
81
  background: var(--martian-orange) !important;
82
  cursor: pointer !important;
83
+ width: 16px !important;
84
+ height: 16px !important;
85
+ border-radius: 50% !important;
86
  }
87
 
88
  input[type="range"]::-moz-range-thumb {
89
  background: var(--martian-orange) !important;
90
  cursor: pointer !important;
91
+ width: 16px !important;
92
+ height: 16px !important;
93
+ border-radius: 50% !important;
94
  }
95
 
96
  input[type="range"]::-webkit-slider-runnable-track {
97
+ background: linear-gradient(to right, var(--martian-orange) 0%, var(--martian-orange) var(--value, 50%), #3A3A3A var(--value, 50%), #3A3A3A 100%) !important;
98
+ height: 4px !important;
99
+ border-radius: 2px !important;
100
+ }
101
+
102
+ input[type="range"]::-moz-range-track {
103
+ background: #3A3A3A !important;
104
+ height: 4px !important;
105
+ border-radius: 2px !important;
106
+ }
107
+
108
+ input[type="range"]::-moz-range-progress {
109
+ background: var(--martian-orange) !important;
110
+ height: 4px !important;
111
+ border-radius: 2px !important;
112
  }
113
 
114
  /* Remove any purple/blue colors */
 
117
  border-color: var(--martian-orange) !important;
118
  }
119
 
120
+ button {
121
+ border: none !important;
122
+ }
123
+
124
  /* Footer */
125
  .footer {
126
  text-align: center;
 
157
  0%, 100% { transform: scale(1); }
158
  50% { transform: scale(1.1); }
159
  }
160
+
161
+ .citation-box {
162
+ background: #2A2A2A;
163
+ border: 1px solid #3A3A3A;
164
+ border-radius: 12px;
165
+ padding: 1.5rem;
166
+ margin: 2rem auto;
167
+ max-width: 900px;
168
+ font-family: 'Monaco', 'Courier New', monospace;
169
+ font-size: 0.85rem;
170
+ }
171
+
172
+ .citation-header {
173
+ font-weight: 700;
174
+ color: #FF6B4A;
175
+ margin-bottom: 1rem;
176
+ font-size: 1.1rem;
177
+ text-align: center;
178
+ }
179
+
180
+ .citation-box pre {
181
+ color: #D0D0D0;
182
+ background: #1A1A1A;
183
+ padding: 1rem;
184
+ border-radius: 8px;
185
+ overflow-x: auto;
186
+ margin: 0;
187
+ }
188
  """
189
 
190
  with gr.Blocks(css=custom_css, title="TinySQL Demo", theme=gr.themes.Soft()) as demo:
 
208
  with gr.Tab("Model Demo"):
209
  model_components = model_demo(shared_instruction, shared_schema)
210
 
211
+ # Citation section
212
+ gr.HTML("""
213
+ <div class="citation-box">
214
+ <div class="citation-header">Cite Our Work</div>
215
+ <pre>@misc{harrasse2025tinysqlprogressivetexttosqldataset,
216
+ title={TinySQL: A Progressive Text-to-SQL Dataset for Mechanistic Interpretability Research},
217
+ author={Abir Harrasse and Philip Quirke and Clement Neo and Dhruv Nathawani and Luke Marks and Amir Abdullah},
218
+ year={2025},
219
+ eprint={2503.12730},
220
+ archivePrefix={arXiv},
221
+ primaryClass={cs.LG},
222
+ url={https://arxiv.org/abs/2503.12730}
223
+ }</pre>
224
+ </div>
225
+ """)
226
+
227
  # Footer with Martian branding
228
  gr.HTML("""
229
  <div class="footer">
 
234
  <p class="footer-text" style="font-size: 0.85rem; margin-top: 1rem;">
235
  <a href="https://arxiv.org/abs/2503.12730" style="color: #FF6B4A; text-decoration: none;">Paper</a> •
236
  <a href="https://github.com/withmartian/TinySQL" style="color: #FF6B4A; text-decoration: none;">Code</a> •
237
+ <a href="https://huggingface.co/collections/withmartian/tinysql-tinysql-6760e92748b63fa56a6ffc9f" style="color: #FF6B4A; text-decoration: none;">Dataset</a>
238
  </p>
239
  </div>
240
  """)
tinysql_dataset_viewer.py CHANGED
@@ -19,6 +19,8 @@ def load_preview(dataset_name):
19
  df = pd.DataFrame(ds).head(500)
20
  if all(col in df.columns for col in COLUMNS):
21
  df = df[COLUMNS]
 
 
22
  return df
23
  except Exception as e:
24
  return pd.DataFrame({"Error": [str(e)]})
@@ -62,32 +64,17 @@ def dataset_viewer(shared_instruction, shared_schema):
62
  info="Select complexity level"
63
  )
64
 
65
- # Better formatted model guide card
66
  gr.HTML("""
67
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0; border: 1px solid #3A3A3A;">
68
  <h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.25rem 0; font-weight: 700; border-bottom: 2px solid #3A3A3A; padding-bottom: 0.75rem;">Dataset Complexity Levels</h4>
69
 
70
- <div style="margin-bottom: 1.5rem;">
71
- <div style="color: #4CAF50; font-weight: 600; font-size: 0.95rem; margin-bottom: 0.5rem;">Basic Level</div>
72
- <div style="margin-left: 1rem; color: #999; font-size: 0.85rem; line-height: 1.8;">
73
- <div><strong style="color: #D0D0D0;">CS1:</strong> Basic SELECT-FROM queries</div>
74
- <div><strong style="color: #D0D0D0;">CS2:</strong> Adds ORDER BY clauses</div>
75
- </div>
76
- </div>
77
-
78
- <div style="margin-bottom: 1.5rem;">
79
- <div style="color: #FF9800; font-weight: 600; font-size: 0.95rem; margin-bottom: 0.5rem;">Intermediate Level</div>
80
- <div style="margin-left: 1rem; color: #999; font-size: 0.85rem; line-height: 1.8;">
81
- <div><strong style="color: #D0D0D0;">CS3:</strong> Aggregations (COUNT, SUM, AVG)</div>
82
- <div><strong style="color: #D0D0D0;">CS4:</strong> Adds WHERE filters</div>
83
- </div>
84
- </div>
85
-
86
- <div>
87
- <div style="color: #f44336; font-weight: 600; font-size: 0.95rem; margin-bottom: 0.5rem;">Advanced Level</div>
88
- <div style="margin-left: 1rem; color: #999; font-size: 0.85rem; line-height: 1.8;">
89
- <div><strong style="color: #D0D0D0;">CS5:</strong> Multi-table JOINs</div>
90
- </div>
91
  </div>
92
 
93
  <div style="margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid #3A3A3A;">
@@ -119,10 +106,14 @@ def dataset_viewer(shared_instruction, shared_schema):
119
  lines=1
120
  )
121
 
122
- # HuggingFace-style table
123
  gr.HTML("""
124
  <style>
125
- /* True HuggingFace-style table */
 
 
 
 
126
  .dataframe-container {
127
  border-radius: 8px !important;
128
  overflow: hidden !important;
@@ -153,11 +144,29 @@ def dataset_viewer(shared_instruction, shared_schema):
153
  .dataframe tbody tr {
154
  background: #111827 !important;
155
  border-bottom: 1px solid #1f2937 !important;
156
- transition: background-color 0.15s ease !important;
 
157
  }
158
 
159
  .dataframe tbody tr:hover {
160
  background: #1f2937 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
163
  .dataframe tbody td {
@@ -173,15 +182,23 @@ def dataset_viewer(shared_instruction, shared_schema):
173
  .dataframe tbody tr:last-child {
174
  border-bottom: none !important;
175
  }
 
 
 
 
 
 
 
 
 
176
  </style>
177
  """)
178
 
179
  df_display = gr.Dataframe(
180
- headers=COLUMNS,
181
- datatype=["str", "str", "str"],
182
  interactive=False,
183
  wrap=True,
184
- label="Results",
185
  elem_classes="dataframe-container"
186
  )
187
 
 
19
  df = pd.DataFrame(ds).head(500)
20
  if all(col in df.columns for col in COLUMNS):
21
  df = df[COLUMNS]
22
+ # Add index column
23
+ df.insert(0, 'index', range(len(df)))
24
  return df
25
  except Exception as e:
26
  return pd.DataFrame({"Error": [str(e)]})
 
64
  info="Select complexity level"
65
  )
66
 
67
+ # Simpler dataset guide - no colors, no beginner/intermediate
68
  gr.HTML("""
69
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0; border: 1px solid #3A3A3A;">
70
  <h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.25rem 0; font-weight: 700; border-bottom: 2px solid #3A3A3A; padding-bottom: 0.75rem;">Dataset Complexity Levels</h4>
71
 
72
+ <div style="color: #D0D0D0; font-size: 0.9rem; line-height: 2;">
73
+ <div><strong>CS1:</strong> Basic SELECT-FROM queries</div>
74
+ <div><strong>CS2:</strong> Adds ORDER BY clauses</div>
75
+ <div><strong>CS3:</strong> Aggregations (COUNT, SUM, AVG)</div>
76
+ <div><strong>CS4:</strong> Adds WHERE filters</div>
77
+ <div><strong>CS5:</strong> Multi-table JOINs</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  </div>
79
 
80
  <div style="margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid #3A3A3A;">
 
106
  lines=1
107
  )
108
 
109
+ # HuggingFace-style table with row index on hover
110
  gr.HTML("""
111
  <style>
112
+ /* True HuggingFace-style table - NO "Results" label */
113
+ .dataframe-container label {
114
+ display: none !important;
115
+ }
116
+
117
  .dataframe-container {
118
  border-radius: 8px !important;
119
  overflow: hidden !important;
 
144
  .dataframe tbody tr {
145
  background: #111827 !important;
146
  border-bottom: 1px solid #1f2937 !important;
147
+ transition: all 0.15s ease !important;
148
+ position: relative !important;
149
  }
150
 
151
  .dataframe tbody tr:hover {
152
  background: #1f2937 !important;
153
+ box-shadow: 0 2px 8px rgba(255, 107, 74, 0.1) !important;
154
+ }
155
+
156
+ .dataframe tbody tr:hover::before {
157
+ content: "Row " attr(data-row-index);
158
+ position: absolute;
159
+ left: -60px;
160
+ top: 50%;
161
+ transform: translateY(-50%);
162
+ background: #FF6B4A;
163
+ color: white;
164
+ padding: 0.25rem 0.5rem;
165
+ border-radius: 4px;
166
+ font-size: 0.75rem;
167
+ font-weight: 600;
168
+ white-space: nowrap;
169
+ opacity: 0.9;
170
  }
171
 
172
  .dataframe tbody td {
 
182
  .dataframe tbody tr:last-child {
183
  border-bottom: none !important;
184
  }
185
+
186
+ /* Hide index column but keep it for reference */
187
+ .dataframe tbody td:first-child,
188
+ .dataframe thead th:first-child {
189
+ width: 0 !important;
190
+ padding: 0 !important;
191
+ opacity: 0 !important;
192
+ position: absolute !important;
193
+ }
194
  </style>
195
  """)
196
 
197
  df_display = gr.Dataframe(
198
+ headers=["index"] + COLUMNS,
199
+ datatype=["number", "str", "str", "str"],
200
  interactive=False,
201
  wrap=True,
 
202
  elem_classes="dataframe-container"
203
  )
204
 
tinysql_model_demo.py CHANGED
@@ -61,15 +61,6 @@ def generate_sql(model_name, instruction, schema, max_length=256, temperature=0.
61
  except Exception as e:
62
  return f"Error: {str(e)}"
63
 
64
- # Only ONE example
65
- examples = [
66
- [
67
- "BM2_CS2_Syn (0.5B)",
68
- "List worker earnings from highest to lowest",
69
- "CREATE TABLE employees (name VARCHAR(100), salary INT, department VARCHAR(100))"
70
- ],
71
- ]
72
-
73
  def model_demo(shared_instruction, shared_schema):
74
  gr.HTML("""
75
  <div style="text-align: center; padding: 2rem; background: linear-gradient(135deg, #3A3A3A 0%, #4A4A4A 100%); border-radius: 16px; margin-bottom: 1.5rem;">
@@ -98,24 +89,24 @@ def model_demo(shared_instruction, shared_schema):
98
  info="Larger models = better accuracy"
99
  )
100
 
101
- # Better formatted guide
102
  gr.HTML("""
103
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0; border: 1px solid #3A3A3A;">
104
  <h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.25rem 0; font-weight: 700; border-bottom: 2px solid #3A3A3A; padding-bottom: 0.75rem;">Model Guide</h4>
105
 
106
  <div style="margin-bottom: 1rem;">
107
- <div style="color: #4CAF50; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM1 (33M parameters)</div>
108
- <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">Lightning fast, ideal for simple queries</div>
109
  </div>
110
 
111
  <div style="margin-bottom: 1rem;">
112
- <div style="color: #FF9800; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM2 (0.5B parameters)</div>
113
- <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">Balanced performance and speed</div>
114
  </div>
115
 
116
  <div style="margin-bottom: 1.25rem;">
117
- <div style="color: #f44336; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM3 (1B parameters)</div>
118
- <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">Most accurate for complex queries</div>
119
  </div>
120
 
121
  <div style="padding-top: 1rem; border-top: 1px solid #3A3A3A;">
@@ -133,9 +124,12 @@ def model_demo(shared_instruction, shared_schema):
133
 
134
  with gr.Column(scale=2):
135
  gr.Markdown("### Your Query")
136
- instruction = gr.Textbox(
 
 
137
  label="Natural Language Query",
138
- placeholder="e.g., Find all employees earning more than 50000 sorted by name",
 
139
  lines=2
140
  )
141
 
@@ -158,14 +152,15 @@ def model_demo(shared_instruction, shared_schema):
158
 
159
  gr.Markdown("### Example Query")
160
 
161
- # Custom examples with 2-line schema display
162
  gr.HTML("""
163
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1rem 0; border: 1px solid #3A3A3A;">
164
  <div style="margin-bottom: 0.75rem;">
165
  <strong style="color: #FF6B4A;">Model:</strong> <span style="color: #D0D0D0;">BM2_CS2_Syn (0.5B)</span>
166
  </div>
167
- <div style="margin-bottom: 0.75rem;">
168
- <strong style="color: #FF6B4A;">Query:</strong> <span style="color: #D0D0D0;">List worker earnings from highest to lowest</span>
 
169
  </div>
170
  <div>
171
  <strong style="color: #FF6B4A;">Schema:</strong>
 
61
  except Exception as e:
62
  return f"Error: {str(e)}"
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: 1.5rem;">
 
89
  info="Larger models = better accuracy"
90
  )
91
 
92
+ # Better formatted guide with base models
93
  gr.HTML("""
94
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0; border: 1px solid #3A3A3A;">
95
  <h4 style="color: #FF6B4A; font-size: 1rem; margin: 0 0 1.25rem 0; font-weight: 700; border-bottom: 2px solid #3A3A3A; padding-bottom: 0.75rem;">Model Guide</h4>
96
 
97
  <div style="margin-bottom: 1rem;">
98
+ <div style="color: #E0E0E0; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM1 (33M parameters)</div>
99
+ <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">TinyStories 33M fine-tuned</div>
100
  </div>
101
 
102
  <div style="margin-bottom: 1rem;">
103
+ <div style="color: #E0E0E0; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM2 (0.5B parameters)</div>
104
+ <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">Qwen 2.5 0.5B fine-tuned</div>
105
  </div>
106
 
107
  <div style="margin-bottom: 1.25rem;">
108
+ <div style="color: #E0E0E0; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem;">BM3 (1B parameters)</div>
109
+ <div style="color: #999; font-size: 0.85rem; margin-left: 1rem;">Llama 3.2 1B fine-tuned</div>
110
  </div>
111
 
112
  <div style="padding-top: 1rem; border-top: 1px solid #3A3A3A;">
 
124
 
125
  with gr.Column(scale=2):
126
  gr.Markdown("### Your Query")
127
+
128
+ # Query in code box like schema
129
+ instruction = gr.Code(
130
  label="Natural Language Query",
131
+ language="text",
132
+ value="",
133
  lines=2
134
  )
135
 
 
152
 
153
  gr.Markdown("### Example Query")
154
 
155
+ # Custom example with query in code box
156
  gr.HTML("""
157
  <div style="background: #2A2A2A; border-radius: 12px; padding: 1.5rem; margin: 1rem 0; border: 1px solid #3A3A3A;">
158
  <div style="margin-bottom: 0.75rem;">
159
  <strong style="color: #FF6B4A;">Model:</strong> <span style="color: #D0D0D0;">BM2_CS2_Syn (0.5B)</span>
160
  </div>
161
+ <div style="margin-bottom: 0.75rem;">
162
+ <strong style="color: #FF6B4A;">Query:</strong>
163
+ <pre style="background: #1A1A1A; padding: 0.75rem; border-radius: 6px; margin-top: 0.5rem; color: #D0D0D0; font-size: 0.85rem; line-height: 1.5;">List worker earnings from highest to lowest</pre>
164
  </div>
165
  <div>
166
  <strong style="color: #FF6B4A;">Schema:</strong>