Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
|
2 |
-
import re
|
3 |
import openai
|
|
|
|
|
|
|
4 |
|
5 |
def gpt3(texts):
|
6 |
openai.api_key ="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"
|
@@ -9,77 +11,23 @@ def gpt3(texts):
|
|
9 |
engine="code-davinci-002",
|
10 |
prompt= texts,
|
11 |
temperature=0,
|
12 |
-
max_tokens=
|
13 |
top_p=1,
|
14 |
frequency_penalty=0.0,
|
15 |
presence_penalty=0.0,
|
16 |
-
|
17 |
-
stop = ("conn.close()", "</code>", "#")
|
18 |
)
|
19 |
x = response.choices[0].text
|
20 |
-
|
21 |
-
x = re.sub(r'(cur.execute\(\"|\"\))', '', x)
|
22 |
-
# cut everything off after the first "\n"
|
23 |
-
x = x.split("\n")[0]
|
24 |
return x
|
25 |
|
26 |
|
27 |
|
28 |
-
#using the name of the database, return the table names and the column names
|
29 |
-
|
30 |
-
def print_attributes(database, table):
|
31 |
-
conn = sqlite3.connect(database)
|
32 |
-
c = conn.cursor()
|
33 |
-
c.execute("PRAGMA table_info(" + table + ")")
|
34 |
-
print(c.fetchall())
|
35 |
-
conn.close()
|
36 |
-
|
37 |
-
# if tabes returns ([], []), re do the function and the base input
|
38 |
-
def get_tables():
|
39 |
-
# make the base variable global
|
40 |
-
global base
|
41 |
-
base = input("Name the database to connect to:")
|
42 |
-
if len(base) <5:
|
43 |
-
print("The name is too short")
|
44 |
-
get_tables()
|
45 |
-
#exit clause
|
46 |
-
if base == "exit":
|
47 |
-
return
|
48 |
-
conn = sqlite3.connect(base)
|
49 |
-
c = conn.cursor()
|
50 |
-
c.execute("SELECT name FROM sqlite_master WHERE type='table';")
|
51 |
-
tables = c.fetchall()
|
52 |
-
|
53 |
-
|
54 |
-
conn.close()
|
55 |
-
if tables == [] and columns == []:
|
56 |
-
get_tables()
|
57 |
-
return tables
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
#tables = get_tables()
|
63 |
-
|
64 |
-
#if len(base)==0:
|
65 |
-
# base= "gmaildb.sqlite"
|
66 |
-
|
67 |
-
# turn this: "request=input("What would you like to do to the database?")" into a callable function that repeats itself if too short
|
68 |
-
|
69 |
-
def request():
|
70 |
-
requests=input("What would you like to do to the database?")
|
71 |
-
if len(requests) < 5:
|
72 |
-
print("The request is too short")
|
73 |
-
request()
|
74 |
-
return requests
|
75 |
-
|
76 |
-
import gradio as gr
|
77 |
-
|
78 |
|
79 |
# create a UI using gradio that takes in a text name and a text prompt, which then is displayed back to the user
|
80 |
|
81 |
def greet( prompt):
|
82 |
-
txt= (
|
83 |
sql = gpt3(txt)
|
84 |
return sql
|
85 |
|
@@ -91,17 +39,3 @@ def greet( prompt):
|
|
91 |
iface = gr.Interface(greet, inputs = ["text"], outputs = "text")
|
92 |
iface.launch()
|
93 |
|
94 |
-
|
95 |
-
#breakpoint()
|
96 |
-
#req = request()
|
97 |
-
|
98 |
-
#txt= ("# Python 3 \n# SQLite \n# "+req+ "\nimport sqlite3"+'\nconn = sqlite3.connect("'+ base +'")\ncur = conn.cursor()')
|
99 |
-
#cod = gpt3(txt)
|
100 |
-
|
101 |
-
|
102 |
-
#scrip= (txt+str(cod))
|
103 |
-
#print(scrip)
|
104 |
-
#exec(scrip)
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
1 |
+
|
|
|
2 |
import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
|
7 |
def gpt3(texts):
|
8 |
openai.api_key ="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"
|
|
|
11 |
engine="code-davinci-002",
|
12 |
prompt= texts,
|
13 |
temperature=0,
|
14 |
+
max_tokens=750,
|
15 |
top_p=1,
|
16 |
frequency_penalty=0.0,
|
17 |
presence_penalty=0.0,
|
18 |
+
stop = (";", "/*")
|
|
|
19 |
)
|
20 |
x = response.choices[0].text
|
21 |
+
|
|
|
|
|
|
|
22 |
return x
|
23 |
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# create a UI using gradio that takes in a text name and a text prompt, which then is displayed back to the user
|
28 |
|
29 |
def greet( prompt):
|
30 |
+
txt= (f'''/*Prompt: {prompt}*/ \n --SQL Code:''')
|
31 |
sql = gpt3(txt)
|
32 |
return sql
|
33 |
|
|
|
39 |
iface = gr.Interface(greet, inputs = ["text"], outputs = "text")
|
40 |
iface.launch()
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|