Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
-
from pandasai import
|
5 |
from pandasai.responses.streamlit_response import StreamlitResponse
|
6 |
from langchain_groq import ChatGroq
|
7 |
|
@@ -44,14 +44,14 @@ url = (
|
|
44 |
|
45 |
# Load data only if URL changes
|
46 |
if st.session_state['pre_url'] != url:
|
47 |
-
|
48 |
pd.read_csv(url, index_col=0),
|
49 |
config={
|
50 |
"llm": llm,
|
51 |
"response_parser": StreamlitResponse
|
52 |
}
|
53 |
)
|
54 |
-
st.session_state['
|
55 |
st.session_state['pre_url'] = url
|
56 |
|
57 |
# Step 2: Request for analysis or chart
|
@@ -61,8 +61,8 @@ request = st.text_input(
|
|
61 |
|
62 |
# Execute chat and display results
|
63 |
if st.button("Analyze"):
|
64 |
-
if st.session_state['
|
65 |
-
file = st.session_state['
|
66 |
if os.path.exists(file):
|
67 |
st.image(file)
|
68 |
else:
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
4 |
+
from pandasai import Agent
|
5 |
from pandasai.responses.streamlit_response import StreamlitResponse
|
6 |
from langchain_groq import ChatGroq
|
7 |
|
|
|
44 |
|
45 |
# Load data only if URL changes
|
46 |
if st.session_state['pre_url'] != url:
|
47 |
+
agent = Agent(
|
48 |
pd.read_csv(url, index_col=0),
|
49 |
config={
|
50 |
"llm": llm,
|
51 |
"response_parser": StreamlitResponse
|
52 |
}
|
53 |
)
|
54 |
+
st.session_state['agent'] = agent
|
55 |
st.session_state['pre_url'] = url
|
56 |
|
57 |
# Step 2: Request for analysis or chart
|
|
|
61 |
|
62 |
# Execute chat and display results
|
63 |
if st.button("Analyze"):
|
64 |
+
if st.session_state['agent'] is not None:
|
65 |
+
file = st.session_state['agent'].chat(request)
|
66 |
if os.path.exists(file):
|
67 |
st.image(file)
|
68 |
else:
|