pandas-ai / app.py
cboettig's picture
and here it goes
defb42e
raw
history blame
1.24 kB
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>
'''