Spaces:
Runtime error
Runtime error
Upload copy_of_sql_gpt_3_notebook.py
Browse files
copy_of_sql_gpt_3_notebook.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Copy of sql gpt-3-notebook.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1yIUz4HcpR_67B1cM7e-TotZIlqF3IcXl
|
8 |
+
"""
|
9 |
+
|
10 |
+
!pip install openai
|
11 |
+
|
12 |
+
import json
|
13 |
+
import openai
|
14 |
+
|
15 |
+
with open('GPT_SECRET_KEY.json') as f:
|
16 |
+
data = json.load(f)
|
17 |
+
|
18 |
+
openai.api_key = data["API_KEY"]
|
19 |
+
|
20 |
+
from gpt import GPT
|
21 |
+
from gpt import Example
|
22 |
+
|
23 |
+
gpt = GPT(engine="davinci",
|
24 |
+
temperature=0.6,
|
25 |
+
max_tokens=100)
|
26 |
+
|
27 |
+
"""# Adding Examples for GPT Model"""
|
28 |
+
|
29 |
+
gpt.add_example(Example('Fetch unique values of DEPARTMENT from Worker table.',
|
30 |
+
'Select distinct DEPARTMENT from Worker;'))
|
31 |
+
|
32 |
+
gpt.add_example(Example('Print the first three characters of FIRST_NAME from Worker table.',
|
33 |
+
'Select substring(FIRST_NAME,1,3) from Worker;'))
|
34 |
+
|
35 |
+
gpt.add_example(Example("Find the position of the alphabet ('a') in the first name column 'Amitabh' from Worker table.",
|
36 |
+
"Select INSTR(FIRST_NAME, BINARY'a') from Worker where FIRST_NAME = 'Amitabh';"))
|
37 |
+
|
38 |
+
gpt.add_example(Example("Print the FIRST_NAME from Worker table after replacing 'a' with 'A'.",
|
39 |
+
"Select CONCAT(FIRST_NAME, ' ', LAST_NAME) AS 'COMPLETE_NAME' from Worker;"))
|
40 |
+
|
41 |
+
gpt.add_example(Example("Display the second highest salary from the Worker table.",
|
42 |
+
"Select max(Salary) from Worker where Salary not in (Select max(Salary) from Worker);"))
|
43 |
+
|
44 |
+
gpt.add_example(Example("Display the highest salary from the Worker table.",
|
45 |
+
"Select max(Salary) from Worker;"))
|
46 |
+
|
47 |
+
gpt.add_example(Example("Fetch the count of employees working in the department Admin.",
|
48 |
+
"SELECT COUNT(*) FROM worker WHERE DEPARTMENT = 'Admin';"))
|
49 |
+
|
50 |
+
gpt.add_example(Example("Get all details of the Workers whose SALARY lies between 100000 and 500000.",
|
51 |
+
"Select * from Worker where SALARY between 100000 and 500000;"))
|
52 |
+
|
53 |
+
gpt.add_example(Example("Get Salary details of the Workers",
|
54 |
+
"Select Salary from Worker"))
|
55 |
+
|
56 |
+
"""# Example 1"""
|
57 |
+
|
58 |
+
prompt = "Display sum of salaries which are less than 5000 from table."
|
59 |
+
|
60 |
+
output = gpt.submit_request(prompt)
|
61 |
+
|
62 |
+
output.choices[0].text
|
63 |
+
|
64 |
+
"""# Example 2"""
|
65 |
+
|
66 |
+
prompt = "Tell me the count of employees working in the department HR."
|
67 |
+
|
68 |
+
output = gpt.submit_request(prompt)
|
69 |
+
|
70 |
+
output.choices[0].text
|
71 |
+
|
72 |
+
"""# Example 3"""
|
73 |
+
|
74 |
+
prompt = "Get salary details of the Workers whose AGE lies between 25 and 55"
|
75 |
+
|
76 |
+
print(gpt.get_top_reply(prompt))
|
77 |
+
|
78 |
+
prompt = "Get the full name of employee from employee table"
|
79 |
+
|
80 |
+
print(gpt.get_top_reply(prompt))
|
81 |
+
|
82 |
+
pip! install gradio
|
83 |
+
|
84 |
+
!nvidia-smi
|
85 |
+
|
86 |
+
!pip install gradio
|
87 |
+
|