feat: add example
Browse files
app.py
CHANGED
@@ -13,6 +13,28 @@ filename = "Qwen2.5-Coder-7B-Instruct-Q4_K_M.gguf"
|
|
13 |
llm = load_llm(repo_id, filename)
|
14 |
|
15 |
st.title("CSV TO SQL")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
with st.expander("Upload CSV"):
|
18 |
csv_file = st.file_uploader(
|
@@ -37,7 +59,10 @@ if "messages" not in st.session_state:
|
|
37 |
# Display chat messages from history on app rerun
|
38 |
for message in st.session_state.messages:
|
39 |
with st.chat_message(message["role"]):
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
# Accept user input
|
43 |
if prompt := st.chat_input(
|
|
|
13 |
llm = load_llm(repo_id, filename)
|
14 |
|
15 |
st.title("CSV TO SQL")
|
16 |
+
st.write("To start, Upload your CSV below 👇")
|
17 |
+
if st.button("Example prompt"):
|
18 |
+
st.session_state.db_name = "sales"
|
19 |
+
st.session_state.table_name = "sales"
|
20 |
+
csv_to_sqlite("./data/sales.csv", "sales", "sales")
|
21 |
+
|
22 |
+
prompt = "What is the sum, count and average sales?"
|
23 |
+
|
24 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
25 |
+
response_sql = response_generator(
|
26 |
+
db_name=st.session_state.db_name,
|
27 |
+
table_name=st.session_state.table_name,
|
28 |
+
llm=llm,
|
29 |
+
messages=st.session_state.messages,
|
30 |
+
question=prompt,
|
31 |
+
)
|
32 |
+
result = run_sql_query(db_name=st.session_state.db_name, query=response_sql)
|
33 |
+
st.session_state.messages.append({"role": "assistant", "content": response_sql})
|
34 |
+
st.session_state.messages.append(
|
35 |
+
{"role": "assistant", "content": str(result), "result": result}
|
36 |
+
)
|
37 |
+
|
38 |
|
39 |
with st.expander("Upload CSV"):
|
40 |
csv_file = st.file_uploader(
|
|
|
59 |
# Display chat messages from history on app rerun
|
60 |
for message in st.session_state.messages:
|
61 |
with st.chat_message(message["role"]):
|
62 |
+
if "content" in message:
|
63 |
+
st.markdown(message["content"])
|
64 |
+
if "result" in message:
|
65 |
+
st.dataframe(message["result"])
|
66 |
|
67 |
# Accept user input
|
68 |
if prompt := st.chat_input(
|