File size: 1,243 Bytes
defb42e
478171f
defb42e
478171f
defb42e
 
 
478171f
defb42e
 
478171f
defb42e
 
 
478171f
 
 
defb42e
478171f
defb42e
 
 
478171f
defb42e
 
478171f
defb42e
478171f
 
defb42e
 
 
 
 
 
 
 
 
 
 
 
 
478171f
defb42e
478171f
defb42e
478171f
defb42e
 
 
 
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
import os
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from pandasai.llm.openai import OpenAI
from pandasai import Agent
from pandasai.responses.streamlit_response import StreamlitResponse

llm = OpenAI(api_token=st.secrets["OPENAI_API_KEY"])
df1 = pd.read_csv("data.csv")

agent = Agent(
    [df1],
    config={"verbose": True, "response_parser": StreamlitResponse, "llm": llm},
)


st.title("Pandas-AI demo using climate data")

'''
A simple demo based on Mauna Loa CO2 Records.  Ask questions of the data below:
'''

## Dataset
st.dataframe(df1)

## Chatbot


with st.container():
    prompt = st.chat_input("Plot CO2 over time")
    if prompt:
        with st.spinner():
            resp = agent.chat(prompt)
            if os.path.isfile('exports/charts/temp_chart.png'):
                im = plt.imread('exports/charts/temp_chart.png')
                st.image(im)
                os.remove('exports/charts/temp_chart.png')
            st.write(resp)
        
        
st.divider()

'''

[pandas-ai docs](https://docs.pandas-ai.com/intro)

Copyright 2024 [Carl Boettiger](https://carlboettiger.info), UC Berkeley.  
License: BSD2
Data from: <https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.txt>
'''