feat: add sidebar
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from llm import load_llm, response_generator
|
3 |
from sql import csv_to_sqlite, run_sql_query
|
4 |
|
@@ -13,6 +14,7 @@ llm = load_llm(repo_id, filename)
|
|
13 |
st.title("CSV TO SQL")
|
14 |
st.write("To start, Upload your CSV below π")
|
15 |
if st.button("Example prompt"):
|
|
|
16 |
st.session_state.db_name = "sales"
|
17 |
st.session_state.table_name = "sales"
|
18 |
csv_to_sqlite("./data/sales.csv", "sales", "sales")
|
@@ -42,6 +44,7 @@ with st.expander("Upload CSV"):
|
|
42 |
table_name = st.text_input("Table Name")
|
43 |
if st.button("Save"):
|
44 |
if csv_file and db_name and table_name:
|
|
|
45 |
st.session_state.db_name = db_name
|
46 |
st.session_state.table_name = table_name
|
47 |
|
@@ -58,7 +61,10 @@ if "messages" not in st.session_state:
|
|
58 |
for message in st.session_state.messages:
|
59 |
with st.chat_message(message["role"]):
|
60 |
if "content" in message:
|
61 |
-
|
|
|
|
|
|
|
62 |
if "result" in message:
|
63 |
st.dataframe(message["result"])
|
64 |
|
@@ -84,10 +90,24 @@ if prompt := st.chat_input(
|
|
84 |
messages=st.session_state.messages,
|
85 |
question=prompt,
|
86 |
)
|
87 |
-
response = st.
|
88 |
result = run_sql_query(db_name=st.session_state.db_name, query=response_sql)
|
89 |
st.markdown(result)
|
90 |
st.table(result)
|
91 |
|
92 |
# Add assistant response to chat history
|
93 |
st.session_state.messages.append({"role": "assistant", "content": response_sql})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
from llm import load_llm, response_generator
|
4 |
from sql import csv_to_sqlite, run_sql_query
|
5 |
|
|
|
14 |
st.title("CSV TO SQL")
|
15 |
st.write("To start, Upload your CSV below π")
|
16 |
if st.button("Example prompt"):
|
17 |
+
st.session_state.csv_file = "./data/sales.csv"
|
18 |
st.session_state.db_name = "sales"
|
19 |
st.session_state.table_name = "sales"
|
20 |
csv_to_sqlite("./data/sales.csv", "sales", "sales")
|
|
|
44 |
table_name = st.text_input("Table Name")
|
45 |
if st.button("Save"):
|
46 |
if csv_file and db_name and table_name:
|
47 |
+
st.session_state.csv_file = csv_file
|
48 |
st.session_state.db_name = db_name
|
49 |
st.session_state.table_name = table_name
|
50 |
|
|
|
61 |
for message in st.session_state.messages:
|
62 |
with st.chat_message(message["role"]):
|
63 |
if "content" in message:
|
64 |
+
if message["role"] == "user":
|
65 |
+
st.markdown(message["content"])
|
66 |
+
else:
|
67 |
+
st.code(message["content"])
|
68 |
if "result" in message:
|
69 |
st.dataframe(message["result"])
|
70 |
|
|
|
90 |
messages=st.session_state.messages,
|
91 |
question=prompt,
|
92 |
)
|
93 |
+
response = st.code(response_sql)
|
94 |
result = run_sql_query(db_name=st.session_state.db_name, query=response_sql)
|
95 |
st.markdown(result)
|
96 |
st.table(result)
|
97 |
|
98 |
# Add assistant response to chat history
|
99 |
st.session_state.messages.append({"role": "assistant", "content": response_sql})
|
100 |
+
|
101 |
+
with st.sidebar:
|
102 |
+
st.title("Data Previewer")
|
103 |
+
st.write("You can see you CSV file content here")
|
104 |
+
if (
|
105 |
+
"csv_file" in st.session_state
|
106 |
+
and "db_name" in st.session_state
|
107 |
+
and "table_name" in st.session_state
|
108 |
+
):
|
109 |
+
result = run_sql_query(
|
110 |
+
db_name=st.session_state.db_name,
|
111 |
+
query=f"SELECT * FROM {st.session_state.table_name}",
|
112 |
+
)
|
113 |
+
st.dataframe(result)
|