lpo_ai / app.py
coulibaly-b
llm setting
8758db2
raw
history blame
2.19 kB
import streamlit as st
import hashlib
from AI_generator import SCHEMA_STR, SqlToPlotlyStreamlit
from dashboard import dashboard
from dotenv import load_dotenv
import os
load_dotenv()
username = os.getenv("USERNAME")
password = os.getenv("PASSWORD")
st.sidebar.markdown("""
<footer style="position: fixed; bottom: 0; text-align: center;
background-color: #002b36; border-top: 1px solid #ddd;">
&copy; 2023 LPO. All rights reserved.
</footer>
""", unsafe_allow_html=True)
# Create an authentication function
def authenticate(username, password):
users = {
username: hashlib.sha256(password.encode()).hexdigest()
}
hashed_password = hashlib.sha256(password.encode()).hexdigest()
if username in users and users[username] == hashed_password:
return True
return False
# Create a login form
@st.cache_resource()
def login_cache():
return {"authenticated": False}
def login():
st.title("Login")
form = st.form("login_form")
username = form.text_input("Username")
password = form.text_input("Password", type="password")
if form.form_submit_button("Login"):
if authenticate(username, password):
login_cache()["authenticated"] = True
st.experimental_rerun()
else:
st.error("Invalid username or password")
# Protect your app content
def home():
if not login_cache()["authenticated"]:
login()
else:
# Your app content here
st.title("SQL Query Visualizer")
schema = SCHEMA_STR
question = st.text_input(
"Enter Question:", "what is the total of zones for each category?"
)
if st.button("Run"):
obj = SqlToPlotlyStreamlit(schema, question)
obj.execute_overall_flow()
exec(obj.generated_python_code)
def page2():
if not login_cache()["authenticated"]:
login()
else:
dashboard()
# Run the app
if __name__ == "__main__":
pages = {"AI Generator": home, "Analytic Dashboard": page2}
st.sidebar.markdown("<h2> Select a page </h2>", unsafe_allow_html=True)
page = st.sidebar.selectbox("", list(pages.keys()))
pages[page]()