Build a Python Web App to chat with your datasets using GenAI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
can I ask for the top 10 customers that got the most amount of frauds in this pandas data frame without learning the pandas idium in this video I'll show you how to ask a question to a pandas data frame from a small web app that you built yourself as a prerequisite we use open a GPT 3.5 as the llm to convert human language to Panda's executable code so make sure you have ready to use API key stored in the open AI API key environment variable download the simulated data set from the rep iable machine learning for credit card fraud detection handbook I'll put a link in the description below the data set is split into daily pickled pandas data frames so in a dedicated data P script I implemented a method to read a pickle file and another one to stack all of the daily files into one Consolidated data frame how can we build a web app to display and query the data frame M TriMet a popular python library to quickly build data web apps in a few lines of code go ahead create a new stream app.py script launch it with the streamlit Run command and your web app should appear in a new browser tab first challenge display a title and explore the fraud data set from the app import the stream Library as St and add a title to your web app by using the St WR method when you save your script streamlet immediately reloads the changes and a title should appear in your browser tab load the data set into a data variable using the load data method we previously created again use the s WR method to display it inside the app s WR will adapt its output depending on what you pass to it let's hide the data frame preview in an expander this is taking too much space there are a lot of streamed widgets and layouts elements outside of the S WR method you'll find more of those inside the streamly documentation okay now how do I query the top 10 customers with the most frauds there are multiple libraries to transform a data frame into a query engine like L change python data frame agent or L index pandas engine for this tutorial we will use a dedicated highlevel library that makes data frame go conversational called pandas AI install pandas AI in your python environment import smart data frame and create one from the initial data set how do we add an interactive text prompt well stream it as a text input widget it displays a text area in your web app and stores the user input back to the script in a python variable s if the query is not empty pass it through the chat method of the smart data frame and pandas AI will work its magic to transform it into pandas code then execute it on the input smart data frame and voila your web data frame query engine is ready to go time for small chitchat with the data get the top 10 customer ID with the largest fraud amount a fraud being text fraud equal one as you can see it works now I wonder can I ask for a plot I I'm I'm curious yeah if you ask to plot something the response from P AI won't be a data frame anymore instead the plot is saved in a temporary file thankfully panaz AI has a plugable response system you can build your own stream L class which uses STD data frame to display the data and SD image to display the plot stored in this temporary file after plugging our new streamlet class into Panda Ai and cleaning the St data frame at end it is now able to correctly display plots and data frames okay for transparency sake I want to learn what pandas code was generated from my query pandas AI also accepts a custom callback which lets you interact with the pandas code as soon as it is generated create a container under the text input widget use it as input to the Callback initialization and ask for a plot again and there you go here's the full code to group by customer ID s by amount and finally plot with M plotly generative AI is Paving new ways for analyst to interact with data it's a good complement to your data exploration skills I'll let you try it out and be part of the next wave of data analyst assisted by Jenny ey I'll see you around bye
Info
Channel: Tech at Worldline
Views: 23,366
Rating: undefined out of 5
Keywords: TechAtWorldline
Id: 30_0j0XYOas
Channel Id: undefined
Length: 4min 22sec (262 seconds)
Published: Thu Nov 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.