How to connect user upload database using st.file_uploader?

I am working on LLM app where user will upload database file of type = .db, .sql, .sqlite and make a connection to that file for data retrieval and chat with databases just like accessing contents of PDF by asking Questions.

Currently I am working locally in my system where sample database file in my project directory is working fine. But when I try to upload other database file which is not in my project directory is not working.

For better understanding this my code:

def get_response(question, prompt):
    model = genai.GenerativeModel('gemini-pro')
    response = model.generate_content([prompt, question])
    return response.text


# Function to execute SQL query and return results as DataFrame
def read_sql_query(sql, db):
    conn = sqlite3.connect(db)
    df = pd.read_sql_query(sql, conn)
    conn.close()
    return df

with st.sidebar:
    st.write('<h4 style="color: #ff3333;">Enter your Gemini API key</h4>',
             unsafe_allow_html=True)
    st.session_state.api_key = st.text_input('Enter API Key', type='password', key='st.session_state.api_key',
                                             label_visibility="collapsed")
    if st.session_state.api_key != '':
        user_db = st.file_uploader("Upload your database file ", type=[".sqlite", '.db', '.sql'])

    genai.configure(api_key=st.session_state.api_key)

prompt = st.text_area("Enter a prompt for Model: ", help="Enter the prompt for AI model to interact with your  database file. Basically a role of SQL Expert/Developer.")

col1, col2 = st.columns([6, 1], gap="small", vertical_alignment="bottom")
     with col1:
         question = st.text_input("Input your question here: ", key="input", placeholder="Type here...")
     with col2:
         submit = st.button("Get Data", help="Click to submit your question.", on_click=click_button)

  if submit:
      if question:
          st.session_state.sql_query = get_response(question, prompt)
          try:
              if st.session_state.sql_query:
                  if user_db is not None:
                      st.session_state.df = read_sql_query(st.session_state.sql_query, user_db.name)
                      if st.session_state.df.empty:
                          st.write(
                              """<h4 style="color: #ff3333;">No results found for the given query. Try another 
                              input...!</h4>""",
                              unsafe_allow_html=True)
          except:
              st.error(
                  "Could not extract SQL query from the response. Please try again to retrieve data or change the "
                  "input with respect to database.")
              st.stop()
      else:
          st.error("Please enter a valid Question related to database.")
          st.stop()

Note: App will be hosted on using streamlit or any other hosting services so according how can I approach of using database management.

If anyone have done this approach or already worked on database file upload use case, Please reply with your solution asap?

Any other approaches and Guidance are highly appreciated.