Nikhil0987 commited on
Commit
66a7cc5
1 Parent(s): e42d8c4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pandasai.llm.openai import OpenAI
3
+ from dotenv import load_dotenv
4
+ import os
5
+ import pandas as pd
6
+ from pandasai import PandasAI
7
+
8
+ load_dotenv()
9
+
10
+
11
+ openai_api_key = os.getenv("OPENAI_API_KEY")
12
+
13
+
14
+ def chat_with_csv(df,prompt):
15
+ llm = OpenAI(api_token=openai_api_key)
16
+ pandas_ai = PandasAI(llm)
17
+ result = pandas_ai.run(df, prompt=prompt)
18
+ print(result)
19
+ return result
20
+
21
+ st.set_page_config(layout='wide')
22
+
23
+ st.title("ChatCSV powered by LLM")
24
+
25
+ input_csv = st.file_uploader("Upload your CSV file", type=['csv'])
26
+
27
+ if input_csv is not None:
28
+
29
+ col1, col2 = st.columns([1,1])
30
+
31
+ with col1:
32
+ st.info("CSV Uploaded Successfully")
33
+ data = pd.read_csv(input_csv)
34
+ st.dataframe(data, use_container_width=True)
35
+
36
+ with col2:
37
+
38
+ st.info("Chat Below")
39
+
40
+ input_text = st.text_area("Enter your query")
41
+
42
+ if input_text is not None:
43
+ if st.button("Chat with CSV"):
44
+ st.info("Your Query: "+input_text)
45
+ result = chat_with_csv(data, input_text)
46
+ st.success(result)