Parthx10 commited on
Commit
706ed27
·
verified ·
1 Parent(s): df20f58

Upload 3 files

Browse files
Files changed (3) hide show
  1. deme.py +47 -0
  2. requiremnts.txt +4 -0
  3. superstore Creation.sql +56 -0
deme.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from transformers import LLMForConditionalGeneration, LLMTokenizer
4
+ import sqlite3
5
+
6
+ # Load Hugging Face LLM2 model and tokenizer
7
+ model_name = "microsoft/CodeGPT-small-py"
8
+ tokenizer = LLMTokenizer.from_pretrained(model_name)
9
+ model = LLMForConditionalGeneration.from_pretrained(model_name)
10
+
11
+ # Function to generate SQL query
12
+ def generate_sql_query(text):
13
+ input_ids = tokenizer.encode(text, return_tensors="pt")
14
+ outputs = model.generate(input_ids, max_length=100, do_sample=False)
15
+ generated_sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return generated_sql
17
+
18
+ # Function to execute SQL query and retrieve results from the database
19
+ def execute_query(sql_query):
20
+ conn = sqlite3.connect('C:/Users/Chovatiya.Parth/Desktop/SQL/superstore Creation.sql')
21
+ cursor = conn.cursor()
22
+ cursor.execute(sql_query)
23
+ results = cursor.fetchall()
24
+ conn.close()
25
+ return results
26
+
27
+ # Streamlit UI
28
+ def main():
29
+ st.title("SQL Chatbot")
30
+
31
+ user_query = st.text_input("Enter your query:")
32
+
33
+ if st.button("Submit"):
34
+ sql_query = generate_sql_query(user_query)
35
+ st.write("Generated SQL query:", sql_query)
36
+
37
+ try:
38
+ results = execute_query(sql_query)
39
+ st.write("Results from the database:")
40
+ for row in results:
41
+ st.write(row)
42
+ except Exception as e:
43
+ st.error("An error occurred while executing the SQL query.")
44
+ st.error(e)
45
+
46
+ if __name__ == "__main__":
47
+ main()
requiremnts.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ torch==1.10.0
3
+ transformers==4.12.2
4
+ sqlite3
superstore Creation.sql ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ create database super_store;
2
+ use super_store;
3
+
4
+ create table customer(Customer_ID varchar(30) primary key,
5
+ Customer_Name varchar(50),
6
+ Segment varchar(20),
7
+ Country varchar(20),
8
+ City varchar(20),
9
+ State varchar(20),
10
+ Postal_Code int(10),
11
+ Region varchar(20));
12
+ select * from customer;
13
+
14
+ CREATE TABLE super_store.order(
15
+ Order_ID VARCHAR(30) PRIMARY KEY,
16
+ Order_Date DATE,
17
+ Ship_Date DATE,
18
+ Ship_Mode VARCHAR(50)
19
+ );
20
+
21
+ select * from super_store.order;
22
+
23
+
24
+ CREATE TABLE Product (
25
+ Product_ID VARCHAR(30) PRIMARY KEY,
26
+ Category VARCHAR(50),
27
+ Sub_Category VARCHAR(50),
28
+ Product_Name VARCHAR(150)
29
+ );
30
+ select * from Product;
31
+
32
+
33
+ -- Create Returned table with foreign key constraint
34
+ CREATE TABLE Returned (
35
+ Order_ID VARCHAR(30),
36
+ Returned varchar(10),
37
+ PRIMARY KEY (Order_ID),
38
+ FOREIGN KEY (Order_ID) REFERENCES super_store.order(Order_ID)
39
+ );
40
+ select * from returned;
41
+
42
+
43
+ CREATE TABLE Sales (
44
+ Order_ID varchar(30) NOT NULL,
45
+ Customer_ID varchar(30) NOT NULL,
46
+ Product_ID varchar(30) NOT NULL,
47
+ Sales DECIMAL(10,2) NOT NULL,
48
+ Quantity INT NOT NULL,
49
+ Discount DECIMAL(5,2),
50
+ Profit DECIMAL(10,2),
51
+ PRIMARY KEY (Order_ID, Customer_ID, Product_ID),
52
+ FOREIGN KEY (Order_ID) REFERENCES super_store.order(Order_ID),
53
+ FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID),
54
+ FOREIGN KEY (Product_ID) REFERENCES Product(Product_ID)
55
+ );
56
+ select * from sales;