PandasAI, OpenAI and Streamlit - Analyzing File Uploads with User Prompts

preview_player
Показать описание
In this video, we'll use Streamlit to build a small UI that allows users to upload a file of CSV data, and will create a text input and buttons that allow users to submit a prompt that can then be used to analyze and interrogate the data.

The prompt will be passed to the PandasAI library, which will take care of sending that prompt along with the data to OpenAI for analysis via their LLMs.

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
01:58 Loading API Key with python-dotenv
02:58 Building a UI with Streamlit
09:42 Using PandasAI and OpenAI to respond to user prompt
16:03 Generating Matplotlib Charts with PandasAI

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#python #llm #pandas #artificialintelligence #datascience #streamlit
Рекомендации по теме
Комментарии
Автор

I was actually going to ask how to display graphs on the web before i finished the video, but i did manage to figure it out on my own. You have to set PandasAI(llm, save_charts=True), then have code in the display anser logic that detects if the number of files in the folder where the images are stored changes, and display the latest image. You would need to do something else like checking for the specific filenames if you had concurrent users in your app but for now it's enough.

answer=pandas_ai.run(st.session_state.df, question)
if

st.write(answer)
list_of_files =
st.write(list_of_files)
latest_file = max(list_of_files, key=os.path.getctime)
st.image(latest_file)
else:
st.write(answer)

lcdhzxp
Автор

This is awesome. Have never heard of streamlit before and my mind is racing with what I can do with this on top of Pandas and ChatGPT

shuntera
Автор

Great resource would love more content relating to deploying Open AI ML solutions on streamlit

pereganranwei
Автор

This was really good. Would certainly be keen to know how to extend the functionality of this - for example, allow other users to input their own Open AI keys. Would also like to see how this is done in Flask too.

danquixote
Автор

thank you! I had this idea in my head and found this video on youtube!

zac
Автор

Great! Very well done. I don't see the project in the GitHub repo.

roberthuff
Автор

Well explained and straight to the point, thanks so much for your video.

techitint.
Автор

Hi,
Thanks for the amazing video. I tried very hard to give you an answer while asking ChatGPT for help.
The issue I see and ChatGPT 4 acknowledges too, is that the answer provided by chatgpt is not in the format that one can use to display the graph within the streamlit directly. Maybe you need to add a check condition if the data is plottable then use st.pyplot() ?
Below is the code snippet for displaying charts using streamlit in the browswer.
---
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Create a random DataFrame for demonstration
df = pd.DataFrame({
'A': np.random.rand(50),
'B': np.random.rand(50) + 1
})

# Create a figure and axes
fig, ax = plt.subplots(figsize=(10, 5))

# Plot a bar chart using the DataFrame
ax.bar(df.index, df['A'], label='A')
ax.bar(df.index, df['B'], bottom=df['A'], label='B')

ax.legend(loc='upper left')
ax.set_title("Bar Chart")
ax.set_xlabel("Index")
ax.set_ylabel("Value")

# Display the chart with Streamlit
st.pyplot(fig)

mocanada
Автор

Amazing content! 🦾 As a 'not developer' that is just starting with Python and OpenAI for work, this video was so helpful, i really apreciate it!
In order to ad a new text_area for a new prompt, related to the last PandasAI response, which would be the next code lines i should use to achieve this?

rodrigokitsuro
Автор

Great tutorial, can you show us how to do this with a offline LLM Model where the data is private and processed locally.

SANJIVRAI
Автор

Can you please help me where I can upload multiple excel or csv files and ai agent will correlate between them in order to give output

PratikBhande-qqht
Автор

Great video!! Have you found any updated way or easier to run Pandas AI to analyze data? Many thanks in advance!

WhySoBroke
Автор

What version of pandas ai did you use, because i keep getting a error when using from pandas import pandasia

premmanu
Автор

hi @BugBytes, i have this error when i try to upload the file: "AxiosError: Request failed with status code 403" and i put correctly the API-keyand the libs, any idea?

ciprianchamps
Автор

Hello BugBytes, can you create a video instead of connecting to open AI you use open source llms? That could be great thank you.

evansmwakughu
Автор

For Generating Charts,we can make a tricky:
llm = OpenAI()
df = SmartDataframe(df, config={"llm": llm})
df.chat('Plot the histogram of countries showing for each the gdp')
from PIL import Image
image =
st.image(image, caption='')


'exports/charts/temp_chart.png', this can be found from

glory_vn
Автор

On pandasai Github page under security the guy has given some info if you want to keep your data privacy. I think one can use that..

vashisht
Автор

Hi...Getting below error while running the app

ImportError: cannot import name ‘PandasAI’ from ‘pandasai’ (C:\Users\RONALD

JiteshPatil
Автор

Bloody brilliant! Is it trivial to scale this to 'read' a pdf with multiple tables and converting the tables into csvs? I am thinking of a use case where the user uploads a pdf of financial statements? Have you try your example using st.session_state? And conversation buffer memory or does this not work with pandasai?

jpcam
Автор

Thank you so much for the help! I was not able to get it to work on streamlit cloud though only locally any info there? I would truly appreciate it

mohammedabdelgalil