Linh Vuu commited on
Commit
b503afb
1 Parent(s): 4c4bfab

added files

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +47 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .streamlit
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from pandasai import PandasAI
4
+ from pandasai.llm.openai import OpenAI
5
+
6
+ openai_api_key = st.secrets["openai_api_key"]
7
+
8
+ # create an LLM by instantiating OpenAI object, and passing API token
9
+ llm = OpenAI(api_key = openai_api_key)
10
+
11
+ # create PandasAI object, passing the LLM
12
+ pandas_ai = PandasAI(llm)
13
+
14
+ st.title("Prompt-driven data analysis with PandasAI")
15
+
16
+ uploaded_file = st.file_uploader("Upload a CSV file for analysis", type=['csv'])
17
+
18
+ if uploaded_file is not None:
19
+ df = pd.read_csv(uploaded_file)
20
+ st.write(df.head(3))
21
+
22
+ if uploaded_file is not None:
23
+ df = pd.read_csv(uploaded_file)
24
+ st.write(df.head(3))
25
+
26
+ prompt = st.text_area("Enter your prompt:")
27
+
28
+ # Generate output
29
+ if st.button("Generate"):
30
+ if prompt:
31
+ st.write("Generating response...")
32
+ else:
33
+ st.warning("Please enter a prompt.")
34
+
35
+ if uploaded_file is not None:
36
+ df = pd.read_csv(uploaded_file)
37
+ st.write(df.head(3))
38
+ prompt = st.text_area("Enter your prompt:")
39
+
40
+ # Generate output
41
+ if st.button("Generate"):
42
+ if prompt:
43
+ # call pandas_ai.run(), passing dataframe and prompt
44
+ with st.spinner("Generating response..."):
45
+ st.write(pandas_ai.run(df, prompt))
46
+ else:
47
+ st.warning("Please enter a prompt.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ streamlit
3
+ pandasai