RealMati commited on
Commit
3fb0154
Β·
verified Β·
1 Parent(s): 281ebae

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +134 -222
app.py CHANGED
@@ -108,26 +108,23 @@ def format_parsed(sel, agg, conds, columns):
108
  def predict(question, schema, num_beams, max_length):
109
  if not question or not question.strip():
110
  return (
111
- "-- Enter a question and schema above, then click Generate SQL",
112
  "Waiting for input...",
113
  "No query submitted yet",
114
  "",
115
  )
116
-
117
  table_name, columns = parse_schema(schema)
118
-
119
  if not columns:
120
  return (
121
- "-- Please provide a database schema\n-- Format: table_name: col1, col2, col3",
122
- "Cannot generate without schema",
123
- "Schema is required to map column indices",
124
  "",
125
  )
126
 
127
  input_text = f"translate to SQL: {question}"
128
  if schema.strip():
129
  input_text += f" | schema: {schema.strip()}"
130
-
131
  inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
132
 
133
  t0 = time.time()
@@ -150,9 +147,8 @@ def predict(question, schema, num_beams, max_length):
150
  sql = f"-- Could not parse model output\n-- Raw: {raw_output}"
151
 
152
  parsed = format_parsed(sel, agg, conds, columns) if sel is not None else "Parse failed"
153
- latency_str = f"Inference: {latency:.2f}s | Beams: {int(num_beams)} | Input tokens: {inputs['input_ids'].shape[1]}"
154
-
155
- return sql, raw_output, parsed, latency_str
156
 
157
 
158
  theme = gr.themes.Soft(
@@ -163,52 +159,36 @@ theme = gr.themes.Soft(
163
  font_mono=gr.themes.GoogleFont("Fira Code"),
164
  )
165
 
166
- with gr.Blocks(title="Text-to-SQL | T5 Fine-tuned on WikiSQL") as demo:
167
 
168
- # ── Header ──
169
  gr.HTML("""
170
- <div class="main-header">
171
- <h1>Text-to-SQL</h1>
172
- <p class="tagline">A fine-tuned T5 encoder-decoder that translates natural language
173
- into structured SQL via learned column &amp; operator indices</p>
174
- <a class="model-link" href="https://huggingface.co/RealMati/t2sql_v6_structured" target="_blank">
175
- View Model on HuggingFace
176
- </a>
177
  </div>
178
- """)
179
-
180
- # ── Tech Badges ──
181
- gr.HTML("""
182
  <div class="tech-badges">
183
- <span class="badge badge-indigo">T5-base (220M params)</span>
184
  <span class="badge badge-purple">Seq2Seq</span>
185
- <span class="badge badge-emerald">WikiSQL (80K+ examples)</span>
186
  <span class="badge badge-amber">Structured Output</span>
187
  </div>
188
- """)
189
-
190
- # ── Pipeline Strip ──
191
- gr.HTML("""
192
  <div class="pipeline-strip">
193
- <span class="step step-input">Natural Language</span>
194
  <span class="arrow">&rarr;</span>
195
  <span class="step step-model">T5 Encoder-Decoder</span>
196
  <span class="arrow">&rarr;</span>
197
  <span class="step step-struct">SEL | AGG | CONDS</span>
198
  <span class="arrow">&rarr;</span>
199
- <span class="step step-sql">Executable SQL</span>
200
  </div>
201
  """)
202
 
203
- # ── Tabs ──
204
  with gr.Tabs():
205
 
206
- # ═══════════ TAB 1: DEMO ═══════════
207
  with gr.Tab("Demo"):
208
  with gr.Row(equal_height=False):
209
- # Left column β€” inputs
210
  with gr.Column(scale=1):
211
- gr.Markdown("#### Query Input")
212
  question = gr.Textbox(
213
  label="Natural Language Question",
214
  placeholder="e.g. What is terrence ross' nationality?",
@@ -219,56 +199,27 @@ with gr.Blocks(title="Text-to-SQL | T5 Fine-tuned on WikiSQL") as demo:
219
  placeholder="table_name: col1, col2, col3, ...",
220
  lines=2,
221
  )
222
- gr.HTML('<p class="input-hint">Format: <code>table_name: column1, column2, column3</code> &mdash; column order matters (maps to indices)</p>')
223
-
224
  with gr.Row():
225
  beams = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Beam Size")
226
  max_len = gr.Slider(minimum=64, maximum=512, value=256, step=64, label="Max Length")
227
-
228
  btn = gr.Button("Generate SQL", variant="primary", elem_classes=["generate-btn"], size="lg")
229
 
230
- # Right column β€” outputs
231
  with gr.Column(scale=1):
232
- gr.Markdown("#### Model Output")
233
  sql_out = gr.Textbox(
234
  label="Generated SQL",
235
- value="-- Enter a question and schema above, then click Generate SQL",
236
  lines=3,
237
  elem_classes=["sql-output"],
238
  )
239
- with gr.Row():
240
- raw_out = gr.Textbox(
241
- label="Raw Structured Tokens",
242
- value="Waiting for input...",
243
- lines=1,
244
- elem_classes=["decode-box"],
245
- )
246
- parsed_out = gr.Textbox(
247
- label="Decoded Mapping",
248
- value="No query submitted yet",
249
- lines=1,
250
- elem_classes=["decode-box"],
251
- )
252
- latency_out = gr.Textbox(
253
- label="Performance",
254
- value="",
255
- lines=1,
256
- elem_classes=["decode-box"],
257
- )
258
 
259
- btn.click(
260
- fn=predict,
261
- inputs=[question, schema, beams, max_len],
262
- outputs=[sql_out, raw_out, parsed_out, latency_out],
263
- )
264
- question.submit(
265
- fn=predict,
266
- inputs=[question, schema, beams, max_len],
267
- outputs=[sql_out, raw_out, parsed_out, latency_out],
268
- )
269
 
270
- # ── Examples ──
271
- gr.Markdown("#### Example Queries")
272
  gr.Examples(
273
  examples=[
274
  ["What is terrence ross' nationality", "players: Player, No., Nationality, Position, Years in Toronto, School/Club Team", 5, 256],
@@ -287,180 +238,141 @@ with gr.Blocks(title="Text-to-SQL | T5 Fine-tuned on WikiSQL") as demo:
287
  cache_examples=False,
288
  )
289
 
290
- # ═══════════ TAB 2: HOW IT WORKS ═══════════
291
  with gr.Tab("How It Works"):
292
  gr.HTML("""
293
- <div class="arch-section">
294
-
 
 
 
 
 
 
295
  <div class="arch-card">
296
- <h3>Architecture Overview</h3>
297
- <p>This system uses a <strong>T5-base</strong> (Text-to-Text Transfer Transformer) model
298
- fine-tuned on the <strong>WikiSQL</strong> dataset. Instead of generating raw SQL strings directly,
299
- the model outputs <em>structured tokens</em> that encode the query as column indices and operator codes.
300
- A deterministic decoder then maps these indices back to actual column names using the provided schema.</p>
301
  </div>
302
-
303
- <div class="arch-grid">
304
- <div class="arch-card">
305
- <h3>1. Input Encoding</h3>
306
- <p>The natural language question and database schema are concatenated into a single input string:</p>
307
- <p><code>translate to SQL: {question} | schema: {table}: {col1}, {col2}, ...</code></p>
308
- <p>The schema provides the column vocabulary. Column order is critical &mdash;
309
- the model references columns by their <strong>positional index</strong> (0-based).</p>
310
- </div>
311
-
312
- <div class="arch-card">
313
- <h3>2. T5 Generation</h3>
314
- <p>The encoder processes the full input sequence. The decoder then generates structured tokens
315
- using beam search (default: 5 beams) with early stopping.</p>
316
- <p>Output format: <code>SEL:{col_idx} | AGG:{agg_idx} | CONDS:{col},{op},{val};...</code></p>
317
- </div>
318
-
319
- <div class="arch-card">
320
- <h3>3. Structured Decoding</h3>
321
- <p>The raw token string is parsed into three components:</p>
322
- <ul style="margin:0.5rem 0; padding-left:1.2rem;">
323
- <li><strong>SEL</strong> &mdash; which column to SELECT (index into schema)</li>
324
- <li><strong>AGG</strong> &mdash; aggregation function (0=none, 1=MAX, 2=MIN, 3=COUNT, 4=SUM, 5=AVG)</li>
325
- <li><strong>CONDS</strong> &mdash; WHERE conditions as <code>col_idx,op_idx,value</code> tuples</li>
326
- </ul>
327
- </div>
328
-
329
- <div class="arch-card">
330
- <h3>4. SQL Assembly</h3>
331
- <p>Column indices are mapped back to actual column names from the schema. Operator indices
332
- are converted to SQL operators (=, >, <, >=, <=, !=). The components are assembled into
333
- a valid SQL query with proper quoting and escaping.</p>
334
- </div>
335
  </div>
336
-
337
  <div class="arch-card">
338
- <h3>Why Structured Output?</h3>
339
- <p>Generating SQL as structured indices rather than free-form text provides several advantages:</p>
340
- <ul style="margin:0.5rem 0; padding-left:1.2rem;">
341
- <li><strong>Schema-agnostic</strong> &mdash; The model learns query patterns, not specific column names.
342
- It generalizes across any table schema.</li>
343
- <li><strong>Syntactically valid</strong> &mdash; The deterministic decoder guarantees well-formed SQL.
344
- No risk of misspelled keywords or broken syntax.</li>
345
- <li><strong>Smaller output space</strong> &mdash; The model only needs to predict a few integers and condition values,
346
- reducing the search space and improving accuracy.</li>
347
- <li><strong>Interpretable</strong> &mdash; Each component (SEL, AGG, CONDS) can be inspected independently,
348
- making debugging and analysis straightforward.</li>
349
  </ul>
350
  </div>
351
-
352
  <div class="arch-card">
353
- <h3>Encoding Reference</h3>
354
- <table class="encoding-table">
355
- <tr>
356
- <th>Component</th>
357
- <th>Index</th>
358
- <th>Meaning</th>
359
- </tr>
360
- <tr><td rowspan="6"><strong>AGG</strong></td>
361
- <td class="mono">0</td><td>No aggregation (plain SELECT)</td></tr>
362
- <tr><td class="mono">1</td><td>MAX</td></tr>
363
- <tr><td class="mono">2</td><td>MIN</td></tr>
364
- <tr><td class="mono">3</td><td>COUNT</td></tr>
365
- <tr><td class="mono">4</td><td>SUM</td></tr>
366
- <tr><td class="mono">5</td><td>AVG</td></tr>
367
- <tr><td rowspan="6"><strong>OP</strong> (in CONDS)</td>
368
- <td class="mono">0</td><td>= (equals)</td></tr>
369
- <tr><td class="mono">1</td><td>> (greater than)</td></tr>
370
- <tr><td class="mono">2</td><td>< (less than)</td></tr>
371
- <tr><td class="mono">3</td><td>>= (greater or equal)</td></tr>
372
- <tr><td class="mono">4</td><td><= (less or equal)</td></tr>
373
- <tr><td class="mono">5</td><td>!= (not equal)</td></tr>
374
- </table>
375
  </div>
376
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  """)
378
 
379
- # ═══════════ TAB 3: MODEL INFO ═══════════
380
  with gr.Tab("Model & Training"):
381
  gr.HTML("""
382
- <div class="arch-section">
383
-
384
- <div class="stats-grid">
385
- <div class="stat-card">
386
- <div class="stat-value">220M</div>
387
- <div class="stat-label">Parameters</div>
388
- </div>
389
- <div class="stat-card">
390
- <div class="stat-value">80K+</div>
391
- <div class="stat-label">Training Examples</div>
392
- </div>
393
- <div class="stat-card">
394
- <div class="stat-value">T5-base</div>
395
- <div class="stat-label">Architecture</div>
396
- </div>
397
- <div class="stat-card">
398
- <div class="stat-value">WikiSQL</div>
399
- <div class="stat-label">Dataset</div>
400
- </div>
401
  </div>
402
-
403
- <div class="arch-grid">
404
- <div class="arch-card">
405
- <h3>Model Architecture</h3>
406
- <ul style="margin:0.5rem 0; padding-left:1.2rem;">
407
- <li><strong>Base model:</strong> T5-base (encoder-decoder transformer)</li>
408
- <li><strong>Tokenizer:</strong> SentencePiece (32K vocabulary)</li>
409
- <li><strong>Max input length:</strong> 512 tokens</li>
410
- <li><strong>Max output length:</strong> 256 tokens</li>
411
- <li><strong>Decoding:</strong> Beam search (default 5 beams)</li>
412
- <li><strong>Framework:</strong> HuggingFace Transformers + PyTorch</li>
413
- </ul>
414
- </div>
415
-
416
- <div class="arch-card">
417
- <h3>Training Details</h3>
418
- <ul style="margin:0.5rem 0; padding-left:1.2rem;">
419
- <li><strong>Dataset:</strong> WikiSQL (Zhong et al., 2017)</li>
420
- <li><strong>Train split:</strong> ~56,355 examples</li>
421
- <li><strong>Dev split:</strong> ~8,421 examples</li>
422
- <li><strong>Test split:</strong> ~15,878 examples</li>
423
- <li><strong>Output format:</strong> Structured tokens (SEL/AGG/CONDS)</li>
424
- <li><strong>Task prefix:</strong> <code>translate to SQL:</code></li>
425
- </ul>
426
- </div>
427
-
428
- <div class="arch-card">
429
- <h3>Dataset: WikiSQL</h3>
430
- <p>WikiSQL is a large-scale dataset of 80,654 hand-annotated SQL queries and natural language
431
- questions corresponding to 24,241 tables from Wikipedia. Each query operates on a single table
432
- and supports SELECT, aggregation (COUNT, SUM, MAX, MIN, AVG), and WHERE conditions
433
- with comparison operators.</p>
434
- <p style="margin-top:0.5rem;">
435
- <a href="https://github.com/salesforce/WikiSQL" target="_blank" style="color:#667eea;">
436
- github.com/salesforce/WikiSQL
437
- </a>
438
- </p>
439
- </div>
440
-
441
- <div class="arch-card">
442
- <h3>Limitations</h3>
443
- <ul style="margin:0.5rem 0; padding-left:1.2rem;">
444
- <li><strong>Single-table only</strong> &mdash; No JOINs or subqueries (WikiSQL constraint)</li>
445
- <li><strong>Fixed operators</strong> &mdash; Limited to =, >, <, >=, <=, != </li>
446
- <li><strong>No GROUP BY / ORDER BY</strong> &mdash; Not in the WikiSQL schema</li>
447
- <li><strong>AND-only conditions</strong> &mdash; Multiple conditions are joined with AND</li>
448
- <li><strong>Schema required</strong> &mdash; Column names and order must be provided</li>
449
- </ul>
450
- </div>
 
 
451
  </div>
452
  </div>
453
  """)
454
 
455
- # ── Footer ──
456
  gr.HTML("""
457
  <div class="app-footer">
458
- Built with <a href="https://huggingface.co/docs/transformers" target="_blank">Transformers</a>
459
- &amp; <a href="https://gradio.app" target="_blank">Gradio</a>
460
  &nbsp;&bull;&nbsp;
461
- Model: <a href="https://huggingface.co/RealMati/t2sql_v6_structured" target="_blank">RealMati/t2sql_v6_structured</a>
462
  &nbsp;&bull;&nbsp;
463
- Dataset: <a href="https://github.com/salesforce/WikiSQL" target="_blank">WikiSQL</a>
464
  </div>
465
  """)
466
 
 
108
  def predict(question, schema, num_beams, max_length):
109
  if not question or not question.strip():
110
  return (
111
+ "-- Enter a question and schema, then click Generate SQL",
112
  "Waiting for input...",
113
  "No query submitted yet",
114
  "",
115
  )
 
116
  table_name, columns = parse_schema(schema)
 
117
  if not columns:
118
  return (
119
+ "-- Please provide a schema\n-- Format: table_name: col1, col2, col3",
120
+ "Schema required",
121
+ "Cannot map indices without column names",
122
  "",
123
  )
124
 
125
  input_text = f"translate to SQL: {question}"
126
  if schema.strip():
127
  input_text += f" | schema: {schema.strip()}"
 
128
  inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
129
 
130
  t0 = time.time()
 
147
  sql = f"-- Could not parse model output\n-- Raw: {raw_output}"
148
 
149
  parsed = format_parsed(sel, agg, conds, columns) if sel is not None else "Parse failed"
150
+ perf = f"Inference: {latency:.2f}s | Beams: {int(num_beams)} | Tokens: {inputs['input_ids'].shape[1]}"
151
+ return sql, raw_output, parsed, perf
 
152
 
153
 
154
  theme = gr.themes.Soft(
 
159
  font_mono=gr.themes.GoogleFont("Fira Code"),
160
  )
161
 
162
+ with gr.Blocks(title="Text-to-SQL | T5 on WikiSQL") as demo:
163
 
164
+ # Compact header β€” one line title + badges + pipeline
165
  gr.HTML("""
166
+ <div class="app-header">
167
+ <h1><span>Text-to-SQL</span></h1>
 
 
 
 
 
168
  </div>
 
 
 
 
169
  <div class="tech-badges">
170
+ <span class="badge badge-indigo">T5-base (220M)</span>
171
  <span class="badge badge-purple">Seq2Seq</span>
172
+ <span class="badge badge-emerald">WikiSQL 80K+</span>
173
  <span class="badge badge-amber">Structured Output</span>
174
  </div>
 
 
 
 
175
  <div class="pipeline-strip">
176
+ <span class="step step-input">Question</span>
177
  <span class="arrow">&rarr;</span>
178
  <span class="step step-model">T5 Encoder-Decoder</span>
179
  <span class="arrow">&rarr;</span>
180
  <span class="step step-struct">SEL | AGG | CONDS</span>
181
  <span class="arrow">&rarr;</span>
182
+ <span class="step step-sql">SQL</span>
183
  </div>
184
  """)
185
 
 
186
  with gr.Tabs():
187
 
188
+ # ══ TAB 1: INFERENCE (main focus) ══
189
  with gr.Tab("Demo"):
190
  with gr.Row(equal_height=False):
 
191
  with gr.Column(scale=1):
 
192
  question = gr.Textbox(
193
  label="Natural Language Question",
194
  placeholder="e.g. What is terrence ross' nationality?",
 
199
  placeholder="table_name: col1, col2, col3, ...",
200
  lines=2,
201
  )
202
+ gr.HTML('<p class="input-hint">Format: <code>table: col1, col2, col3</code> β€” column order = index mapping</p>')
 
203
  with gr.Row():
204
  beams = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Beam Size")
205
  max_len = gr.Slider(minimum=64, maximum=512, value=256, step=64, label="Max Length")
 
206
  btn = gr.Button("Generate SQL", variant="primary", elem_classes=["generate-btn"], size="lg")
207
 
 
208
  with gr.Column(scale=1):
 
209
  sql_out = gr.Textbox(
210
  label="Generated SQL",
211
+ value="-- Enter a question and schema, then click Generate SQL",
212
  lines=3,
213
  elem_classes=["sql-output"],
214
  )
215
+ raw_out = gr.Textbox(label="Raw Structured Tokens", value="Waiting for input...", lines=1, elem_classes=["decode-box"])
216
+ parsed_out = gr.Textbox(label="Decoded Mapping", value="No query submitted yet", lines=1, elem_classes=["decode-box"])
217
+ latency_out = gr.Textbox(label="Performance", value="", lines=1, elem_classes=["decode-box"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
+ btn.click(fn=predict, inputs=[question, schema, beams, max_len], outputs=[sql_out, raw_out, parsed_out, latency_out])
220
+ question.submit(fn=predict, inputs=[question, schema, beams, max_len], outputs=[sql_out, raw_out, parsed_out, latency_out])
 
 
 
 
 
 
 
 
221
 
222
+ gr.Markdown("#### Examples")
 
223
  gr.Examples(
224
  examples=[
225
  ["What is terrence ross' nationality", "players: Player, No., Nationality, Position, Years in Toronto, School/Club Team", 5, 256],
 
238
  cache_examples=False,
239
  )
240
 
241
+ # ══ TAB 2: HOW IT WORKS ══
242
  with gr.Tab("How It Works"):
243
  gr.HTML("""
244
+ <div class="arch-card">
245
+ <h3>Architecture</h3>
246
+ <p>A <strong>T5-base</strong> encoder-decoder fine-tuned on WikiSQL.
247
+ Instead of generating raw SQL, it outputs <strong>structured tokens</strong>
248
+ β€” column indices and operator codes β€” which a deterministic decoder
249
+ maps to actual SQL using the provided schema.</p>
250
+ </div>
251
+ <div class="arch-grid">
252
  <div class="arch-card">
253
+ <h3>1. Input Encoding</h3>
254
+ <p>Question + schema concatenated:</p>
255
+ <p><code>translate to SQL: {question} | schema: {table}: {col1}, {col2}</code></p>
256
+ <p>Column order matters β€” the model references columns by <strong>0-based index</strong>.</p>
 
257
  </div>
258
+ <div class="arch-card">
259
+ <h3>2. T5 Generation</h3>
260
+ <p>The encoder processes input, decoder generates structured tokens via beam search.</p>
261
+ <p>Output: <code>SEL:{col} | AGG:{agg} | CONDS:{col},{op},{val}</code></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  </div>
 
263
  <div class="arch-card">
264
+ <h3>3. Structured Decoding</h3>
265
+ <ul style="margin:0.4rem 0;padding-left:1.2rem;">
266
+ <li><strong>SEL</strong> β€” column index to SELECT</li>
267
+ <li><strong>AGG</strong> β€” aggregation (0=none, 3=COUNT, etc.)</li>
268
+ <li><strong>CONDS</strong> β€” WHERE conditions as <code>col,op,value</code> tuples</li>
 
 
 
 
 
 
269
  </ul>
270
  </div>
 
271
  <div class="arch-card">
272
+ <h3>4. SQL Assembly</h3>
273
+ <p>Indices mapped back to column names from schema. Operators converted to SQL.
274
+ Result: a valid, executable query.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  </div>
276
  </div>
277
+ <div class="arch-card">
278
+ <h3>Why Structured Output?</h3>
279
+ <ul style="margin:0.4rem 0;padding-left:1.2rem;">
280
+ <li><strong>Schema-agnostic</strong> β€” learns patterns, not column names</li>
281
+ <li><strong>Always valid SQL</strong> β€” deterministic decoder guarantees syntax</li>
282
+ <li><strong>Smaller search space</strong> β€” predicts indices, not full strings</li>
283
+ <li><strong>Interpretable</strong> β€” each component inspectable independently</li>
284
+ </ul>
285
+ </div>
286
+ <div class="arch-card">
287
+ <h3>Encoding Reference</h3>
288
+ <table class="encoding-table">
289
+ <tr><th>Component</th><th>Index</th><th>Meaning</th></tr>
290
+ <tr><td><strong>AGG</strong></td><td class="mono">0</td><td>No aggregation</td></tr>
291
+ <tr><td></td><td class="mono">1</td><td>MAX</td></tr>
292
+ <tr><td></td><td class="mono">2</td><td>MIN</td></tr>
293
+ <tr><td></td><td class="mono">3</td><td>COUNT</td></tr>
294
+ <tr><td></td><td class="mono">4</td><td>SUM</td></tr>
295
+ <tr><td></td><td class="mono">5</td><td>AVG</td></tr>
296
+ <tr><td><strong>OP</strong></td><td class="mono">0</td><td>= (equals)</td></tr>
297
+ <tr><td></td><td class="mono">1</td><td>> (greater than)</td></tr>
298
+ <tr><td></td><td class="mono">2</td><td>< (less than)</td></tr>
299
+ <tr><td></td><td class="mono">3</td><td>>= (greater or equal)</td></tr>
300
+ <tr><td></td><td class="mono">4</td><td><= (less or equal)</td></tr>
301
+ <tr><td></td><td class="mono">5</td><td>!= (not equal)</td></tr>
302
+ </table>
303
+ </div>
304
  """)
305
 
306
+ # ══ TAB 3: MODEL INFO ══
307
  with gr.Tab("Model & Training"):
308
  gr.HTML("""
309
+ <div class="stats-grid">
310
+ <div class="stat-card">
311
+ <div class="stat-value">220M</div>
312
+ <div class="stat-label">Parameters</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  </div>
314
+ <div class="stat-card">
315
+ <div class="stat-value">80K+</div>
316
+ <div class="stat-label">Training Examples</div>
317
+ </div>
318
+ <div class="stat-card">
319
+ <div class="stat-value">T5-base</div>
320
+ <div class="stat-label">Architecture</div>
321
+ </div>
322
+ <div class="stat-card">
323
+ <div class="stat-value">WikiSQL</div>
324
+ <div class="stat-label">Dataset</div>
325
+ </div>
326
+ </div>
327
+ <div class="arch-grid">
328
+ <div class="arch-card">
329
+ <h3>Model</h3>
330
+ <ul style="margin:0.4rem 0;padding-left:1.2rem;">
331
+ <li><strong>Base:</strong> T5-base (encoder-decoder)</li>
332
+ <li><strong>Tokenizer:</strong> SentencePiece (32K vocab)</li>
333
+ <li><strong>Max input:</strong> 512 tokens</li>
334
+ <li><strong>Max output:</strong> 256 tokens</li>
335
+ <li><strong>Decoding:</strong> Beam search (5 beams)</li>
336
+ <li><strong>Framework:</strong> Transformers + PyTorch</li>
337
+ </ul>
338
+ </div>
339
+ <div class="arch-card">
340
+ <h3>Training</h3>
341
+ <ul style="margin:0.4rem 0;padding-left:1.2rem;">
342
+ <li><strong>Dataset:</strong> WikiSQL (Zhong et al., 2017)</li>
343
+ <li><strong>Train:</strong> ~56,355 examples</li>
344
+ <li><strong>Dev:</strong> ~8,421 examples</li>
345
+ <li><strong>Test:</strong> ~15,878 examples</li>
346
+ <li><strong>Output:</strong> Structured tokens (SEL/AGG/CONDS)</li>
347
+ <li><strong>Prefix:</strong> <code>translate to SQL:</code></li>
348
+ </ul>
349
+ </div>
350
+ <div class="arch-card">
351
+ <h3>WikiSQL Dataset</h3>
352
+ <p>80,654 hand-annotated SQL queries across 24,241 Wikipedia tables.
353
+ Single-table queries with SELECT, aggregation, and WHERE conditions.</p>
354
+ <p style="margin-top:0.4rem;"><a href="https://github.com/salesforce/WikiSQL" target="_blank">github.com/salesforce/WikiSQL</a></p>
355
+ </div>
356
+ <div class="arch-card">
357
+ <h3>Limitations</h3>
358
+ <ul style="margin:0.4rem 0;padding-left:1.2rem;">
359
+ <li><strong>Single-table only</strong> β€” no JOINs or subqueries</li>
360
+ <li><strong>Fixed operators</strong> β€” =, >, <, >=, <=, !=</li>
361
+ <li><strong>No GROUP BY / ORDER BY</strong></li>
362
+ <li><strong>AND-only</strong> conditions</li>
363
+ <li><strong>Schema required</strong> as input</li>
364
+ </ul>
365
  </div>
366
  </div>
367
  """)
368
 
 
369
  gr.HTML("""
370
  <div class="app-footer">
371
+ <a href="https://huggingface.co/RealMati/t2sql_v6_structured" target="_blank">Model</a>
 
372
  &nbsp;&bull;&nbsp;
373
+ <a href="https://github.com/salesforce/WikiSQL" target="_blank">WikiSQL</a>
374
  &nbsp;&bull;&nbsp;
375
+ Built with Transformers &amp; Gradio
376
  </div>
377
  """)
378