File size: 1,945 Bytes
192f447
5875608
 
 
192f447
5875608
 
 
 
192f447
5875608
192f447
 
 
5875608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192f447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5875608
 
 
 
 
 
 
 
 
192f447
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
from llm import load_llm, response_generator
from sql import csv_to_sqlite


# repo_id = "Qwen/Qwen2.5-Coder-1.5B-Instruct-GGUF"
repo_id = "Qwen/Qwen2.5-0.5B-Instruct-GGUF"
# filename="qwen2.5-coder-1.5b-instruct-q8_0.gguf"
filename = "qwen2.5-0.5b-instruct-q8_0.gguf"

llm = load_llm(repo_id, filename)

st.title("CSV TO SQL")

with st.expander("Upload CSV"):
    csv_file = st.file_uploader(
        "CSV",
    )
    db_name = st.text_input("DB Name")
    table_name = st.text_input("Table Name")
    if st.button("Save"):
        if csv_file and db_name and table_name:
            st.session_state.db_name = db_name
            st.session_state.table_name = table_name

            csv_to_sqlite(csv_file, db_name, table_name)
            st.write("Saved ✅")
        else:
            st.write("Please enter all values")

# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Accept user input
if prompt := st.chat_input("What is up?"):
    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})
    # Display user message in chat message container
    with st.chat_message("user"):
        st.markdown(prompt)

    # Display assistant response in chat message container
    with st.chat_message("assistant"):
        response = st.write(
            response_generator(
                db_name=st.session_state.db_name,
                table_name=st.session_state.table_name,
                llm=llm,
                messages=st.session_state.messages,
                question=prompt,
            )
        )
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})