Spaces:
Sleeping
Sleeping
“Raj” commited on
Commit ·
cfda861
1
Parent(s): bea9198
Deploy text-to-SQL demo app
Browse files- Gradio interface for SQL generation
- Loads model from HuggingFace Hub
- Includes example queries
- app.py +9 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -8,6 +8,7 @@ and generates PostgreSQL queries from natural language questions.
|
|
| 8 |
import spaces
|
| 9 |
import gradio as gr
|
| 10 |
import torch
|
|
|
|
| 11 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 12 |
from peft import PeftModel
|
| 13 |
|
|
@@ -132,6 +133,14 @@ Generate only the SQL query without any explanation. [/INST]"""
|
|
| 132 |
sql = sql.split("</s>")[0].strip()
|
| 133 |
sql = sql.split("[INST]")[0].strip()
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
print(f"[DEBUG] Generated SQL: {sql[:100]}...")
|
| 136 |
return sql
|
| 137 |
|
|
|
|
| 8 |
import spaces
|
| 9 |
import gradio as gr
|
| 10 |
import torch
|
| 11 |
+
import sqlparse
|
| 12 |
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 13 |
from peft import PeftModel
|
| 14 |
|
|
|
|
| 133 |
sql = sql.split("</s>")[0].strip()
|
| 134 |
sql = sql.split("[INST]")[0].strip()
|
| 135 |
|
| 136 |
+
# Format SQL for better readability
|
| 137 |
+
sql = sqlparse.format(
|
| 138 |
+
sql,
|
| 139 |
+
reindent=True,
|
| 140 |
+
keyword_case='upper',
|
| 141 |
+
indent_width=2
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
print(f"[DEBUG] Generated SQL: {sql[:100]}...")
|
| 145 |
return sql
|
| 146 |
|
requirements.txt
CHANGED
|
@@ -6,3 +6,4 @@ gradio==4.44.1
|
|
| 6 |
torch>=2.0.0
|
| 7 |
sentencepiece>=0.1.99
|
| 8 |
protobuf>=3.20.0
|
|
|
|
|
|
| 6 |
torch>=2.0.0
|
| 7 |
sentencepiece>=0.1.99
|
| 8 |
protobuf>=3.20.0
|
| 9 |
+
sqlparse>=0.5.0
|