Hi, I have a database called database.db which is in the same folder as the app.py file.
I have already added the data and named the table as “user” using sqlite3 locally and the pushed this database.
But it says the below when I deploy it on Streamlit :
Error: no such table: user
Its weird cause when I tried locally, it works as intended and I am able to get the info.
I have added the secret key:
os.environ["GOOGLE_API_KEY"] = st.secrets.db_credentials.GOOGLE_API_KEY
genai.configure(api_key=st.secrets.db_credentials.GOOGLE_API_KEY)
and to get the value:
if st.button("Submit"):
if question:
# Generate SQL query
sql_query = response_gemini(question, prompt).strip()
st.write("Generated SQL Query:")
st.code(sql_query, language='sql')
# Retrieve and display data
try:
results = sql_retrieve(sql_query, "database.db")
st.write("Query Results:")
if results:
for row in results:
st.write(row)
else:
st.write("No results found.")
except Exception as e:
st.write(f"Error: {e}")
def sql_retrieve(sql, db):
db = sqlite3.connect(db)
cursor = db.cursor()
cursor.execute(sql)
output = cursor.fetchall()
return output