Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import streamlit as st
|
|
| 5 |
import google.generativeai as genai
|
| 6 |
import sqlite3
|
| 7 |
import os
|
| 8 |
-
import pyperclip
|
| 9 |
|
| 10 |
|
| 11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
@@ -51,15 +50,6 @@ def read_sql_query(sql,db):
|
|
| 51 |
print(row)
|
| 52 |
return rows
|
| 53 |
|
| 54 |
-
st.set_page_config("DataChat: Explore Your Database")
|
| 55 |
-
st.header("chat with your sql database")
|
| 56 |
-
|
| 57 |
-
table_name = st.text_input("Enter the correct table name")
|
| 58 |
-
|
| 59 |
-
question=st.text_input("enter your input/question")
|
| 60 |
-
|
| 61 |
-
input=f"{question} in {table_name} table"
|
| 62 |
-
|
| 63 |
|
| 64 |
#save uploaded file
|
| 65 |
def save_uploaded_file(uploaded_file):
|
|
@@ -75,13 +65,25 @@ uploaded_file = st.sidebar.file_uploader("Upload SQLite Database", type=["db"])
|
|
| 75 |
if uploaded_file is not None:
|
| 76 |
# Save the uploaded file
|
| 77 |
db_path = save_uploaded_file(uploaded_file)
|
| 78 |
-
st.success("Database uploaded successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
submit=st.button("submit")
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
|
|
|
| 85 |
if submit and uploaded_file and input:
|
| 86 |
query=gemini_sql_query(prompt,input)
|
| 87 |
response=read_sql_query(query,db_path)
|
|
@@ -97,7 +99,7 @@ if submit and uploaded_file and input:
|
|
| 97 |
|
| 98 |
with col2:
|
| 99 |
st.header("Generated SQL Query:")
|
| 100 |
-
st.code(query)
|
| 101 |
|
| 102 |
|
| 103 |
|
|
|
|
| 5 |
import google.generativeai as genai
|
| 6 |
import sqlite3
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
|
|
| 50 |
print(row)
|
| 51 |
return rows
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
#save uploaded file
|
| 55 |
def save_uploaded_file(uploaded_file):
|
|
|
|
| 65 |
if uploaded_file is not None:
|
| 66 |
# Save the uploaded file
|
| 67 |
db_path = save_uploaded_file(uploaded_file)
|
| 68 |
+
st.sidebar.success("Database uploaded successfully.")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
st.set_page_config("DataChat: Explore Your Database")
|
| 73 |
+
st.header("chat with your sql database")
|
| 74 |
+
|
| 75 |
+
table_name = st.text_input("Enter the correct table name")
|
| 76 |
+
|
| 77 |
+
question=st.text_input("enter your input/question")
|
| 78 |
+
|
| 79 |
+
input=f"{question} in {table_name} table"
|
| 80 |
|
| 81 |
submit=st.button("submit")
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
+
|
| 87 |
if submit and uploaded_file and input:
|
| 88 |
query=gemini_sql_query(prompt,input)
|
| 89 |
response=read_sql_query(query,db_path)
|
|
|
|
| 99 |
|
| 100 |
with col2:
|
| 101 |
st.header("Generated SQL Query:")
|
| 102 |
+
st.code(query,height=300)
|
| 103 |
|
| 104 |
|
| 105 |
|