File size: 3,055 Bytes
182219d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import streamlit as st
from streamlit_option_menu import option_menu
from memory import memory_storage
from agent_chain import get_agent_chain
from default_text import default_text4
from generate_plot import generate_plot, retry_generate_plot
from markup import app_intro, how_use_intro
from modules import replace_default_dataset, save_uploaded_dataset
import pandas as pd
import os

if 'error' not in st.session_state:
    st.session_state['error'] = []

def tab1():

    col1, col2 = st.columns([1, 2])
    with col1:
        st.image("image.jpg", use_column_width=True)
    with col2:
        st.markdown(app_intro(), unsafe_allow_html=True)
    st.markdown(how_use_intro(),unsafe_allow_html=True) 

    
    #st.markdown("<p style='font-size: 14px; color: #777;'>Disclaimer: This app is a proof-of-concept and may not be suitable for real-world decisions. During the Hackthon period usage information are being recorded using Langsmith</p>", unsafe_allow_html=True)



def tab2():

    dataset_option = st.radio("Select Dataset Option", ("Default", "Upload"))
    
    if dataset_option == "Default":
        if st.button("Use Default Dataset"):
            replace_default_dataset()
    else:
        uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
        if uploaded_file:
            save_uploaded_dataset(uploaded_file)

    st.header("🗣️ Chat")

    for i, msg in enumerate(memory_storage.messages):
        name = "user" if i % 2 == 0 else "assistant"
        st.chat_message(name).markdown(msg.content)

    if user_input := st.chat_input("User Input"):

        with st.chat_message("user"):
            st.markdown(user_input)

        with st.spinner("Generating Response..."):

            with st.chat_message("assistant"):
                zeroshot_agent_chain = get_agent_chain()
                response = zeroshot_agent_chain({"input": user_input})

                answer = response['output']
                st.markdown(answer)

    
    if st.sidebar.button("Clear Chat History"):
        memory_storage.clear()


def tab4():

    try:
        df = pd.read_csv("dataset.csv")

        st.header("Dataset Content")
        st.dataframe(df)

    except FileNotFoundError:
        st.error("File 'dataset.csv' not found in the current directory.")

    except pd.errors.EmptyDataError:
        st.error("File 'dataset.csv' is empty.")

    except pd.errors.ParserError:
        st.error("File 'dataset.csv' could not be parsed as a CSV file.")

def main():
    st.set_page_config(page_title="NaturalViz", page_icon=":memo:", layout="wide")

    #os.environ['LANGCHAIN_TRACING_V2'] = "true"
    #os.environ['LANGCHAIN_API_KEY'] == st.secrets['LANGCHAIN_API_KEY']

    tabs = ["Intro","Chat", "View Dataset"]

    with st.sidebar:

        current_tab = option_menu("Select a Tab", tabs, menu_icon="cast")

    tab_functions = {
    "Intro": tab1,
    "Chat": tab2,
    "View Dataset": tab4,
    }

    if current_tab in tab_functions:
        tab_functions[current_tab]()

if __name__ == "__main__":
    main()