Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,20 +20,72 @@ def text_to_sql(question):
|
|
| 20 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 21 |
outputs = model.generate(
|
| 22 |
**inputs,
|
| 23 |
-
max_new_tokens=
|
| 24 |
do_sample=False
|
| 25 |
)
|
| 26 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
demo.launch()
|
|
|
|
| 20 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 21 |
outputs = model.generate(
|
| 22 |
**inputs,
|
| 23 |
+
max_new_tokens=256,
|
| 24 |
do_sample=False
|
| 25 |
)
|
| 26 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
|
| 28 |
+
def load_example():
|
| 29 |
+
return "How many heads of the departments are older than 56?"
|
| 30 |
+
|
| 31 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 32 |
+
gr.Markdown(
|
| 33 |
+
"""
|
| 34 |
+
# 🧠 Text-to-SQL Demo
|
| 35 |
+
This application converts **natural language questions** into **SQL queries**
|
| 36 |
+
using a fine-tuned **Qwen2.5-0.5B** language model.
|
| 37 |
+
"""
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
with gr.Row():
|
| 41 |
+
with gr.Column(scale=1):
|
| 42 |
+
input_box = gr.Textbox(
|
| 43 |
+
label="📝 Natural Language Question",
|
| 44 |
+
placeholder="Enter your question here...",
|
| 45 |
+
lines=8
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
generate_btn = gr.Button("🚀 Generate SQL", variant="primary")
|
| 49 |
+
|
| 50 |
+
with gr.Column(scale=1):
|
| 51 |
+
output_box = gr.Textbox(
|
| 52 |
+
label="🧾 Generated SQL Query",
|
| 53 |
+
lines=10,
|
| 54 |
+
interactive=False
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
generate_btn.click(
|
| 58 |
+
fn=text_to_sql,
|
| 59 |
+
inputs=input_box,
|
| 60 |
+
outputs=output_box
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
gr.Markdown("---")
|
| 64 |
+
|
| 65 |
+
gr.Markdown(
|
| 66 |
+
"""
|
| 67 |
+
## 📌 Example Usage
|
| 68 |
+
Click the button below to load a sample question and test the model.
|
| 69 |
+
"""
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
example_btn = gr.Button("📎 Load Example Question")
|
| 73 |
+
example_btn.click(
|
| 74 |
+
fn=load_example,
|
| 75 |
+
inputs=None,
|
| 76 |
+
outputs=input_box
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
gr.Markdown(
|
| 80 |
+
"""
|
| 81 |
+
**Example Question:**
|
| 82 |
+
*How many heads of the departments are older than 56?*
|
| 83 |
+
|
| 84 |
+
**Expected SQL Output:**
|
| 85 |
+
```sql
|
| 86 |
+
SELECT count(*) FROM head WHERE age > 56;
|
| 87 |
+
```
|
| 88 |
+
"""
|
| 89 |
+
)
|
| 90 |
|
| 91 |
demo.launch()
|