File size: 1,580 Bytes
060a68f
 
 
 
 
 
8fe5fe5
 
060a68f
 
 
 
8fe5fe5
 
 
 
060a68f
 
 
 
 
 
 
8fe5fe5
060a68f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain.callbacks import StreamlitCallbackHandler
import streamlit as st
from pandas import DataFrame

from pedalo.main import run
import pandas as pd
import os
import openai

# st.set_page_config(layout="wide")
st.title("PEDALO - Productive Exploratory Data Analysis using Langchain interrOgation")
st.write("Ask your data what you wanna know!")
if "OPENAI_API_KEY" in os.environ:
    openai_api_key = os.environ.get("OPENAI_API_KEY")
else:
    openai_api_key = st.sidebar.text_input("OPENAI_API_KEY")
model = st.sidebar.radio("Which model do you wanna use?", ("gpt-4", "gpt-3.5-turbo"), index=1)
uploaded_file = st.sidebar.file_uploader("Choose a file", type=["csv"])



def run_df_analysis(prompt:str, df: DataFrame):
    st_callback = StreamlitCallbackHandler(st.container())
    response = run(prompt, df, st_callback, openai_api_key, model)
    st.write(response)


def initial_analysis(df: DataFrame):
    run_df_analysis("Give a brief outline and interpretation of the file content.", df)


def user_interrogation(df: DataFrame):
    user_question = st.text_input("or enter your question about the CSV data:")
    if user_question:
        run_df_analysis(user_question, df)


def main():
    if uploaded_file is not None:
        df = pd.read_csv(uploaded_file)
        st.write(df)

        # if st.button("Start analyzing"):
        st.write(f"Starting to analyze using model {model}...")
        if st.button("Give initial insight"):
            initial_analysis(df)
        user_interrogation(df)
    else:
        st.write("Please upload a CSV file.")

main()