Says database doesnt exist

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

Can you share a link to the repo? Are the streamlit_app.py and the database.db file both in the repo, and both located in the root of the repo, or are they elsewhere?

Also, can you please edit your post so that it is all in a code block, so that it is readable and testable by others?

Yes both are located in the root. Here is the github repo link: Gen_AI/Text_to_SQL at main · Siddhesh19991/Gen_AI · GitHub

Paths must be relative to the root of the repository.

Do u mean here:

results = sql_retrieve(sql_query, "database.db")

Cause as u can see, the database and python file are in the same folder

Screenshot 2024-06-29 at 11.03.59 AM

I am getting this error in the logs without further explanation too:

[16:09:14] ❗️ We have encountered an unexpected problem. If this issue persists, please contact support

But that folder is not the root of the repository so you need to tell python where to find the file.

Ahh I got it now, I had it inside another folder. Thanks!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.