Commit
·
3c6562d
1
Parent(s):
b324ca4
Improved frontend and updated readme file
Browse files- README.md +45 -0
- app/app.py +12 -5
README.md
CHANGED
@@ -11,6 +11,20 @@ pinned: false
|
|
11 |
|
12 |
# SQL Chat Assistant
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
## Overview
|
15 |
|
16 |
This project is a Flask-based chat assistant that converts natural language queries into SQL statements using state-of-the-art NLP models. The system leverages Hugging Face transformer models, sentence embedding techniques, and fine-tuning approaches to generate accurate SQL queries for an SQLite database.
|
@@ -66,3 +80,34 @@ $env:FLASK_APP="app.main:app"
|
|
66 |
flask run
|
67 |
```
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# SQL Chat Assistant
|
13 |
|
14 |
+
## Public Testing
|
15 |
+
|
16 |
+
```sh
|
17 |
+
https://huggingface.co/spaces/DevashishNagpal/nlp-to-sql-chat-assistant
|
18 |
+
|
19 |
+
```
|
20 |
+
Please note that this project is still under development, and the model may not work as expected for all queries. Feel free to test it out and provide feedback for improvements.
|
21 |
+
|
22 |
+
Example queries:
|
23 |
+
- "Show me all the employees"
|
24 |
+
- "Show me the employees who are managers"
|
25 |
+
- "Who is the manager of Marketing department?"
|
26 |
+
|
27 |
+
|
28 |
## Overview
|
29 |
|
30 |
This project is a Flask-based chat assistant that converts natural language queries into SQL statements using state-of-the-art NLP models. The system leverages Hugging Face transformer models, sentence embedding techniques, and fine-tuning approaches to generate accurate SQL queries for an SQLite database.
|
|
|
80 |
flask run
|
81 |
```
|
82 |
|
83 |
+
## Models Explored for the Project
|
84 |
+
|
85 |
+
I experimented with multiple models before settling on the fine-tuned t5-small model with ONNX quantization.
|
86 |
+
|
87 |
+
## Models Explored and Rejected
|
88 |
+
|
89 |
+
| Model | Reason for Rejection |
|
90 |
+
|--------------------------------------------|--------------------------------------------------------------------------------------|
|
91 |
+
| mrm8488/t5-base-finetuned-wikiSQL | Produced incorrect table references due to its focus on WikiSQL datasets. |
|
92 |
+
| tscholak/cxmefzzi | Large model size, requiring high computational resources for inference. |
|
93 |
+
| HridaAI/Hrida-T2SQL-3B-V0.2 | Optimized for Spider dataset, failing on custom schemas. |
|
94 |
+
| cssupport/t5-small-awesome-text-to-sql | Limited accuracy without schema-specific fine-tuning. |
|
95 |
+
| hasibzunair/t5-small-spider-sql | Required significant schema customization. |
|
96 |
+
| hkunlp/text2sql-t5-small | Generated incomplete queries. |
|
97 |
+
| szarnyasg/transformer-text2sql | Poor generalization on varied SQL queries. |
|
98 |
+
| jimypbr/gpt2-finetuned-wikitext2 | GPT-2 was not suited for structured SQL generation. |
|
99 |
+
|
100 |
+
## Future Improvements
|
101 |
+
|
102 |
+
- Enhance dataset for fine-tuning.
|
103 |
+
- Implement caching for faster response times.
|
104 |
+
- Deploy the model using Hugging Face Spaces or an optimized cloud server.
|
105 |
+
|
106 |
+
## Author
|
107 |
+
Devashish Nagpal
|
108 |
+
|
109 |
+
### GitHub: github.com/DevashishXO
|
110 |
+
### LinkedIn: linkedin.com/in/devashishnagpal
|
111 |
+
|
112 |
+
## License
|
113 |
+
This project is open-source under the MIT License.
|
app/app.py
CHANGED
@@ -20,12 +20,19 @@ def chatbot(user_query):
|
|
20 |
return "⚠️ No data found."
|
21 |
|
22 |
# Formatting SQL output
|
23 |
-
response = "**Query:**\n
|
24 |
response += "**Result:**\n"
|
25 |
-
response += "
|
26 |
-
response += "-
|
|
|
|
|
|
|
27 |
for row in result['data']:
|
28 |
-
response += "
|
|
|
|
|
|
|
|
|
29 |
return response
|
30 |
|
31 |
except Exception as e:
|
@@ -41,7 +48,7 @@ demo = gr.Interface(
|
|
41 |
)
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, share
|
45 |
|
46 |
|
47 |
|
|
|
20 |
return "⚠️ No data found."
|
21 |
|
22 |
# Formatting SQL output
|
23 |
+
response = f"**Query:**\n```\n{sql}\n```\n\n"
|
24 |
response += "**Result:**\n"
|
25 |
+
response += "<table style='width:100%; border-collapse: collapse;'>"
|
26 |
+
response += "<tr style='background-color: #f2f2f2;'>"
|
27 |
+
for col in result['columns']:
|
28 |
+
response += f"<th style='border: 1px solid #ddd; padding: 8px;'>{col}</th>"
|
29 |
+
response += "</tr>"
|
30 |
for row in result['data']:
|
31 |
+
response += "<tr>"
|
32 |
+
for cell in row:
|
33 |
+
response += f"<td style='border: 1px solid #ddd; padding: 8px;'>{cell}</td>"
|
34 |
+
response += "</tr>"
|
35 |
+
response += "</table>"
|
36 |
return response
|
37 |
|
38 |
except Exception as e:
|
|
|
48 |
)
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
52 |
|
53 |
|
54 |
|