File size: 1,939 Bytes
a312673
0b62f98
 
232ae3b
0b62f98
 
 
 
232ae3b
 
0b62f98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed66cea
0b62f98
 
 
 
 
 
ed66cea
 
 
 
232ae3b
baccc56
13845c1
20edd2c
66e32da
7df306a
 
 
ed66cea
232ae3b
 
 
7df306a
232ae3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import pandas as pd
from ydata_profiling import ProfileReport
import streamlit as st
from streamlit_pandas_profiling import st_profile_report
from langchain.llms.openai import OpenAI
from langchain.agents.agent_types import AgentType
import time

def main():
    st.sidebar.title("App Options")
    option = st.sidebar.selectbox("Choose an option", ["Data Profiling", "Personal Assistant"])

    if option == "Data Profiling":
        data_profiling()
    elif option == "Personal Assistant":
        personal_assistant()

def data_profiling():
    st.title("Data Profiling App")

    # Load the data
    df = pd.read_csv('data.csv')

    # Display the dataframe
    st.dataframe(df)

    # Generate and display the data profile report
    pr = ProfileReport(df, title="Report")
    st_profile_report(pr)

def personal_assistant():
    st.sidebar.title("OpenAI Settings")
    openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key", type="password")

    os.environ['OPENAI_API_KEY'] = openai_api_key

    st.title("Personal Assistant")
    st.text("A BR CREATION")
    st.image("chatbot.jpg", caption="Chatbot", width=178)

    uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
    if uploaded_file is None:
        st.warning("Please upload a CSV file.")
        st.stop()  # Stop execution if no file uploaded

    llm = OpenAI(temperature=0)
    agent = create_csv_agent(
        llm,
        uploaded_file,
        verbose=False,
        agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    )

    query = st.text_input("What would you like to know?")
    if st.button("Ask"):
        if query.strip() == "":
            st.warning("Please enter a query.")
        else:
            start = time.time()
            answer = agent.run(query)
            end = time.time()
            st.write(answer)
            st.write(f"Answer (took {round(end - start, 2)} s.)")

if __name__ == "__main__":
    main()