Linh Vuu commited on
Commit
a9ec8a3
1 Parent(s): 86652f1

added files

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. app.py +23 -26
  3. requirements.txt +1 -1
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -1,17 +1,14 @@
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
 
@@ -19,29 +16,29 @@ 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.")
 
1
  import streamlit as st
2
  import pandas as pd
3
+ from pandasai import SmartDataframe
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_token = openai_api_key)
10
 
11
+ st.title("Data analysis with PandasAI")
 
 
 
12
 
13
  uploaded_file = st.file_uploader("Upload a CSV file for analysis", type=['csv'])
14
 
 
16
  df = pd.read_csv(uploaded_file)
17
  st.write(df.head(3))
18
 
19
+ # create PandasAI object, passing the LLM
20
+ sdf = SmartDataframe(df, config={"llm": llm})
 
21
 
22
+ prompt = st.text_area("Enter your question:")
23
 
24
+ # Generate the answer
25
+ if st.button("Find the answer"):
 
 
 
 
 
 
 
 
 
 
 
 
26
  if prompt:
27
  # call pandas_ai.run(), passing dataframe and prompt
28
  with st.spinner("Generating response..."):
29
+
30
+ st.write("The answer is: ")
31
+ st.write(sdf.chat(prompt))
32
+
33
+ st.write("Here is the code to get the answer: ")
34
+ code_string = sdf.last_code_generated
35
+
36
+ # Split the string into separate lines
37
+ code_lines = code_string.strip().split('\n')
38
+
39
+ # Print the lines
40
+ for line in code_lines:
41
+ st.write(line)
42
+
43
  else:
44
+ st.warning("Please enter a question.")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
  streamlit
2
  pandasai
3
- pydantic
 
1
  streamlit
2
  pandasai
3
+ scikit-learn