from pandasai.llm.openai import OpenAI
import streamlit as st 
from pandasai import SmartDataframe
import pandas as pd
from pandasai import Agent

OPENAI_API_KEY = "sk-********************************"
llm = OpenAI(api_token=OPENAI_API_KEY)

#st.UI-타이틀 
st.title("Data analysis with PandasAl Agent")

#st.UI-sidebar 데이터 세트로드  
uploaded_file = st.sidebar.file_uploader(
    "upload a CSV file", 
    type=['csv']
)

#st.UI-read & write 
if uploaded_file is not None:
    data = pd.read_csv(uploaded_file)
    st.write(data.head(3))

    agent = Agent(data, config={"llm":llm})
    prompt = st.text_area("Enter your prompt:")
    
    if st.button("Generate"):
        if prompt:
            with st.spinner("Generating response..."):
                st.write(agent.chat(prompt))

스크린샷 2024-06-19 오전 11.28.12.png

스크린샷 2024-06-19 오전 11.26.20.png