Update app.py
Browse files
app.py
CHANGED
@@ -8,27 +8,7 @@ import os
|
|
8 |
|
9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
10 |
model=genai.GenerativeModel('gemini-pro')
|
11 |
-
|
12 |
-
|
13 |
-
#dun to retrieve query from the sql database
|
14 |
-
|
15 |
-
def read_sql_query(sql,db):
|
16 |
-
conn=sqlite3.connect(db)
|
17 |
-
cursor=conn.cursor()
|
18 |
-
cursor.execute(sql)
|
19 |
-
rows=cursor.fetchall()
|
20 |
-
conn.commit()
|
21 |
-
conn.close()
|
22 |
-
|
23 |
-
for row in rows:
|
24 |
-
print(row)
|
25 |
-
return rows
|
26 |
-
|
27 |
-
# prompt="""
|
28 |
-
# you are a professinal sql query expert, i will provide input what i want from database
|
29 |
-
# ,you give me the query without quotes are comma or " " double quotes or ```, just give me query
|
30 |
-
# """
|
31 |
-
|
32 |
|
33 |
prompt=[
|
34 |
"""
|
@@ -49,23 +29,34 @@ prompt=[
|
|
49 |
also the sql code should not have ``` in beginning or end and sql word in output and
|
50 |
|
51 |
"""
|
52 |
-
|
53 |
-
|
54 |
]
|
55 |
|
56 |
-
|
57 |
|
|
|
58 |
def gemini_sql_query(prompt,input):
|
59 |
response=model.generate_content([prompt[0],input])
|
60 |
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
|
63 |
st.set_page_config("DataChat: Explore Your Database")
|
64 |
st.header("chat with your sql database")
|
65 |
|
66 |
-
input=st.text_input("enter your input/question ")
|
67 |
|
68 |
-
|
|
|
69 |
def save_uploaded_file(uploaded_file):
|
70 |
file_path = os.path.join(os.getcwd(), "uploaded.db")
|
71 |
with open(file_path, "wb") as f:
|
@@ -104,13 +95,4 @@ if submit and uploaded_file and input:
|
|
104 |
if st.button("Copy SQL Query"):
|
105 |
st.write("SQL query copied to clipboard!")
|
106 |
st.text_area("SQL Query:", value=query, height=100)
|
107 |
-
|
108 |
-
# if submit:
|
109 |
-
# query=gemini_sql_query(prompt,input)
|
110 |
-
# response=read_sql_query(query,"student.db")
|
111 |
-
# print(query)
|
112 |
-
# st.header("response")
|
113 |
-
# for row in response:
|
114 |
-
# values = [str(value) for value in row]
|
115 |
-
# st.write(*values)
|
116 |
-
|
|
|
8 |
|
9 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
10 |
model=genai.GenerativeModel('gemini-pro')
|
11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
prompt=[
|
14 |
"""
|
|
|
29 |
also the sql code should not have ``` in beginning or end and sql word in output and
|
30 |
|
31 |
"""
|
|
|
|
|
32 |
]
|
33 |
|
|
|
34 |
|
35 |
+
#llm response
|
36 |
def gemini_sql_query(prompt,input):
|
37 |
response=model.generate_content([prompt[0],input])
|
38 |
return response.text
|
39 |
+
|
40 |
+
#dun to retrieve query from the sql database
|
41 |
+
def read_sql_query(sql,db):
|
42 |
+
conn=sqlite3.connect(db)
|
43 |
+
cursor=conn.cursor()
|
44 |
+
cursor.execute(sql)
|
45 |
+
rows=cursor.fetchall()
|
46 |
+
conn.commit()
|
47 |
+
conn.close()
|
48 |
+
for row in rows:
|
49 |
+
print(row)
|
50 |
+
return rows
|
51 |
|
52 |
|
53 |
st.set_page_config("DataChat: Explore Your Database")
|
54 |
st.header("chat with your sql database")
|
55 |
|
56 |
+
input=st.text_input("enter your input/question and specify correct table name")
|
57 |
|
58 |
+
|
59 |
+
#save uploaded file
|
60 |
def save_uploaded_file(uploaded_file):
|
61 |
file_path = os.path.join(os.getcwd(), "uploaded.db")
|
62 |
with open(file_path, "wb") as f:
|
|
|
95 |
if st.button("Copy SQL Query"):
|
96 |
st.write("SQL query copied to clipboard!")
|
97 |
st.text_area("SQL Query:", value=query, height=100)
|
98 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|