Skip to content

Commit

Permalink
selectbox for database shema selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jrpereirajr committed Aug 4, 2024
1 parent a696504 commit 2cd8a2c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-streamlit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.9-slim

COPY ./python/sqlzilla /app
COPY ./python/sqlzilla/ /app/

WORKDIR /app

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ services:
context: .
dockerfile: Dockerfile-streamlit
ports:
- 8501:8501
- 8501:8501
volumes:
- ./python/sqlzilla/:/app/
8 changes: 8 additions & 0 deletions python/sqlzilla/.streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# this is needed for local development with docker
[server]
# if you don't want to start the default browser:
headless = true
# you will need this for local development:
runOnSave = true
# you will need this if running docker on windows host:
fileWatcherType = "poll"
25 changes: 24 additions & 1 deletion python/sqlzilla/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
from dotenv import load_dotenv
import os
from sqlalchemy import create_engine
from sqlzilla import SQLZilla

# Load environment variables from .env file
Expand Down Expand Up @@ -73,7 +74,29 @@ def assistant_interaction(sqlzilla, prompt):
st.success("Configuration updated!")

# Initial prompts for namespace and database schema
database_schema = st.text_input('Enter Database Schema')
# database_schema = st.text_input('Enter Database Schema')
try:
connection_string = db_connection_str()
engine = create_engine(connection_string)
cnx = engine.connect().connection
cursor = cnx.cursor()
query = """
SELECT SCHEMA_NAME
FROM INFORMATION_SCHEMA.SCHEMATA
"""
params = []
cursor.execute(query, params)
rows = cursor.fetchall()
options = [row[0] for row in rows or []]
database_schema = st.selectbox(
'Enter Database Schema',
options,
index=None,
placeholder="Select database schema...",
)
except:
database_schema = st.text_input('Enter Database Schema')
st.warning('Was not possible to retrieve database schemas. Please provide it manually.')

if st.session_state.namespace and database_schema and st.session_state.openai_api_key:
sqlzilla = SQLZilla(db_connection_str(), st.session_state.openai_api_key)
Expand Down

0 comments on commit 2cd8a2c

Please sign in to comment.