Nikhil0987's picture
Update app.py
4d8a920 verified
import streamlit as st
from pandasai.llm.openai import OpenAI
from dotenv import load_dotenv
import os
import pandas as pd
from pandasai import PandasAI
load_dotenv()
openai_api_key = os.getenv("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")
def chat_with_csv(df,prompt):
llm = OpenAI(api_token=openai_api_key)
pandas_ai = PandasAI(llm)
result = pandas_ai.run(df, prompt=prompt)
print(result)
return result
st.set_page_config(layout='wide')
st.title("ChatCSV powered by LLM")
input_csv = st.file_uploader("Upload your CSV file", type=['csv'])
if input_csv is not None:
col1, col2 = st.columns([1,1])
with col1:
st.info("CSV Uploaded Successfully")
data = pd.read_csv(input_csv)
st.dataframe(data, use_container_width=True)
with col2:
st.info("Chat Below")
input_text = st.text_area("Enter your query")
if input_text is not None:
if st.button("Chat with CSV"):
st.info("Your Query: "+input_text)
result = chat_with_csv(data, input_text)
st.success(result)