melihemin commited on
Commit
9c30257
·
verified ·
1 Parent(s): 87784e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -11
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=128,
24
  do_sample=False
25
  )
26
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
27
 
28
- demo = gr.Interface(
29
- fn=text_to_sql,
30
- inputs=gr.Textbox(
31
- lines=4,
32
- placeholder="How many heads of the departments are older than 56?"
33
- ),
34
- outputs="text",
35
- title="Text to SQL Demo",
36
- description="Qwen2.5-0.5B fine-tuned for Text-to-SQL"
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()