-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathapp.py
47 lines (31 loc) · 1.17 KB
/
app.py
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
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("OPENAI_API_KEY")
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)