Spaces:
Sleeping
Sleeping
Linh Vuu
commited on
Commit
·
a9ec8a3
1
Parent(s):
86652f1
added files
Browse files- .DS_Store +0 -0
- app.py +23 -26
- 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
|
| 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(
|
| 10 |
|
| 11 |
-
|
| 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 |
-
|
| 23 |
-
df =
|
| 24 |
-
st.write(df.head(3))
|
| 25 |
|
| 26 |
-
prompt = st.text_area("Enter your
|
| 27 |
|
| 28 |
-
# Generate
|
| 29 |
-
if st.button("
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
-
st.warning("Please enter a
|
|
|
|
| 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 |
-
|
|
|
|
| 1 |
streamlit
|
| 2 |
pandasai
|
| 3 |
+
scikit-learn
|