I tried to use pandasai on streamlit to generate chart image, it works well until I show image, the error is
Traceback (most recent call last):
File "/home/adminuser/venv/lib/python3.11/site-packages/pandasai/pipelines/chat/generate_chat_pipeline.py", line 335, in run
).run(input)
^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/pandasai/pipelines/pipeline.py", line 137, in run
raise e
File "/home/adminuser/venv/lib/python3.11/site-packages/pandasai/pipelines/pipeline.py", line 101, in run
step_output = logic.execute(
^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/pandasai/pipelines/chat/code_execution.py", line 133, in execute
{"content_type": "response", "value": ResponseSerializer.serialize(result)},
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/pandasai/responses/response_serializer.py", line 35, in serialize
with open(result["value"], "rb") as image_file:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/mount/src/final_project_data_visualization/exports/27e8e5b4-b5f1-4768-a92e-384ff64f1c33.png'
I realized image first stored (because I can see its name 27e8e5b4-b5f1-4768-a92e-384ff64f1c33.png’) then it disappear with no reason
Bellow is my code
export_folder = os.path.join(os.getcwd(), "exports")
sdf = SmartDataframe(data, config={"save_charts": True, "save_charts_path": export_folder, "verbose": True, "response_parser": StreamlitResponse, "custom_whitelisted_dependencies": ["to_numeric"]})
with st.container():
# File uploader widget to upload a CSV file
config_file = st.file_uploader("Upload your config file", type=["json"])
images = []
if 'Send_button' not in st.session_state:
st.session_state.send_button = False
if st.button("Send"):
st.session_state.send_button = True
if st.session_state.send_button and config_file is not None:
# Open and read the JSON file
data = json.load(config_file)
report_name = data["Report Name"]
reporter_name = data["Reporter Name"]
graph_lists_name = data['Graphs']
colors = data["Colors"]
# Clear export folder before generating images
for file in os.listdir(export_folder):
file_path = os.path.join(export_folder, file)
if os.path.isfile(file_path) and file.lower().endswith(('.png', '.jpg', '.jpeg')):
os.remove(file_path)
for index, graph in enumerate(graph_lists_name):
translated_graph_name = translator.translate(graph)
translated_input = "Draw " + translated_graph_name + "with matplotlib and seaborn"
response = sdf.chat(translated_input)
image_files = [f for f in os.listdir(export_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
if image_files:
image_path = os.path.join(export_folder, image_files[0])
st.Image(image_path)
images.append(Image.open(image_path))
for image in images:
st.Image(image)
st.session_state.send_button = False