Update app.py
Browse files
app.py
CHANGED
|
@@ -67,20 +67,28 @@ input=st.text_input("enter your input/question ")
|
|
| 67 |
|
| 68 |
uploaded_file = st.file_uploader("Upload SQLite Database", type=["db"])
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
if uploaded_file is not None:
|
| 71 |
-
# Read the contents of the uploaded database file
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
st.success("Database uploaded successfully.")
|
| 77 |
|
|
|
|
|
|
|
|
|
|
| 78 |
submit=st.button("submit")
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
-
if submit and uploaded_file:
|
| 84 |
query=gemini_sql_query(prompt,input)
|
| 85 |
response=read_sql_query(query,"uploaded.db")
|
| 86 |
print(query)
|
|
@@ -90,7 +98,8 @@ if submit and uploaded_file:
|
|
| 90 |
with col1:
|
| 91 |
st.header("Response:")
|
| 92 |
for row in response:
|
| 93 |
-
|
|
|
|
| 94 |
|
| 95 |
with col2:
|
| 96 |
st.header("Generated SQL Query:")
|
|
@@ -99,12 +108,12 @@ if submit and uploaded_file:
|
|
| 99 |
st.write("SQL query copied to clipboard!")
|
| 100 |
st.text_area("SQL Query:", value=query, height=100)
|
| 101 |
|
| 102 |
-
if submit:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
|
|
|
| 67 |
|
| 68 |
uploaded_file = st.file_uploader("Upload SQLite Database", type=["db"])
|
| 69 |
|
| 70 |
+
connection = sqlite3.connect(":memory:") # Use in-memory database
|
| 71 |
+
cursor = connection.cursor()
|
| 72 |
+
|
| 73 |
if uploaded_file is not None:
|
| 74 |
+
# Read the contents of the uploaded database file in binary mode
|
| 75 |
+
db_content = uploaded_file.read()
|
| 76 |
+
|
| 77 |
+
# Execute the script directly with binary data
|
| 78 |
+
cursor.executescript(db_content)
|
| 79 |
+
|
| 80 |
+
# Display a success message after uploading the database file
|
| 81 |
st.success("Database uploaded successfully.")
|
| 82 |
|
| 83 |
+
# User input for SQL query
|
| 84 |
+
input_text = st.text_input("Enter the query")
|
| 85 |
+
|
| 86 |
submit=st.button("submit")
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
+
if submit and uploaded_file and input:
|
| 92 |
query=gemini_sql_query(prompt,input)
|
| 93 |
response=read_sql_query(query,"uploaded.db")
|
| 94 |
print(query)
|
|
|
|
| 98 |
with col1:
|
| 99 |
st.header("Response:")
|
| 100 |
for row in response:
|
| 101 |
+
values = [str(value) for value in row]
|
| 102 |
+
st.write(*values)
|
| 103 |
|
| 104 |
with col2:
|
| 105 |
st.header("Generated SQL Query:")
|
|
|
|
| 108 |
st.write("SQL query copied to clipboard!")
|
| 109 |
st.text_area("SQL Query:", value=query, height=100)
|
| 110 |
|
| 111 |
+
# if submit:
|
| 112 |
+
# query=gemini_sql_query(prompt,input)
|
| 113 |
+
# response=read_sql_query(query,"student.db")
|
| 114 |
+
# print(query)
|
| 115 |
+
# st.header("response")
|
| 116 |
+
# for row in response:
|
| 117 |
+
# values = [str(value) for value in row]
|
| 118 |
+
# st.write(*values)
|
| 119 |
|