|
| 1 | +`GUIPandasAI`: An open-source, low-code simple python wrapper around PandasAI using the Streamlit Framework. |
| 2 | +============================================================================================================ |
| 3 | + |
| 4 | +`gui-pandas-ai` is concieved, designed and developed by `Ajay Arunachalam` (ajay.arunachalam08@gmail) - https://www.linkedin.com/in/ajay-ph-d-4744581a/ |
| 5 | + |
| 6 | +**gui-pandas-ai** |
| 7 | + |
| 8 | +pypi: https://pypi.org/project/gui-pandas-ai |
| 9 | + |
| 10 | + |
| 11 | +The APP workflow is as seen below. |
| 12 | +.. image:: images/main_ui.png |
| 13 | + |
| 14 | +The users after sucessful login, are redirected to the API key input window to submit their respective openAI key. Next, the users can upload their flat csv file followed by their data analysis queries. The history of the prompts and responses can be stored in the text file, along with any response plots. Simply, one can ask questions about your data and get the answers back, in the form of human natural language response. |
| 15 | + |
| 16 | + |
| 17 | +About `GUIPandasAI` |
| 18 | +=================== |
| 19 | + |
| 20 | +`gui-pandas-ai` is a simple, ease-to-use Python UI Wrapper built to use `PandasAI` as naively and intuitively as possible. `gui-pandas-ai` provides an easy web gui interface to access `ChatGPT` directly along with provision for several key data analysis utilities. It is altogether a `low-code` solution. With this utility APP one can perform all end-to-end data analysis simply with text-based input queries democratizing Generative AI functionalities. User's can simply ask question related to their data and get the corresponding analysis as response. Further, one can also get quick insights, explore trends & patterns, get the aggregated results, fetch data profiling report and data summary, rendered SQL view of data for offline SQL analysis, data storytelling extract, etc. |
| 21 | + |
| 22 | +GUIPandasAI Usage Steps |
| 23 | +======================= |
| 24 | +Step 1) Create a virtual environment |
| 25 | + |
| 26 | +.. code:: bash |
| 27 | + |
| 28 | + py -3 -m venv <your_env_name> |
| 29 | + cd <your_env_name>/Scripts/activate |
| 30 | + |
| 31 | + **or** |
| 32 | + |
| 33 | + conda create -n <your_env_name> python=3.x (or 3.x) |
| 34 | + source activate <your_env_name> |
| 35 | +
|
| 36 | +Step 2) Create the clone of the repository in your created virtual environment |
| 37 | + |
| 38 | +.. code:: bash |
| 39 | +
|
| 40 | + >>> git clone https://github.com/ajayarunachalam/gui-pandas-ai |
| 41 | + >>> cd gui-pandas-ai |
| 42 | + >>> pip install -r requirements.txt |
| 43 | + |
| 44 | + $ git clone https://github.com/ajayarunachalam/gui-pandas-ai |
| 45 | + $ cd gui-pandas-ai |
| 46 | + $ sudo bash setup.sh |
| 47 | + |
| 48 | + **or** |
| 49 | + $ git clone https://github.com/ajayarunachalam/gui-pandas-ai |
| 50 | + $ cd gui-pandas-ai |
| 51 | + $ sudo bash setup.sh or python setup.py install |
| 52 | + |
| 53 | +Step 3) Launch APP |
| 54 | + |
| 55 | +- **The users can set their own credentials in the file `secrets.toml` found under the folder `.streamlit`. Alternatively, one can also use the existing example credentials as-it-is which are `user_test` and `user@123` or |
| 56 | +`dev_test` and `dev@123`** |
| 57 | + |
| 58 | +- **Windows users within the cloned folder just simply double-click the "run_app_windows.bat" file. Note:- Open the file with an Editor and replace with your virtual directory path within the file** |
| 59 | + |
| 60 | +- **Linux users navigate within the cloned folder and type in "sudo bash run_app_linux.sh" in the terminal** |
| 61 | + |
| 62 | +- **Mac users navigate within the cloned folder and type in "sh run_app_mac.sh" in the terminal** |
| 63 | + |
| 64 | +The APP will launch with a URL as seen below. |
| 65 | + |
| 66 | +.. image:: images/run_app.png |
| 67 | + |
| 68 | + |
| 69 | +APP Q&A Window |
| 70 | +============== |
| 71 | +As seen below the user's can drag and drop their `CSV` files or upload them, and submit their questions in form of simple queries. The data analysis results are received back in the form of natural language. |
| 72 | + |
| 73 | +.. image:: images/page0.png |
| 74 | + |
| 75 | +GUIPandasAI Code Snippet |
| 76 | +======================== |
| 77 | +Below is the example code snippet that runs the LLMs while viewing the uploaded data. |
| 78 | + |
| 79 | +```python |
| 80 | +if st.session_state.df is not None: |
| 81 | + st.subheader("Peek into the uploaded dataframe:") |
| 82 | + st.write(st.session_state.df.head(2)) |
| 83 | +
|
| 84 | +with st.form("Question"): |
| 85 | + question = st.text_area("Question", value="", help="Enter your queries here") |
| 86 | + answer = st.text_area("Answer", value="") |
| 87 | + submitted = st.form_submit_button("Submit") |
| 88 | + if submitted: |
| 89 | + with st.spinner(): |
| 90 | + llm = OpenAI(api_token=st.session_state.openai_key) |
| 91 | + pandas_ai = PandasAI(llm) |
| 92 | + x = pandas_ai.run(st.session_state.df, prompt=question) |
| 93 | +
|
| 94 | + fig = plt.gcf() |
| 95 | + fig, ax = plt.subplots(figsize=(10, 6)) |
| 96 | + plt.tight_layout() |
| 97 | + if fig.get_axes() and fig is not None: |
| 98 | + st.pyplot(fig) |
| 99 | + fig.savefig("plot.png") |
| 100 | + st.write(x) |
| 101 | + st.session_state.prompt_history.append(question) |
| 102 | + response_history.append(x) # Append the response to the list |
| 103 | + st.session_state.response_history = response_history |
| 104 | +``` |
| 105 | + |
| 106 | +PandasAI - Overview |
| 107 | +=================== |
| 108 | +`Pandas AI` is a Python library that adds generative artificial intelligence capabilities to Pandas, the popular data analysis and manipulation tool. `PandasAI` [PandasAI](https://github.com/gventuri/pandas-ai) aims to make Pandas dataframes conversational, allowing you to ask questions about your data and get answers back, in the form of natural human language. |
| 109 | + |
| 110 | +For quick overview glimse through the below illustration: (All Credits & Copyrights Reserved to `Pandas AI`) |
| 111 | + |
| 112 | +```python |
| 113 | +import pandas as pd |
| 114 | +from pandasai import PandasAI |
| 115 | +
|
| 116 | +# Sample DataFrame |
| 117 | +df = pd.DataFrame({ |
| 118 | + "country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"], |
| 119 | + "gdp": [19294482071552, 2891615567872, 2411255037952, 3435817336832, 1745433788416, 1181205135360, 1607402389504, 1490967855104, 4380756541440, 14631844184064], |
| 120 | + "happiness_index": [6.94, 7.16, 6.66, 7.07, 6.38, 6.4, 7.23, 7.22, 5.87, 5.12] |
| 121 | +}) |
| 122 | +
|
| 123 | +# Instantiate a LLM |
| 124 | +from pandasai.llm.openai import OpenAI |
| 125 | +llm = OpenAI(api_token="YOUR_API_TOKEN") |
| 126 | +
|
| 127 | +pandas_ai = PandasAI(llm, conversational=True) |
| 128 | +pandas_ai(df, prompt='Which are the 5 happiest countries?') |
| 129 | +``` |
| 130 | + |
| 131 | +The above code will return the following: |
| 132 | + |
| 133 | +``` |
| 134 | +6 Canada |
| 135 | +7 Australia |
| 136 | +1 United Kingdom |
| 137 | +3 Germany |
| 138 | +0 United States |
| 139 | +Name: country, dtype: object |
| 140 | +``` |
| 141 | + |
| 142 | +Of course, you can also ask PandasAI to perform more complex queries. For example, you can ask PandasAI to find the sum of the GDPs of the 2 unhappiest countries: |
| 143 | + |
| 144 | +```python |
| 145 | +pandas_ai(df, prompt='What is the sum of the GDPs of the 2 unhappiest countries?') |
| 146 | +``` |
| 147 | + |
| 148 | +The above code will return the following: |
| 149 | + |
| 150 | +``` |
| 151 | +19012600725504 |
| 152 | +``` |
| 153 | + |
| 154 | +```python |
| 155 | +"""Example of using PandasAI on multiple Pandas DataFrame""" |
| 156 | +
|
| 157 | +import pandas as pd |
| 158 | +from pandasai import PandasAI |
| 159 | +from pandasai.llm.openai import OpenAI |
| 160 | +
|
| 161 | +employees_data = { |
| 162 | + 'EmployeeID': [1, 2, 3, 4, 5], |
| 163 | + 'Name': ['John', 'Emma', 'Liam', 'Olivia', 'William'], |
| 164 | + 'Department': ['HR', 'Sales', 'IT', 'Marketing', 'Finance'] |
| 165 | +} |
| 166 | +
|
| 167 | +salaries_data = { |
| 168 | + 'EmployeeID': [1, 2, 3, 4, 5], |
| 169 | + 'Salary': [5000, 6000, 4500, 7000, 5500] |
| 170 | +} |
| 171 | +
|
| 172 | +employees_df = pd.DataFrame(employees_data) |
| 173 | +salaries_df = pd.DataFrame(salaries_data) |
| 174 | +
|
| 175 | +
|
| 176 | +llm = OpenAI() |
| 177 | +pandas_ai = PandasAI(llm, verbose=True) |
| 178 | +response = pandas_ai([employees_df, salaries_df], "Who gets paid the most?") |
| 179 | +print(response) |
| 180 | +``` |
| 181 | + |
| 182 | +``` |
| 183 | +# Output: Olivia |
| 184 | +``` |
| 185 | + |
| 186 | +License |
| 187 | +======= |
| 188 | +Copyright 2022-2023 Ajay Arunachalam < [email protected]> |
| 189 | + |
| 190 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 191 | + |
| 192 | +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 193 | + |
| 194 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. © 2023 GitHub, Inc. |
| 195 | + |
| 196 | +References |
| 197 | +========== |
| 198 | +Special mention to `streamlit`, `openai`, `PandasAI`, `Pandas Profiling` and the other open-source communities for their incredible contributions. |
| 199 | + |
| 200 | + |
| 201 | +TODO |
| 202 | +==== |
| 203 | + |
| 204 | +- [ ] Include more LLMs |
| 205 | +- [ ] Add support for Big Data |
| 206 | +- [ ] Add Statistical data analysis |
| 207 | +- [ ] Add Adv. Data Analytics provision |
| 208 | +- [ ] Integrate Lux based visualizations |
0 commit comments