yatchman commited on
Commit
4c9f528
·
verified ·
1 Parent(s): acaf0e6

Upload dism.py

Browse files
Files changed (1) hide show
  1. dism.py +54 -0
dism.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+
4
+ # Download necessary NLTK data
5
+ nltk.download('punkt')
6
+
7
+ # Load the OmniParser model and tokenizer
8
+ model_name = "microsoft/OmniParser"
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
11
+
12
+ # SQLBot function to generate SQL commands
13
+ def generate_sql_with_omnparser(query):
14
+ # Encode the input query
15
+ inputs = tokenizer.encode(query, return_tensors="pt")
16
+
17
+ # Generate SQL command
18
+ outputs = model.generate(inputs, max_length=50)
19
+
20
+ # Decode the generated SQL command
21
+ sql_command = tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+ return sql_command
23
+
24
+ # SQLBot function with personality
25
+ def sqlbot(query):
26
+ gpt_sql_command = generate_sql_with_omnparser(query)
27
+
28
+ # Adding personality to the bot
29
+ if "create table" in query.lower():
30
+ response = f"Alright, rolling up my sleeves to create that table for you! Here it is:\n{gpt_sql_command}"
31
+ elif "select" in query.lower():
32
+ response = f"Got it! Fetching the data you need:\n{gpt_sql_command}"
33
+ elif "show tables" in query.lower():
34
+ response = f"Let me show you all the tables you've got:\n{gpt_sql_command}"
35
+ elif "insert" in query.lower():
36
+ response = f"Great! Adding new records as requested:\n{gpt_sql_command}"
37
+ elif "update" in query.lower():
38
+ response = f"Time to make some updates! Here you go:\n{gpt_sql_command}"
39
+ elif "delete" in query.lower():
40
+ response = f"Okay, we're deleting those records:\n{gpt_sql_command}"
41
+ else:
42
+ response = f"Here's what I found:\n{gpt_sql_command}"
43
+
44
+ return response
45
+
46
+ # Example usage
47
+ user_query = "Create table employees with name age department"
48
+ generated_sql = sqlbot(user_query)
49
+ print(generated_sql)
50
+
51
+ # Another example usage
52
+ user_query = "Insert into users (name, age) values ('Alice', 30)"
53
+ generated_sql = sqlbot(user_query)
54
+ print(generated_sql)