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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 มิ.ย. 2024
  • 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.
    Blog post: bugbytes.io/posts/streamlit-p...
    ☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
    To support the channel and encourage new videos, please consider buying me a coffee here:
    ko-fi.com/bugbytes
    📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
    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
    𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
    📖 Blog: bugbytes.io/posts/streamlit-p...
    👾 Github: github.com/bugbytes-io/
    🐦 Twitter: / bugbytesio
    📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
    Blog post: bugbytes.io/posts/streamlit-p...
    Streamlit: docs.streamlit.io/
    PandasAI: github.com/gventuri/pandas-ai
    Titanic Data: github.com/datasciencedojo/da...
    python-dotenv: pypi.org/project/python-dotenv/
    #python #llm #pandas #artificialintelligence #datascience #streamlit

ความคิดเห็น • 91

  • @user-lc2dh6zx5p
    @user-lc2dh6zx5p ปีที่แล้ว +8

    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.session_state.count

  • @graczew
    @graczew ปีที่แล้ว +2

    Good stuff as always. 👍👍👍

  • @pereganranwei2153
    @pereganranwei2153 ปีที่แล้ว +2

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

  • @shuntera
    @shuntera ปีที่แล้ว +3

    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

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว

      Thanks! Lots of possibilities with Streamlit and these other tools.

  • @techitint.9100
    @techitint.9100 2 หลายเดือนก่อน

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

  • @zac1427
    @zac1427 ปีที่แล้ว +2

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

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      You're welcome! Thanks for watching.

  • @TheLbachtschin
    @TheLbachtschin ปีที่แล้ว +1

    Great job! Thanks!!

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว

      You're welcome - thank you for watching!

  • @Ego_Maritm
    @Ego_Maritm ปีที่แล้ว +1

    Great Job bro💪

  • @roberthuff3122
    @roberthuff3122 ปีที่แล้ว +3

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

  • @danquixote6072
    @danquixote6072 ปีที่แล้ว +2

    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.

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      Thanks! Some good ideas there.

  • @gustavomonne4921
    @gustavomonne4921 ปีที่แล้ว +1

    Awseme video, thanks

  • @onnot701
    @onnot701 ปีที่แล้ว +1

    this is great!

  • @SOHAILKHAN-iu8fu
    @SOHAILKHAN-iu8fu ปีที่แล้ว +1

    One of the best channel on youtube

  • @jpcam4781
    @jpcam4781 10 หลายเดือนก่อน

    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?

  • @SANJIVRAI6693
    @SANJIVRAI6693 ปีที่แล้ว +1

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

  • @WhySoBroke
    @WhySoBroke 3 หลายเดือนก่อน

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

  • @mohammedabdelgalil5860
    @mohammedabdelgalil5860 11 หลายเดือนก่อน

    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

  • @rodrigokitsuro5753
    @rodrigokitsuro5753 ปีที่แล้ว +1

    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?

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      Thank you Rodrigo! Glad it was helpful.
      Given the response, you could store that in a variable, and use the response as part of the prompt for the next call to pandas_ai.run().
      The rest of the prompt can be constructed with another text_area from Streamlit.
      There's also a helpful library called "langchain" that's good for building apps with multiple calls to LLMs. Not sure at the moment how well it integrates with PandasAI, but I'll do a video on langchain soon too.
      Thanks again!

    • @rodrigokitsuro5753
      @rodrigokitsuro5753 ปีที่แล้ว

      @@bugbytes3923 Thank you a lot again!! I'll be waiting this video! 🙌

  • @ciprianchamps
    @ciprianchamps ปีที่แล้ว +1

    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?

  • @Diana-zo2ut
    @Diana-zo2ut หลายเดือนก่อน

    Thanks, Can we do this with images?

  • @mocanada304
    @mocanada304 ปีที่แล้ว +3

    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)

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว

      Thanks! And yeah, good idea! I'll have a play around with it, and see if I can get it working.

    • @ordaflash
      @ordaflash 8 หลายเดือนก่อน +1

      please can you give some more details about your solution ?
      i cannot handle how from the response generated, we could print it as a plot
      in the example you have given, you creates a new chart. but in our case we need to display the chart generated by the AI no ?
      Thank you !

  • @PratikBhande-qq1ht
    @PratikBhande-qq1ht 5 วันที่ผ่านมา

    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

  • @EmptyNonsens
    @EmptyNonsens ปีที่แล้ว

    Private LLM tut would be amazing

  • @anupgeorge2261
    @anupgeorge2261 7 หลายเดือนก่อน

    Super

    • @bugbytes3923
      @bugbytes3923  7 หลายเดือนก่อน

      Thanks a lot!

  • @Ashmanpan
    @Ashmanpan 5 หลายเดือนก่อน

    Possible to do pandasAi with opensourse models?

  • @SuperLiberty2008
    @SuperLiberty2008 9 หลายเดือนก่อน

    how to set up function description? you have pop-up clue for every function

  • @visheshgupta2048
    @visheshgupta2048 ปีที่แล้ว +1

    That is Awesome, I also created something similar, but I was wondering if we can plot this visualization inside the streamlit application instead of separately. Is there any other way ?

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      Thanks! Not found a way to do this yet, but I'm sure it's possible.

    • @visheshgupta2048
      @visheshgupta2048 ปีที่แล้ว

      @@bugbytes3923 okay thanks for your reply

    • @binoyxbabu
      @binoyxbabu 8 หลายเดือนก่อน +1

      ​@@bugbytes3923could you pls find that way and do another video or comment here...that wil be awesome

    • @binoyxbabu
      @binoyxbabu 6 หลายเดือนก่อน

      I have found it and it worked well (use pyplot figure method)

  • @evansmwakughu8562
    @evansmwakughu8562 3 หลายเดือนก่อน

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

  • @yenaung7643
    @yenaung7643 24 วันที่ผ่านมา

    Which pandasai version do you use?

  • @vashisht1
    @vashisht1 11 หลายเดือนก่อน

    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..

  • @RedCloudServices
    @RedCloudServices ปีที่แล้ว +1

    I built a streamlit app with a Folium map can you make a video which interacts with a Folium map? that would be an interesting use case.

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      Good idea! Will look into that one.

  • @vinaysr6617
    @vinaysr6617 3 หลายเดือนก่อน +1

    Some of these have been revised. PadasAI is imported as smartdataframe

    • @bugbytes3923
      @bugbytes3923  3 หลายเดือนก่อน +1

      Thanks for pointing that out. Might try and do a follow-up!

    • @abhishekbhattacherjee8873
      @abhishekbhattacherjee8873 หลายเดือนก่อน

      can you send the revised code using the Smartdataframe

  • @latestmoviesforall
    @latestmoviesforall 7 หลายเดือนก่อน

    how can i create a virtual environment? using windows. when i creat the two file main.py and .env, i don't seen the ( venv-llm) PS: any help plz.
    thanks for the knowledge you shared

    • @bugbytes3923
      @bugbytes3923  7 หลายเดือนก่อน +1

      Hey - you can try the following:
      1. python -m venv ./venv-llm
      2. ./venv-llm/Scripts/activate
      3. pip install (enter the package names you want to use)

    • @latestmoviesforall
      @latestmoviesforall 7 หลายเดือนก่อน

      thank you@@bugbytes3923 , I put the code in a new terminal in the C path at the end , and it gives me this message : "Python not found. Run without arguments to proceed." what should I do please ?

  • @techystu5823
    @techystu5823 10 หลายเดือนก่อน

    Everything was working fine until I added the from pandasai import PandasAI and then i get an error on my streamlit page says No module named 'bs4'. Can you please help

    • @bugbytes3923
      @bugbytes3923  10 หลายเดือนก่อน

      Not sure why that is, but you can try installing that library with the command:
      pip install BeautifulSoup4

  • @jaysonmagdamit4784
    @jaysonmagdamit4784 ปีที่แล้ว

    how can i create a virtual environment? using mac - Thanks!

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว

      Hey Jayson - you can run the following commands (change 'my-venv' to any name you like):
      --
      python3 -m venv my-venv
      source my-venv/bin/activate
      --
      The first command will create the environment using Python's built-in "venv" module.
      The second command activates the environment - once activated, you can install external packages into this environment.

  • @glory_vn7085
    @glory_vn7085 8 หลายเดือนก่อน

    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 = Image.open('exports/charts/temp_chart.png')
    st.image(image, caption='')
    #########
    'exports/charts/temp_chart.png', this can be found from "print(df.last_code_generated)"

    • @ordaflash
      @ordaflash 8 หลายเดือนก่อน

      please can you give more details about your solution ?

    • @jamesstover718
      @jamesstover718 5 หลายเดือนก่อน +1

      This code works, but with latest pandasai the filename now that I get is a long unique file name. So, I had to add code to extract the relative path to my app with the unique filename and then display it. Wish this was handled better by the pandasai library, but it works. I have an issue though when plotting some charts like a horizontal bar chart where the png image file is chopping off the front of the y-axis labels. Always something to battle.

    • @karthikvb1293
      @karthikvb1293 5 หลายเดือนก่อน

      Even though it's rendering on UI, Still it also opens in new window. How to stop that?

  • @iwhiteside
    @iwhiteside 7 หลายเดือนก่อน

    Hi Bugbytes I am new to python your videos are great I am getting an error from your code PandasAI is not defined I am sure I did something wrong

    • @AshWickramasinghe
      @AshWickramasinghe 6 หลายเดือนก่อน

      the library got updated and the new version isn't using the PandasAI

  • @JiteshPatil518
    @JiteshPatil518 หลายเดือนก่อน

    Hi...Getting below error while running the app
    ImportError: cannot import name ‘PandasAI’ from ‘pandasai’ (C:\Users\RONALD AINEBYONA\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandasai_init_.py)

  • @binoyxbabu
    @binoyxbabu 8 หลายเดือนก่อน

    Bro, i really liked your video but could you reply or do another video that how could we bring graphs also to our streamlit page rather showing it in a seperate window like in this video. I think with that its 100% and a complete product....i know you said that its possible but matter of finding it how 😊

    • @binoyxbabu
      @binoyxbabu 8 หลายเดือนก่อน

      @bugbytes3923 fyr

  • @MahalingamBalasubramanian
    @MahalingamBalasubramanian 5 หลายเดือนก่อน

    It seems this code is not supporting graphs, I am getting below response
    Generating an answer, please wait...
    The bar chart for the top 3 Organization Names by Number of employees is displayed on the axes with coordinates (0.125,0.11) and a size of 0.775x0.77.

  • @anouarben779
    @anouarben779 ปีที่แล้ว

    Are OpenAI API keys free or what,
    Mine requires credits is it the same for everyone?!

    • @unl0ck998
      @unl0ck998 ปีที่แล้ว

      OpenAI API is not free

  • @barutistudio1397
    @barutistudio1397 ปีที่แล้ว

    Can we get the code?

    • @adamtorabi5972
      @adamtorabi5972 7 หลายเดือนก่อน

      I am interested in the code too

  • @zac1427
    @zac1427 ปีที่แล้ว

    Guys ! I found a way to show plot in web app !
    if st.button("Generate"):
    if prompt:
    with st.spinner("Generating response..."):
    answer = pandas_ai.run(st.session_state.df,prompt)
    fig_number = plt.get_fignums()
    if fig_number:
    st.pyplot(plt.gcf())
    else:
    st.write(answer)

    • @bugbytes3923
      @bugbytes3923  ปีที่แล้ว +1

      Nice! Thanks for sharing that!

    • @visheshgupta2048
      @visheshgupta2048 ปีที่แล้ว

      Hi, I used your code, and it is working on the local machine. But this code does not satisfy requirements after deploying it. Do you have any idea about this ?

    • @zac1427
      @zac1427 ปีที่แล้ว

      @@visheshgupta2048 did you use aws ? make sure you let your virtual machine download all the packages in the requirement. It took me a while to fix the bug when I deploy it on AWS

    • @visheshgupta2048
      @visheshgupta2048 ปีที่แล้ว

      @@zac1427 no, I used github and streamlit to deploy. Does AWS works? To show graph in the deployed server.

    • @phaninagandla4983
      @phaninagandla4983 9 หลายเดือนก่อน +1

      Hi, I am receiving the following error when using the above code: " AttributeError: module 'matplotlib' has no attribute 'get_fignums' " : if possible can you share the entire code you?

  • @betenu1
    @betenu1 ปีที่แล้ว +1

    The women and children were more likely to survive because they were put on the lifeboats first.

  • @pidswing5334
    @pidswing5334 ปีที่แล้ว

    Hey BugBytes! The responses provided by my model were very raw for example, when asked about the fare price, I received the response, "32.204207968574636". Can you help me with why is this the case?

  • @shekarshekar4988
    @shekarshekar4988 ปีที่แล้ว

    Hi Mate,
    In the below comments,@zac1427 found a way to display the charts on the frontend.
    But I have played around with the code he/she mentoined. But It hasn't worked.
    import matplotlib.pyplot as plt
    if st.button("Submit"):
    if a:
    with st.spinner("Please Wait....."):
    b=Pandas_ai.run(df, prompt = a)
    fig_number = plt.get_fignums()
    if fig_number:
    st.pyplot(plt.gcf())
    else:
    st.write(b)
    I am receiving the below warning and couldn't not able to display charts.
    UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so it cannot show the figure. Please let us know if it's worked or if you have found any other way.