import streamlit as st from utils.sql_utils import load_data, load_defaultdb_schema_text from utils.handle_sql_commands import execute_sql_duckdb st.markdown( """ """, unsafe_allow_html=True, ) default_dfs = load_data() if "uploaded_dataframes" not in st.session_state: st.session_state.uploaded_dataframes = {} uploaded_dataframes = st.session_state.uploaded_dataframes with st.popover("Click here to see Database Schema", use_container_width=True): uploaded_df_schema = st.session_state.get("uploaded_df_schema", False) choice = st.segmented_control( "Choose", ["Default DB", "Uploaded Files"], label_visibility="collapsed", disabled=uploaded_df_schema == False, default="Default DB" if uploaded_df_schema == False else "Uploaded Files", ) if uploaded_df_schema is False: st.markdown("""> If you want to use your own files(csv/xls), click here - """) st.page_link( page="pages/3 ๐Ÿ“‚File Upload for SQL.py", label="Upload your own CSV or Excel files", icon="๐Ÿ“œ", ) schema = load_defaultdb_schema_text() st.markdown(schema, unsafe_allow_html=True) elif choice == "Default DB": schema = load_defaultdb_schema_text() st.markdown(schema, unsafe_allow_html=True) else: pretty_schema, markdown = st.tabs(["Schema", "Copy Schema in Markdown"]) with pretty_schema: st.info( "You can copy this schema, and give it to any state of the art LLM models like (Gemini /ChatGPT /Claude etc) to cross check your answers.\n You can run the queries directly here, by using ***Manual Query Executer*** in the sidebar and download your results ๐Ÿ˜Š", icon="โ„น๏ธ", ) st.markdown(uploaded_df_schema, unsafe_allow_html=True) with markdown: st.info( "You can copy this schema, and give it to any state of the art LLM models like (Gemini /ChatGPT /Claude etc) to cross check your answers.\n You can run the queries directly here, by using ***Manual Query Executer*** in the sidebar and download your results ๐Ÿ˜Š", icon="โ„น๏ธ", ) st.markdown(f"```\n{uploaded_df_schema}\n```") data_source = None if uploaded_dataframes is None or len(uploaded_dataframes) == 0: data_source = "Default Database" col1, col2 = st.columns([4, 1]) with col1: st.caption( "Use this dialog to execute SQL commands on the Default Database. To use your own Excel/CSV files" ) with col2: st.page_link(page="pages/3 ๐Ÿ“‚File Upload for SQL.py", label="Click Here") else: data_source = st.radio("Select Data Source", ["Default Database", "Uploaded Files"]) if data_source == "Default Database": dataframes = default_dfs if uploaded_dataframes is not None and len(uploaded_dataframes) > 0: st.caption( "Use this dialog to execute SQL commands on the Default Database. To use your own Excel/CSV files" ) else: dataframes = uploaded_dataframes st.caption("Use this dialog to execute SQL commands on Your Uploaded Files") sql_command = st.text_area("Enter your SQL command here:") if st.button("Execute"): df = execute_sql_duckdb(sql_command, dataframes) if df is not None: st.dataframe(df) st.info(f"Rows x Columns: {df.shape[0]} x {df.shape[1]}") st.subheader("Data Description:") st.markdown(df.describe().T.to_markdown()) st.subheader("Data Types:") st.write(df.dtypes) else: st.error( "An error occurred while executing the SQL command. Please cross check your command as well as tables & columns names." )