pandas-ai icon indicating copy to clipboard operation
pandas-ai copied to clipboard

Streamlit application is not displaying charts in upgraded pandasai version

Open mraguth opened this issue 1 year ago • 9 comments

System Info

pandasai version: 1.5.17 Python: 3.11

This is my llm config:

user_defined_path = os.getcwd()

df = SmartDataframe(pd.DataFrame(gsk), config={"save_charts": True,"save_charts_path": user_defined_path,"llm": llm, "verbose": True, "response_parser": StreamlitResponse})

Now all my charts/visuals are storing in user defined path. It is not displaying in streamlit. I like to see my chart both in streamlit as well as save to the directory. Is it possible?

Thank you for all your help.

🐛 Describe the bug

I am using same config in older versions of pandasai and new. Older versions are displaying plots in streamlit.

mraguth avatar Jan 23 '24 16:01 mraguth

Hi @mraguth ,

I looked into this and was able to replicate the issue.

@gventuri I looked through the code and realized that in StreamlitResponse we don't have any method to plot the charts/images for the latest version. However, if we go back to earlier versions of PandasAI, we can see those instructions are there.

If we update our current code with some of the earlier methods, we can replicate the earlier results. However is there any reason, those functionalities were dropped from the code ?

In case we require these functionalities with suggested changes, let me know, and I'll fix this issue.

dudesparsh avatar Feb 01 '24 06:02 dudesparsh

@gventuri @dudesparsh I find the functionalities that allow us to add images to our PowerPoint presentations on Streamlit very valuable. It was easy to use them before, but now it seems difficult since we have to go to the local drive and get the .png file. I believe that upgrades should make our lives easier, not more complicated. I would appreciate it if we could add those functionalities back if possible. Thank you for your feedback.

mraguth avatar Feb 01 '24 17:02 mraguth

@dudesparsh I believe this is actually a regression. We recently changed the behavior so that we have a unified way to handle the charts. In fact, given that many people are implementing it as part of backend frameworks like "flask" or "fast-api", trying to open the chart doesn't make sense. During the process, however, the streamlit parser might have been broken.

@mraguth you should be able to visualize the chart with st.image(path) in the meanwhile, we'll try to fix the issue asap

gventuri avatar Feb 01 '24 19:02 gventuri

@gventuri Thank you for your feedback and looking forward to.

mraguth avatar Feb 03 '24 05:02 mraguth

Please help with this fix...

thecloudgarage avatar Feb 07 '24 12:02 thecloudgarage

I tested with pandas ai v2, still not working.

DataScientistTX avatar Mar 01 '24 06:03 DataScientistTX

@DataScientistTX please try to use st.image(response), that should work. We're releasing a streamlit repo soon tho, so you'll be able to take inspiration from there!

gventuri avatar Mar 01 '24 06:03 gventuri

For those of us who prefer st.pyplot over st.image, the following alternative solution works for me:

  1. Place a file called matplotlibrc.txt at ~/.matplotlib/, where the file is downloaded from https://matplotlib.org/1.2.1/users/customizing.html#matplotlibrc-sample
  2. Replace backend : GTKAgg in matplotlibrc.txt with echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc, as suggested by https://docs.streamlit.io/develop/api-reference/charts/st.pyplot
  3. Then, to display the last figure generated:
fig_to_plot = plt.gcf()
st.pyplot(fig = fig_to_plot)

where plt denotes matplotlib.pyplot.

(Alternatively, to display all figures generated, just iterate over plt.get_fignums()).

I prefer st.pyplot over st.image only because st.image often crops out lengthy labels.

nehcneb avatar May 16 '24 21:05 nehcneb

Please help with this fix...

wuhuanyan avatar Jun 07 '24 01:06 wuhuanyan