I am making a chat with CSV chatbot where we can upload a csv and talk with it it works okay in chat secanrios but when I ask it to plot a graph it doesn’t show the plot on the GUI
Steps to reproduce
Code snippet:
agent = create_pandas_dataframe_agent(
OpenAI(temperature=0), df , verbose=True, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors=True, memory=memory)
st.success('Done!')
if prompt := st.chat_input("Ask a question about your CSV: "):
# st.chat_message("user").write(prompt)
# # Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt})
# # Display user message in chat message container
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
st_callback = StreamlitCallbackHandler(st.container())
response = agent.run(prompt, callbacks=[st_callback])
st.session_state.messages.append({"role": "assistant", "content": response})
st.write(response)
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
SO when I ask a question for exaple plot a histogram it doesn’t show the hisogram on the GUI in my browser, I know i can use st.pyplot but I want to have the output in a chat window like chatgpt
Actual behavior:
Instead the output is shown as “A histogram of the year column is plotted.”
Debug info
Streamlit version: streamlit==1.26.0
Python version: 3.11
Using Virtual env
OS version: Mac OS
Browser version: CHrome
Additional information
If needed, add any other context about the problem here.
Looks like you are trying to display chat messages in a chat format but this package does not support displaying plots inside chat messages, you can use st.plotly_chart outside the chat message container, below the chat input widget or you can use st.chat_message
without the streamlit_chat package, and insert any streamlit element into the returned container using with notation
I am looking for something where when I ask a question suppose “Plot a chart of certain column” then I want the reply from the assistant to be a “Chart/vis of that column”.
I think somewhere you need to implement streamlit plot functionalities. Agents, under the hood solving the data frame operations. but no where they incorporate streamlit plotting functionality . However PandasAI library does that by including streamlit functionalities in form of middleware (if I’m not wrong!)
here’s an example you can try out for testing, but for this one needs to ensure that the initialised data frame is assigned as “df” ( also, you need to add conditional plots - which is not at all elegant way to do )
if "bar" in response_dict:
data = response_dict["bar"]
try:
df_data = {
col: [x[i] if isinstance(x, list) else x for x in data["data"]]
for i, col in enumerate(data["columns"])
}
df = pd.DataFrame(df_data)
if "Products" in df.columns:
df.set_index("Products", inplace=True)
st.bar_chart(df)
except ValueError:
print(f"Couldn't create DataFrame from data: {data}")
I would rather take an alternative approach in solving it by just implementing own prompts and executing fruther. ( drawing inspiration from PandasAI ) . Here’s one of the app I built and demonstrated -
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.