From 457bbdc2f2190f64047e207477414c37b0397637 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 6 Aug 2024 00:35:07 -0400 Subject: [PATCH 01/24] test chart example --- vizro-ai/examples/colab-example-chart.ipynb | 184 ++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 vizro-ai/examples/colab-example-chart.ipynb diff --git a/vizro-ai/examples/colab-example-chart.ipynb b/vizro-ai/examples/colab-example-chart.ipynb new file mode 100644 index 000000000..a8ce1680b --- /dev/null +++ b/vizro-ai/examples/colab-example-chart.ipynb @@ -0,0 +1,184 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b72a43eb-2991-45da-844a-a88c1b9b6f1e", + "metadata": {}, + "source": [ + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6a12271-d8da-4013-a677-74c01605ccc1", + "metadata": {}, + "outputs": [], + "source": [ + "from google.colab import userdata\n", + "\n", + "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", + "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a79a438f-6998-468e-9707-998406c63652", + "metadata": {}, + "outputs": [], + "source": [ + "!pip install vizro-ai" + ] + }, + { + "cell_type": "markdown", + "id": "23acc66a-f782-46b8-832f-4ce5699f23e7", + "metadata": {}, + "source": [ + "# Getting started" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4f37b7d5-5073-4c06-9fe9-fda5ed38115a", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import vizro.plotly.express as px\n", + "\n", + "from vizro_ai import VizroAI" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "01af08c5-484e-4173-bb38-50fed9b7a764", + "metadata": {}, + "outputs": [], + "source": [ + "vizro_ai = VizroAI()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3", + "metadata": {}, + "outputs": [], + "source": [ + "# data for plotting\n", + "df = px.data.gapminder()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c1a9db39-febf-4c09-af2c-168287f6e69f", + "metadata": {}, + "outputs": [], + "source": [ + "vizro_ai.plot(df, \"describe the composition of gdp in continent\")" + ] + }, + { + "cell_type": "markdown", + "id": "ccbacc74-d5fc-46b6-beb2-231242b0e601", + "metadata": {}, + "source": [ + "# Use a different model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0aab1319-e11a-4354-a220-b6517a5934c3", + "metadata": {}, + "outputs": [], + "source": [ + "vizro_ai = VizroAI(model=\"gpt-4o\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e0a171d-502b-4bf1-a0ae-93443af21274", + "metadata": {}, + "outputs": [], + "source": [ + "vizro_ai.plot(df, \"describe the composition of gdp in continent\")" + ] + }, + { + "cell_type": "markdown", + "id": "d4fda13e-a27f-4977-aa58-fcdd8b4cbc05", + "metadata": {}, + "source": [ + "# Use your own data" + ] + }, + { + "cell_type": "markdown", + "id": "dbedf477-cefe-49fa-b675-ef661425c3d3", + "metadata": {}, + "source": [ + "## Upload from local" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dfd45d6e-e828-4f20-9afc-8a659a79b5d6", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b4d83236-f584-4467-bcd3-30174d368e9d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "d61aa049-6785-4926-a543-bfa3cb68e65a", + "metadata": {}, + "source": [ + "## Mount from Google Drive" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "25f17884-333a-4584-a469-3d859bffdd53", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 5652f6ef5bb0f4a5e6a83903e81d49cc65bb6ff5 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 6 Aug 2024 01:20:14 -0400 Subject: [PATCH 02/24] update chart notebook --- vizro-ai/examples/colab-example-chart.ipynb | 107 ++++++++++++++------ 1 file changed, 75 insertions(+), 32 deletions(-) diff --git a/vizro-ai/examples/colab-example-chart.ipynb b/vizro-ai/examples/colab-example-chart.ipynb index a8ce1680b..4b4360705 100644 --- a/vizro-ai/examples/colab-example-chart.ipynb +++ b/vizro-ai/examples/colab-example-chart.ipynb @@ -8,6 +8,28 @@ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb)" ] }, + { + "cell_type": "markdown", + "id": "fbc65f78", + "metadata": {}, + "source": [ + "# Use Vizro-AI in Google Colab" + ] + }, + { + "cell_type": "markdown", + "id": "1ac9a6f7", + "metadata": {}, + "source": [ + "#### 1. Secure your LLM API key as environment variable\n", + "\n", + "- click the `Secrets` button on the left\n", + "- click `Add new secret`\n", + "- insert \"OPENAI_API_KEY\" under `Name`\n", + "- insert the API key value under `Value`\n", + "- click the `Notebook access` toggle to make it available for the notebook run" + ] + }, { "cell_type": "code", "execution_count": null, @@ -15,12 +37,21 @@ "metadata": {}, "outputs": [], "source": [ + "import os\n", "from google.colab import userdata\n", "\n", "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" ] }, + { + "cell_type": "markdown", + "id": "90c99f85", + "metadata": {}, + "source": [ + "#### 2. Install Vizro-AI" + ] + }, { "cell_type": "code", "execution_count": null, @@ -36,50 +67,39 @@ "id": "23acc66a-f782-46b8-832f-4ce5699f23e7", "metadata": {}, "source": [ - "# Getting started" + "#### 3. Load sample data" ] }, { "cell_type": "code", "execution_count": null, - "id": "4f37b7d5-5073-4c06-9fe9-fda5ed38115a", + "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3", "metadata": {}, "outputs": [], "source": [ - "import os\n", "import vizro.plotly.express as px\n", "\n", - "from vizro_ai import VizroAI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "01af08c5-484e-4173-bb38-50fed9b7a764", - "metadata": {}, - "outputs": [], - "source": [ - "vizro_ai = VizroAI()" + "df = px.data.gapminder()" ] }, { - "cell_type": "code", - "execution_count": null, - "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3", + "cell_type": "markdown", + "id": "c6cd92b0", "metadata": {}, - "outputs": [], "source": [ - "# data for plotting\n", - "df = px.data.gapminder()" + "#### 4. Instruct Vizro-AI for your plotting task" ] }, { "cell_type": "code", "execution_count": null, - "id": "c1a9db39-febf-4c09-af2c-168287f6e69f", + "id": "fbb3717e", "metadata": {}, "outputs": [], "source": [ + "from vizro_ai import VizroAI\n", + "\n", + "vizro_ai = VizroAI()\n", "vizro_ai.plot(df, \"describe the composition of gdp in continent\")" ] }, @@ -124,7 +144,7 @@ "id": "dbedf477-cefe-49fa-b675-ef661425c3d3", "metadata": {}, "source": [ - "## Upload from local" + "#### 1. Upload from local" ] }, { @@ -133,7 +153,15 @@ "id": "dfd45d6e-e828-4f20-9afc-8a659a79b5d6", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "from google.colab import files\n", + "\n", + "uploaded = files.upload()\n", + "\n", + "for fn in uploaded.keys():\n", + " print('User uploaded file \"{name}\" with length {length} bytes'.format(\n", + " name=fn, length=len(uploaded[fn])))" + ] }, { "cell_type": "code", @@ -141,23 +169,38 @@ "id": "b4d83236-f584-4467-bcd3-30174d368e9d", "metadata": {}, "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "d61aa049-6785-4926-a543-bfa3cb68e65a", - "metadata": {}, "source": [ - "## Mount from Google Drive" + "import pandas as pd\n", + "\n", + "# Get the filename (assuming you uploaded only one file)\n", + "filename = next(iter(uploaded))\n", + "\n", + "# Read the CSV file into a pandas DataFrame\n", + "df_uploaded = pd.read_csv(filename)\n", + "\n", + "# Display the first few rows of the DataFrame\n", + "print(df_uploaded.head())" ] }, { "cell_type": "code", "execution_count": null, - "id": "25f17884-333a-4584-a469-3d859bffdd53", + "id": "ec8612c7", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "vizro_ai.plot(df_uploaded, \"\")" + ] + }, + { + "cell_type": "markdown", + "id": "d61aa049-6785-4926-a543-bfa3cb68e65a", + "metadata": {}, + "source": [ + "#### 2. Additional ways to connect to your data\n", + "\n", + "https://colab.research.google.com/notebooks/io.ipynb" + ] } ], "metadata": { From 7f9b198929b51ff483bc658c989083881814aa1d Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 6 Aug 2024 22:08:59 -0400 Subject: [PATCH 03/24] add dashboard nb --- vizro-ai/examples/colab-example-chart.ipynb | 8 +- .../examples/colab-example-dashboard.ipynb | 182 ++++++++++++++++++ 2 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 vizro-ai/examples/colab-example-dashboard.ipynb diff --git a/vizro-ai/examples/colab-example-chart.ipynb b/vizro-ai/examples/colab-example-chart.ipynb index 4b4360705..777fe82a4 100644 --- a/vizro-ai/examples/colab-example-chart.ipynb +++ b/vizro-ai/examples/colab-example-chart.ipynb @@ -13,7 +13,7 @@ "id": "fbc65f78", "metadata": {}, "source": [ - "# Use Vizro-AI in Google Colab" + "# Use Vizro-AI to generate Vizro charts" ] }, { @@ -30,6 +30,12 @@ "- click the `Notebook access` toggle to make it available for the notebook run" ] }, + { + "cell_type": "markdown", + "id": "c0df4a08", + "metadata": {}, + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/vizro-ai/examples/colab-example-dashboard.ipynb b/vizro-ai/examples/colab-example-dashboard.ipynb new file mode 100644 index 000000000..5a282fcc6 --- /dev/null +++ b/vizro-ai/examples/colab-example-dashboard.ipynb @@ -0,0 +1,182 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-dashboard.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Use Vizro-AI to generate Vizro dashboard" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 1. Secure your LLM API key as environment variable\n", + "\n", + "- click the `Secrets` button on the left\n", + "- click `Add new secret`\n", + "- insert \"OPENAI_API_KEY\" under `Name`\n", + "- insert the API key value under `Value`\n", + "- click the `Notebook access` toggle to make it available for the notebook run" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from google.colab import userdata\n", + "\n", + "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", + "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Install Vizro-AI" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# TODO: change to !pip install vizro-ai when this PR is ready to merge\n", + "# !pip install vizro-ai\n", + "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import vizro.plotly.express as px\n", + "\n", + "from vizro import Vizro\n", + "from vizro_ai import VizroAI" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @title ## 1. Input your dashboard question\n", + "\n", + "# @markdown ---\n", + "# @markdown #### Instructions:\n", + "user_input = '' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", + "\n", + "print(user_input)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2. Upload your data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @title\n", + "import pandas as pd\n", + "from google.colab import files\n", + "\n", + "uploaded = files.upload()\n", + "\n", + "dfs = []\n", + "for fn in uploaded.keys():\n", + " print('User uploaded file \"{name}\"'.format(\n", + " name=fn, length=len(uploaded[fn])))\n", + " \n", + " df_uploaded = pd.read_csv(fn)\n", + " dfs.append(df_uploaded)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @title String fields\n", + "\n", + "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "\n", + "print(LLM)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# # @title\n", + "# import ipywidgets as widgets\n", + "# from IPython.display import display\n", + "# button = widgets.Button(description=\"Build Dashboard!\")\n", + "# output = widgets.Output()\n", + "\n", + "# def on_button_clicked(b):\n", + "# # Display the message within the output widget.\n", + "# with output:\n", + "# print(\"In progress...\")\n", + "# vizro_ai = VizroAI(model=LLM)\n", + "# dashboard = vizro_ai.dashboard(dfs, user_input)\n", + "# vizro_dashboard = Vizro().build(dashboard)\n", + "# print(\"Build complete.\")\n", + "\n", + "# button.on_click(on_button_clicked)\n", + "# display(button, output)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dashboard = vizro_ai.dashboard(dfs, user_input)\n", + "vizro_dashboard = Vizro().build(dashboard)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vizro_dashboard.run()" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 8b6033f96a09c7929d985b8b9da046f9f5a9b4f7 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 6 Aug 2024 23:49:20 -0400 Subject: [PATCH 04/24] sanitized dashboard version --- vizro-ai/examples/colab-example-chart.ipynb | 1 + .../examples/colab_example_dashboard.ipynb | 182 ++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 vizro-ai/examples/colab_example_dashboard.ipynb diff --git a/vizro-ai/examples/colab-example-chart.ipynb b/vizro-ai/examples/colab-example-chart.ipynb index 777fe82a4..cdf1cfa3a 100644 --- a/vizro-ai/examples/colab-example-chart.ipynb +++ b/vizro-ai/examples/colab-example-chart.ipynb @@ -27,6 +27,7 @@ "- click `Add new secret`\n", "- insert \"OPENAI_API_KEY\" under `Name`\n", "- insert the API key value under `Value`\n", + "- [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", "- click the `Notebook access` toggle to make it available for the notebook run" ] }, diff --git a/vizro-ai/examples/colab_example_dashboard.ipynb b/vizro-ai/examples/colab_example_dashboard.ipynb new file mode 100644 index 000000000..52966704e --- /dev/null +++ b/vizro-ai/examples/colab_example_dashboard.ipynb @@ -0,0 +1,182 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "npjw_Cstpr2I" + }, + "source": [ + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-dashboard.ipynb)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dsR_4Smypr2L" + }, + "source": [ + "# Use Vizro-AI to generate Vizro dashboard" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "cellView": "form", + "id": "dc1unu-0pr2M" + }, + "outputs": [], + "source": [ + "# @title 1. Secure your LLM API key as environment variable\n", + "#@markdown - click the `Secrets` button on the left\n", + "#@markdown - click `Add new secret`\n", + "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", + "#@markdown - insert the API key value under `Value`\n", + "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", + "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", + "\n", + "import os\n", + "from google.colab import userdata\n", + "\n", + "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", + "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "collapsed": true, + "id": "TcELu_eMpr2O" + }, + "outputs": [], + "source": [ + "# @title 2. Install Vizro-AI\n", + "#@markdown TODO: change to !pip install vizro-ai when this PR is ready to merge\n", + "#@markdown #### !pip install vizro-ai\n", + "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "bPXCUA7Kpr2P" + }, + "outputs": [], + "source": [ + "# @title ## 3. Input your dashboard question\n", + "\n", + "# @markdown #### Instructions:\n", + "user_input = 'Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", + "\n", + "print(user_input)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "O_wbhA2zpr2Q" + }, + "outputs": [], + "source": [ + "# @title 4. Upload your data\n", + "import pandas as pd\n", + "from google.colab import files\n", + "\n", + "uploaded = files.upload()\n", + "\n", + "dfs = []\n", + "for fn in uploaded.keys():\n", + " print('User uploaded file \"{name}\"'.format(\n", + " name=fn, length=len(uploaded[fn])))\n", + "\n", + " df_uploaded = pd.read_csv(fn)\n", + " dfs.append(df_uploaded)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "COXftEJEpr2Q" + }, + "outputs": [], + "source": [ + "# @title 5. Choose the LLM model\n", + "\n", + "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "\n", + "print(f\"Selected LLM: {LLM}\")" + ] + }, + { + "cell_type": "code", + "source": [ + "# @title 6. Build the dashboard using Vizro-AI\n", + "\n", + "import ipywidgets as widgets\n", + "from IPython.display import display\n", + "\n", + "def run_code(button):\n", + " from vizro_ai import VizroAI\n", + " from vizro import Vizro\n", + "\n", + " Vizro._reset()\n", + " vizro_ai = VizroAI(model=LLM)\n", + " dashboard = vizro_ai.dashboard(dfs, user_input)\n", + "\n", + " vizro_dashboard = Vizro().build(dashboard)\n", + "\n", + " # Store the result in the button's object\n", + " button.result = vizro_dashboard\n", + "\n", + "# Create and display the button\n", + "button = widgets.Button(description=\"Build Dashboard!\")\n", + "display(button)\n", + "\n", + "# Link the button click to the function\n", + "button.on_click(run_code)" + ], + "metadata": { + "cellView": "form", + "id": "rEl8JajAxmMq" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# @title 7. Render dashboard\n", + "\n", + "button.result.run()" + ], + "metadata": { + "cellView": "form", + "id": "as5y9yI8x-s5" + }, + "execution_count": null, + "outputs": [] + } + ], + "metadata": { + "language_info": { + "name": "python" + }, + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file From e230e67af0226794839a0c068ac92ce634984928 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 03:49:53 +0000 Subject: [PATCH 05/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- vizro-ai/examples/colab_example_dashboard.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-ai/examples/colab_example_dashboard.ipynb b/vizro-ai/examples/colab_example_dashboard.ipynb index 52966704e..fc1a12b78 100644 --- a/vizro-ai/examples/colab_example_dashboard.ipynb +++ b/vizro-ai/examples/colab_example_dashboard.ipynb @@ -179,4 +179,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From 7cbe648478d912c233e60f426ab455d3e4c162bc Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 6 Aug 2024 23:54:48 -0400 Subject: [PATCH 06/24] change link --- .../examples/colab_example_dashboard.ipynb | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/vizro-ai/examples/colab_example_dashboard.ipynb b/vizro-ai/examples/colab_example_dashboard.ipynb index fc1a12b78..ad4cbd696 100644 --- a/vizro-ai/examples/colab_example_dashboard.ipynb +++ b/vizro-ai/examples/colab_example_dashboard.ipynb @@ -6,7 +6,7 @@ "id": "npjw_Cstpr2I" }, "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-dashboard.ipynb)" + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab_example_dashboard.ipynb)" ] }, { @@ -117,6 +117,12 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "rEl8JajAxmMq" + }, + "outputs": [], "source": [ "# @title 6. Build the dashboard using Vizro-AI\n", "\n", @@ -142,39 +148,33 @@ "\n", "# Link the button click to the function\n", "button.on_click(run_code)" - ], - "metadata": { - "cellView": "form", - "id": "rEl8JajAxmMq" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", - "source": [ - "# @title 7. Render dashboard\n", - "\n", - "button.result.run()" - ], + "execution_count": null, "metadata": { "cellView": "form", "id": "as5y9yI8x-s5" }, - "execution_count": null, - "outputs": [] + "outputs": [], + "source": [ + "# @title 7. Render dashboard\n", + "\n", + "button.result.run()" + ] } ], "metadata": { - "language_info": { - "name": "python" - }, "colab": { "provenance": [] }, "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" } }, "nbformat": 4, From 191b2b410c61d2661f776b734d1d9b2353321376 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 00:43:35 -0400 Subject: [PATCH 07/24] update notebook --- .../examples/colab-example-dashboard.ipynb | 182 ------------------ ...oard.ipynb => dashboard_by_vizro_ai.ipynb} | 82 +++++--- 2 files changed, 52 insertions(+), 212 deletions(-) delete mode 100644 vizro-ai/examples/colab-example-dashboard.ipynb rename vizro-ai/examples/{colab_example_dashboard.ipynb => dashboard_by_vizro_ai.ipynb} (71%) diff --git a/vizro-ai/examples/colab-example-dashboard.ipynb b/vizro-ai/examples/colab-example-dashboard.ipynb deleted file mode 100644 index 5a282fcc6..000000000 --- a/vizro-ai/examples/colab-example-dashboard.ipynb +++ /dev/null @@ -1,182 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-dashboard.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Use Vizro-AI to generate Vizro dashboard" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 1. Secure your LLM API key as environment variable\n", - "\n", - "- click the `Secrets` button on the left\n", - "- click `Add new secret`\n", - "- insert \"OPENAI_API_KEY\" under `Name`\n", - "- insert the API key value under `Value`\n", - "- click the `Notebook access` toggle to make it available for the notebook run" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from google.colab import userdata\n", - "\n", - "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", - "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "2. Install Vizro-AI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# TODO: change to !pip install vizro-ai when this PR is ready to merge\n", - "# !pip install vizro-ai\n", - "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "import vizro.plotly.express as px\n", - "\n", - "from vizro import Vizro\n", - "from vizro_ai import VizroAI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title ## 1. Input your dashboard question\n", - "\n", - "# @markdown ---\n", - "# @markdown #### Instructions:\n", - "user_input = '' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", - "\n", - "print(user_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 2. Upload your data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title\n", - "import pandas as pd\n", - "from google.colab import files\n", - "\n", - "uploaded = files.upload()\n", - "\n", - "dfs = []\n", - "for fn in uploaded.keys():\n", - " print('User uploaded file \"{name}\"'.format(\n", - " name=fn, length=len(uploaded[fn])))\n", - " \n", - " df_uploaded = pd.read_csv(fn)\n", - " dfs.append(df_uploaded)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# @title String fields\n", - "\n", - "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", - "\n", - "print(LLM)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# # @title\n", - "# import ipywidgets as widgets\n", - "# from IPython.display import display\n", - "# button = widgets.Button(description=\"Build Dashboard!\")\n", - "# output = widgets.Output()\n", - "\n", - "# def on_button_clicked(b):\n", - "# # Display the message within the output widget.\n", - "# with output:\n", - "# print(\"In progress...\")\n", - "# vizro_ai = VizroAI(model=LLM)\n", - "# dashboard = vizro_ai.dashboard(dfs, user_input)\n", - "# vizro_dashboard = Vizro().build(dashboard)\n", - "# print(\"Build complete.\")\n", - "\n", - "# button.on_click(on_button_clicked)\n", - "# display(button, output)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "dashboard = vizro_ai.dashboard(dfs, user_input)\n", - "vizro_dashboard = Vizro().build(dashboard)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vizro_dashboard.run()" - ] - } - ], - "metadata": { - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/vizro-ai/examples/colab_example_dashboard.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb similarity index 71% rename from vizro-ai/examples/colab_example_dashboard.ipynb rename to vizro-ai/examples/dashboard_by_vizro_ai.ipynb index ad4cbd696..08703d981 100644 --- a/vizro-ai/examples/colab_example_dashboard.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -20,14 +20,29 @@ }, { "cell_type": "code", - "execution_count": 1, + "source": [ + "# @title 1. Install Vizro-AI\n", + "#@markdown (TODO: change to !pip install vizro-ai when this PR is ready to merge)\n", + "# !pip install vizro-ai\n", + "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" + ], + "metadata": { + "cellView": "form", + "id": "OSDQDsyCBjSz" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 2, "metadata": { "cellView": "form", "id": "dc1unu-0pr2M" }, "outputs": [], "source": [ - "# @title 1. Secure your LLM API key as environment variable\n", + "# @title 2. Secure your LLM API key as environment variable\n", "#@markdown - click the `Secrets` button on the left\n", "#@markdown - click `Add new secret`\n", "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", @@ -42,22 +57,6 @@ "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "collapsed": true, - "id": "TcELu_eMpr2O" - }, - "outputs": [], - "source": [ - "# @title 2. Install Vizro-AI\n", - "#@markdown TODO: change to !pip install vizro-ai when this PR is ready to merge\n", - "#@markdown #### !pip install vizro-ai\n", - "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" - ] - }, { "cell_type": "code", "execution_count": null, @@ -84,19 +83,29 @@ }, "outputs": [], "source": [ - "# @title 4. Upload your data\n", + "# @title 4. Upload your CSV data\n", + "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", + "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", + "\n", "import pandas as pd\n", + "from plotly.express.data import gapminder\n", "from google.colab import files\n", "\n", "uploaded = files.upload()\n", "\n", "dfs = []\n", - "for fn in uploaded.keys():\n", - " print('User uploaded file \"{name}\"'.format(\n", - " name=fn, length=len(uploaded[fn])))\n", "\n", - " df_uploaded = pd.read_csv(fn)\n", - " dfs.append(df_uploaded)" + "if not uploaded:\n", + " print(\"No files uploaded. Use the plotly gapminder dataset as an example.\")\n", + " df = gapminder()\n", + " dfs.append(df)\n", + "else:\n", + " for fn in uploaded.keys():\n", + " print('User uploaded file \"{name}\"'.format(\n", + " name=fn, length=len(uploaded[fn])))\n", + "\n", + " df_uploaded = pd.read_csv(fn)\n", + " dfs.append(df_uploaded)" ] }, { @@ -140,14 +149,14 @@ " vizro_dashboard = Vizro().build(dashboard)\n", "\n", " # Store the result in the button's object\n", - " button.result = vizro_dashboard\n", + " button1.result = vizro_dashboard\n", "\n", "# Create and display the button\n", - "button = widgets.Button(description=\"Build Dashboard!\")\n", - "display(button)\n", + "button1 = widgets.Button(description=\"Build Dashboard!\")\n", + "display(button1)\n", "\n", "# Link the button click to the function\n", - "button.on_click(run_code)" + "button1.on_click(run_code)" ] }, { @@ -161,7 +170,20 @@ "source": [ "# @title 7. Render dashboard\n", "\n", - "button.result.run()" + "# button1.result.run()\n", + "\n", + "import ipywidgets as widgets\n", + "from IPython.display import display\n", + "\n", + "def run_dashboard(button):\n", + " button1.result.run()\n", + "\n", + "# Create and display the button\n", + "button2 = widgets.Button(description=\"Run Dashboard!\")\n", + "display(button2)\n", + "\n", + "# Link the button click to the function\n", + "button2.on_click(run_dashboard)" ] } ], @@ -179,4 +201,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From c31c53fb589a3defa5aaea963b38e8a19e2478bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 04:44:07 +0000 Subject: [PATCH 08/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index 08703d981..872bb659d 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -201,4 +201,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From 71a888c59e5fa9e829b53393908dd881a7ed0896 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 00:56:38 -0400 Subject: [PATCH 09/24] add link in readme --- vizro-ai/README.md | 2 ++ vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vizro-ai/README.md b/vizro-ai/README.md index 25e672c43..1a2b9a51d 100644 --- a/vizro-ai/README.md +++ b/vizro-ai/README.md @@ -7,6 +7,8 @@ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mckinsey/vizro/blob/main/LICENSE.md) [![Documentation](https://readthedocs.org/projects/vizro-ai/badge/?version=latest)](https://vizro-ai.readthedocs.io/) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7858/badge)](https://www.bestpractices.dev/projects/7858) +[![Create chart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb) +[![Create dashboard In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/dashboard_by_vizro_ai.ipynb) Gif to demonstrate vizro-ai diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index 872bb659d..e52d2fcd3 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -6,7 +6,7 @@ "id": "npjw_Cstpr2I" }, "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab_example_dashboard.ipynb)" + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/dashboard_by_vizro_ai.ipynb)" ] }, { @@ -20,18 +20,18 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "OSDQDsyCBjSz" + }, + "outputs": [], "source": [ "# @title 1. Install Vizro-AI\n", "#@markdown (TODO: change to !pip install vizro-ai when this PR is ready to merge)\n", "# !pip install vizro-ai\n", "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" - ], - "metadata": { - "cellView": "form", - "id": "OSDQDsyCBjSz" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", From f82250b81aac965fda5672b032364f041ffc0119 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 02:28:36 -0400 Subject: [PATCH 10/24] refactor chart nb --- ...0807_005926_lingyi_zhang_add_colab_link.md | 48 ++++ vizro-ai/examples/chart_by_vizro_ai.ipynb | 217 ++++++++++++++++++ vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 35 ++- 3 files changed, 290 insertions(+), 10 deletions(-) create mode 100644 vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md create mode 100644 vizro-ai/examples/chart_by_vizro_ai.ipynb diff --git a/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md b/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md new file mode 100644 index 000000000..f1f65e73c --- /dev/null +++ b/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb new file mode 100644 index 000000000..cfb2cf71f --- /dev/null +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -0,0 +1,217 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b72a43eb-2991-45da-844a-a88c1b9b6f1e", + "metadata": { + "id": "b72a43eb-2991-45da-844a-a88c1b9b6f1e" + }, + "source": [ + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/chart_by_vizro_ai.ipynb)" + ] + }, + { + "cell_type": "markdown", + "id": "fbc65f78", + "metadata": { + "id": "fbc65f78" + }, + "source": [ + "# Use Vizro-AI to generate Vizro charts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "rdnxbyKfNZkT", + "metadata": { + "cellView": "form", + "id": "rdnxbyKfNZkT" + }, + "outputs": [], + "source": [ + "# @title 1. Install Vizro-AI\n", + "!pip install vizro-ai" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "tH0P_zRIPBLw", + "metadata": { + "cellView": "form", + "id": "tH0P_zRIPBLw" + }, + "outputs": [], + "source": [ + "# @title 2. Secure your LLM API key as environment variable\n", + "#@markdown - click the `Secrets` button on the left\n", + "#@markdown - click `Add new secret`\n", + "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", + "#@markdown - insert the API key value under `Value`\n", + "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", + "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", + "\n", + "import os\n", + "from google.colab import userdata\n", + "\n", + "def safe_get_userdata(key):\n", + " try:\n", + " return userdata.get(key)\n", + " except Exception as e:\n", + " print(f\"Warning: Unable to access {key}. Reason: {str(e)}\")\n", + " return None\n", + "\n", + "# Always try to set the OPENAI_API_KEY\n", + "api_key = safe_get_userdata(\"OPENAI_API_KEY\")\n", + "if api_key:\n", + " os.environ[\"OPENAI_API_KEY\"] = api_key\n", + "else:\n", + " print(\"❌ OPENAI_API_KEY not set. Click `Secrets` icon on the left to setup.\")\n", + "\n", + "# Conditionally set OPENAI_BASE_URL if provided and accessible\n", + "openai_base_url = safe_get_userdata(\"OPENAI_BASE_URL\")\n", + "if openai_base_url:\n", + " os.environ[\"OPENAI_BASE_URL\"] = openai_base_url\n", + "else:\n", + " print(\"User defined OPENAI_BASE_URL not set. Using default URL.\")\n", + "\n", + "print(\"\\nCurrent environment variables:\")\n", + "print(f\"OPENAI_API_KEY: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", + "print(f\"OPENAI_BASE_URL: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set by user, use default'}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3", + "metadata": { + "cellView": "form", + "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3" + }, + "outputs": [], + "source": [ + "# @title ## 3. Input your chart question\n", + "\n", + "# @markdown #### Instructions:\n", + "user_input = 'describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", + "\n", + "print(user_input)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "HJMVfdecTctW", + "metadata": { + "cellView": "form", + "id": "HJMVfdecTctW" + }, + "outputs": [], + "source": [ + "# @title 4. Upload your CSV data (only 1 dataframe accepted per chart)\n", + "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", + "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", + "\n", + "import pandas as pd\n", + "from plotly.express.data import gapminder\n", + "from google.colab import files\n", + "\n", + "uploaded = files.upload()\n", + "\n", + "if not uploaded:\n", + " print(\"No files uploaded. Use the plotly gapminder dataset as an example.\")\n", + " df = gapminder()\n", + "else:\n", + " for fn in uploaded.keys():\n", + " print('User uploaded file \"{name}\"'.format(\n", + " name=fn, length=len(uploaded[fn])))\n", + "\n", + " df = pd.read_csv(fn)\n", + "print(f\"Dataframe used for plotting: \\n{df.head()}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "whPjXfNBTcfg", + "metadata": { + "cellView": "form", + "id": "whPjXfNBTcfg" + }, + "outputs": [], + "source": [ + "# @title 5. Choose the LLM model\n", + "\n", + "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "\n", + "print(f\"Selected LLM: {LLM}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "_yeVqs9nUgYH", + "metadata": { + "cellView": "form", + "id": "_yeVqs9nUgYH" + }, + "outputs": [], + "source": [ + "# @title 6. Create the chart using Vizro-AI\n", + "\n", + "import ipywidgets as widgets\n", + "from IPython.display import display\n", + "\n", + "def run_code(button):\n", + " from vizro_ai import VizroAI\n", + "\n", + " vizro_ai = VizroAI()\n", + " button1.result = vizro_ai.plot(df, user_input, explain=True)\n", + "\n", + "button1 = widgets.Button(description=\"Create chart!\")\n", + "display(button1)\n", + "\n", + "button1.on_click(run_code)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "B9P0eNoqc7gd", + "metadata": { + "cellView": "form", + "id": "B9P0eNoqc7gd" + }, + "outputs": [], + "source": [ + "# @title 7. Show the chart\n", + "button1.result.show()" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index e52d2fcd3..b331a5efe 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "cellView": "form", "id": "dc1unu-0pr2M" @@ -53,8 +53,30 @@ "import os\n", "from google.colab import userdata\n", "\n", - "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", - "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" + "def safe_get_userdata(key):\n", + " try:\n", + " return userdata.get(key)\n", + " except Exception as e:\n", + " print(f\"Warning: Unable to access {key}. Reason: {str(e)}\")\n", + " return None\n", + "\n", + "# Always try to set the OPENAI_API_KEY\n", + "api_key = safe_get_userdata(\"OPENAI_API_KEY\")\n", + "if api_key:\n", + " os.environ[\"OPENAI_API_KEY\"] = api_key\n", + "else:\n", + " print(\"❌ OPENAI_API_KEY not set. Click `Secrets` icon on the left to setup.\")\n", + "\n", + "# Conditionally set OPENAI_BASE_URL if provided and accessible\n", + "openai_base_url = safe_get_userdata(\"OPENAI_BASE_URL\")\n", + "if openai_base_url:\n", + " os.environ[\"OPENAI_BASE_URL\"] = openai_base_url\n", + "else:\n", + " print(\"User defined OPENAI_BASE_URL not set. Using default URL.\")\n", + "\n", + "print(\"\\nCurrent environment variables:\")\n", + "print(f\"OPENAI_API_KEY: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", + "print(f\"OPENAI_BASE_URL: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set by user, use default'}\")" ] }, { @@ -148,14 +170,11 @@ "\n", " vizro_dashboard = Vizro().build(dashboard)\n", "\n", - " # Store the result in the button's object\n", " button1.result = vizro_dashboard\n", "\n", - "# Create and display the button\n", "button1 = widgets.Button(description=\"Build Dashboard!\")\n", "display(button1)\n", "\n", - "# Link the button click to the function\n", "button1.on_click(run_code)" ] }, @@ -170,19 +189,15 @@ "source": [ "# @title 7. Render dashboard\n", "\n", - "# button1.result.run()\n", - "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", "\n", "def run_dashboard(button):\n", " button1.result.run()\n", "\n", - "# Create and display the button\n", "button2 = widgets.Button(description=\"Run Dashboard!\")\n", "display(button2)\n", "\n", - "# Link the button click to the function\n", "button2.on_click(run_dashboard)" ] } From 68836baac67bcfa727364dd9103a3efe7cdbc844 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 02:35:12 -0400 Subject: [PATCH 11/24] delete old one --- vizro-ai/examples/colab-example-chart.ipynb | 234 -------------------- 1 file changed, 234 deletions(-) delete mode 100644 vizro-ai/examples/colab-example-chart.ipynb diff --git a/vizro-ai/examples/colab-example-chart.ipynb b/vizro-ai/examples/colab-example-chart.ipynb deleted file mode 100644 index cdf1cfa3a..000000000 --- a/vizro-ai/examples/colab-example-chart.ipynb +++ /dev/null @@ -1,234 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "b72a43eb-2991-45da-844a-a88c1b9b6f1e", - "metadata": {}, - "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb)" - ] - }, - { - "cell_type": "markdown", - "id": "fbc65f78", - "metadata": {}, - "source": [ - "# Use Vizro-AI to generate Vizro charts" - ] - }, - { - "cell_type": "markdown", - "id": "1ac9a6f7", - "metadata": {}, - "source": [ - "#### 1. Secure your LLM API key as environment variable\n", - "\n", - "- click the `Secrets` button on the left\n", - "- click `Add new secret`\n", - "- insert \"OPENAI_API_KEY\" under `Name`\n", - "- insert the API key value under `Value`\n", - "- [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", - "- click the `Notebook access` toggle to make it available for the notebook run" - ] - }, - { - "cell_type": "markdown", - "id": "c0df4a08", - "metadata": {}, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d6a12271-d8da-4013-a677-74c01605ccc1", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from google.colab import userdata\n", - "\n", - "os.environ[\"OPENAI_API_KEY\"] = userdata.get(\"OPENAI_API_KEY\")\n", - "os.environ[\"OPENAI_BASE_URL\"] = userdata.get(\"OPENAI_BASE_URL\") # optional" - ] - }, - { - "cell_type": "markdown", - "id": "90c99f85", - "metadata": {}, - "source": [ - "#### 2. Install Vizro-AI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a79a438f-6998-468e-9707-998406c63652", - "metadata": {}, - "outputs": [], - "source": [ - "!pip install vizro-ai" - ] - }, - { - "cell_type": "markdown", - "id": "23acc66a-f782-46b8-832f-4ce5699f23e7", - "metadata": {}, - "source": [ - "#### 3. Load sample data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c6ac1b7d-5830-495b-94be-1ad7bf3022d3", - "metadata": {}, - "outputs": [], - "source": [ - "import vizro.plotly.express as px\n", - "\n", - "df = px.data.gapminder()" - ] - }, - { - "cell_type": "markdown", - "id": "c6cd92b0", - "metadata": {}, - "source": [ - "#### 4. Instruct Vizro-AI for your plotting task" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fbb3717e", - "metadata": {}, - "outputs": [], - "source": [ - "from vizro_ai import VizroAI\n", - "\n", - "vizro_ai = VizroAI()\n", - "vizro_ai.plot(df, \"describe the composition of gdp in continent\")" - ] - }, - { - "cell_type": "markdown", - "id": "ccbacc74-d5fc-46b6-beb2-231242b0e601", - "metadata": {}, - "source": [ - "# Use a different model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0aab1319-e11a-4354-a220-b6517a5934c3", - "metadata": {}, - "outputs": [], - "source": [ - "vizro_ai = VizroAI(model=\"gpt-4o\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1e0a171d-502b-4bf1-a0ae-93443af21274", - "metadata": {}, - "outputs": [], - "source": [ - "vizro_ai.plot(df, \"describe the composition of gdp in continent\")" - ] - }, - { - "cell_type": "markdown", - "id": "d4fda13e-a27f-4977-aa58-fcdd8b4cbc05", - "metadata": {}, - "source": [ - "# Use your own data" - ] - }, - { - "cell_type": "markdown", - "id": "dbedf477-cefe-49fa-b675-ef661425c3d3", - "metadata": {}, - "source": [ - "#### 1. Upload from local" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "dfd45d6e-e828-4f20-9afc-8a659a79b5d6", - "metadata": {}, - "outputs": [], - "source": [ - "from google.colab import files\n", - "\n", - "uploaded = files.upload()\n", - "\n", - "for fn in uploaded.keys():\n", - " print('User uploaded file \"{name}\" with length {length} bytes'.format(\n", - " name=fn, length=len(uploaded[fn])))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b4d83236-f584-4467-bcd3-30174d368e9d", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "\n", - "# Get the filename (assuming you uploaded only one file)\n", - "filename = next(iter(uploaded))\n", - "\n", - "# Read the CSV file into a pandas DataFrame\n", - "df_uploaded = pd.read_csv(filename)\n", - "\n", - "# Display the first few rows of the DataFrame\n", - "print(df_uploaded.head())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ec8612c7", - "metadata": {}, - "outputs": [], - "source": [ - "vizro_ai.plot(df_uploaded, \"\")" - ] - }, - { - "cell_type": "markdown", - "id": "d61aa049-6785-4926-a543-bfa3cb68e65a", - "metadata": {}, - "source": [ - "#### 2. Additional ways to connect to your data\n", - "\n", - "https://colab.research.google.com/notebooks/io.ipynb" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 54f66c0730cf8197db8a4b1f7bb77e063338b8ab Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 18:38:43 -0400 Subject: [PATCH 12/24] consolidate cells --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 85 ++++++--------- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 103 ++++++++---------- 2 files changed, 75 insertions(+), 113 deletions(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index cfb2cf71f..b56d7f3e7 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -30,21 +30,14 @@ }, "outputs": [], "source": [ - "# @title 1. Install Vizro-AI\n", - "!pip install vizro-ai" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "tH0P_zRIPBLw", - "metadata": { - "cellView": "form", - "id": "tH0P_zRIPBLw" - }, - "outputs": [], - "source": [ - "# @title 2. Secure your LLM API key as environment variable\n", + "# @title Setup\n", + "#@markdown <-- click the `Run cell` button to\n", + "#@markdown #### 1. Install Vizro-AI\n", + "print(\"Installing vizro-ai\")\n", + "!pip install vizro-ai -q -q -q\n", + "print(\"✅ vizro-ai installed\")\n", + "\n", + "#@markdown #### 2. Secure your LLM API key as environment variable\n", "#@markdown - click the `Secrets` button on the left\n", "#@markdown - click `Add new secret`\n", "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", @@ -77,8 +70,8 @@ " print(\"User defined OPENAI_BASE_URL not set. Using default URL.\")\n", "\n", "print(\"\\nCurrent environment variables:\")\n", - "print(f\"OPENAI_API_KEY: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", - "print(f\"OPENAI_BASE_URL: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set by user, use default'}\")" + "print(f\"OPENAI_API_KEY: {'✅ Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", + "print(f\"OPENAI_BASE_URL: {'✅ Set' if 'OPENAI_BASE_URL' in os.environ else 'Not set by user, use default'}\")" ] }, { @@ -91,25 +84,17 @@ }, "outputs": [], "source": [ - "# @title ## 3. Input your chart question\n", + "# @title ## Set user input\n", "\n", - "# @markdown #### Instructions:\n", - "user_input = 'describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", + "#@markdown <-- click the `Run cell` button to\n", + "#@markdown #### 1. Choose the LLM model\n", "\n", - "print(user_input)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "HJMVfdecTctW", - "metadata": { - "cellView": "form", - "id": "HJMVfdecTctW" - }, - "outputs": [], - "source": [ - "# @title 4. Upload your CSV data (only 1 dataframe accepted per chart)\n", + "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "\n", + "# print(f\"Selected LLM: {LLM}\")\n", + "\n", + "#@markdown ---\n", + "#@markdown #### 2. Upload your CSV data (only 1 dataframe accepted per chart)\n", "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", "\n", @@ -128,24 +113,15 @@ " name=fn, length=len(uploaded[fn])))\n", "\n", " df = pd.read_csv(fn)\n", - "print(f\"Dataframe used for plotting: \\n{df.head()}\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "whPjXfNBTcfg", - "metadata": { - "cellView": "form", - "id": "whPjXfNBTcfg" - }, - "outputs": [], - "source": [ - "# @title 5. Choose the LLM model\n", + "print(f\"Dataframe used for plotting: \\n{df.head()}\")\n", "\n", - "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "#@markdown ---\n", + "#@markdown #### 3. Input your chart question\n", "\n", - "print(f\"Selected LLM: {LLM}\")" + "# @markdown #### Instructions:\n", + "user_input = 'describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", + "\n", + "# print(user_input)" ] }, { @@ -158,7 +134,9 @@ }, "outputs": [], "source": [ - "# @title 6. Create the chart using Vizro-AI\n", + "# @title Create the chart using Vizro-AI\n", + "\n", + "#@markdown <-- click the `Run cell` button to\n", "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", @@ -185,7 +163,8 @@ }, "outputs": [], "source": [ - "# @title 7. Show the chart\n", + "# @title Show the chart\n", + "#@markdown <-- click the `Run cell` button to\n", "button1.result.show()" ] } @@ -214,4 +193,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index b331a5efe..5bc36fed2 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -20,29 +20,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "OSDQDsyCBjSz" - }, - "outputs": [], "source": [ - "# @title 1. Install Vizro-AI\n", + "# @title Setup\n", + "#@markdown <-- click the `Run cell` button to\n", + "#@markdown #### 1. Install Vizro-AI\n", + "print(\"Installing vizro-ai\")\n", "#@markdown (TODO: change to !pip install vizro-ai when this PR is ready to merge)\n", "# !pip install vizro-ai\n", - "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "dc1unu-0pr2M" - }, - "outputs": [], - "source": [ - "# @title 2. Secure your LLM API key as environment variable\n", + "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\" -q -q -q\n", + "print(\"✅ vizro-ai installed\")\n", + "\n", + "#@markdown #### 2. Secure your LLM API key as environment variable\n", "#@markdown - click the `Secrets` button on the left\n", "#@markdown - click `Add new secret`\n", "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", @@ -75,37 +63,30 @@ " print(\"User defined OPENAI_BASE_URL not set. Using default URL.\")\n", "\n", "print(\"\\nCurrent environment variables:\")\n", - "print(f\"OPENAI_API_KEY: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", - "print(f\"OPENAI_BASE_URL: {'Set' if 'OPENAI_API_KEY' in os.environ else 'Not set by user, use default'}\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, + "print(f\"OPENAI_API_KEY: {'✅ Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", + "print(f\"OPENAI_BASE_URL: {'✅ Set' if 'OPENAI_BASE_URL' in os.environ else 'Not set by user, use default'}\")" + ], "metadata": { "cellView": "form", - "id": "bPXCUA7Kpr2P" + "id": "OfhUh-9bxXoD" }, - "outputs": [], - "source": [ - "# @title ## 3. Input your dashboard question\n", - "\n", - "# @markdown #### Instructions:\n", - "user_input = 'Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", - "\n", - "print(user_input)" - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "O_wbhA2zpr2Q" - }, - "outputs": [], "source": [ - "# @title 4. Upload your CSV data\n", + "# @title ## Set user input\n", + "\n", + "#@markdown <-- click the `Run cell` button to\n", + "#@markdown #### 1. Choose the LLM model\n", + "\n", + "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "\n", + "# print(f\"Selected LLM: {LLM}\")\n", + "\n", + "#@markdown ---\n", + "#@markdown #### 2. Upload your CSV data (multiple dataframes accepted)\n", "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", "\n", @@ -127,24 +108,22 @@ " name=fn, length=len(uploaded[fn])))\n", "\n", " df_uploaded = pd.read_csv(fn)\n", - " dfs.append(df_uploaded)" - ] - }, - { - "cell_type": "code", - "execution_count": null, + " dfs.append(df_uploaded)\n", + "\n", + "#@markdown ---\n", + "#@markdown #### 3. Input your chart question\n", + "\n", + "# @markdown #### Instructions:\n", + "user_input = 'Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", + "\n", + "# print(user_input)" + ], "metadata": { "cellView": "form", - "id": "COXftEJEpr2Q" + "id": "60H83HxUyc54" }, - "outputs": [], - "source": [ - "# @title 5. Choose the LLM model\n", - "\n", - "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", - "\n", - "print(f\"Selected LLM: {LLM}\")" - ] + "execution_count": null, + "outputs": [] }, { "cell_type": "code", @@ -159,6 +138,10 @@ "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", + "# from vizro import Vizro\n", + "\n", + "# Vizro._reset()\n", + "# fig = None\n", "\n", "def run_code(button):\n", " from vizro_ai import VizroAI\n", @@ -216,4 +199,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 35c8eb402bca0bd3e5e4b47d2e9c3b7f9d4e844a Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 18:39:24 -0400 Subject: [PATCH 13/24] consolidate cells --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 2 +- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index b56d7f3e7..a29062021 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -193,4 +193,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index 5bc36fed2..aac2270a8 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -199,4 +199,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From b5226221e6a7ac2d6fc8b21135024b80e45fe0bb Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Thu, 8 Aug 2024 22:10:09 -0400 Subject: [PATCH 14/24] use textarea --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 17 ++--- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 69 ++++++++++++++----- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index a29062021..adaf80cd2 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -30,19 +30,20 @@ }, "outputs": [], "source": [ - "# @title Setup\n", + "# @title ## Setup\n", "#@markdown <-- click the `Run cell` button to\n", "#@markdown #### 1. Install Vizro-AI\n", - "print(\"Installing vizro-ai\")\n", + "print(\"Installing dependencies\")\n", + "!pip install \"orjson<3.10.7\" -q -q -q\n", "!pip install vizro-ai -q -q -q\n", - "print(\"✅ vizro-ai installed\")\n", + "print(\"✅ Installation finished\")\n", "\n", "#@markdown #### 2. Secure your LLM API key as environment variable\n", "#@markdown - click the `Secrets` button on the left\n", "#@markdown - click `Add new secret`\n", "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", "#@markdown - insert the API key value under `Value`\n", - "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", + "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its value, based on the requirements from your API key provider.\n", "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", "\n", "import os\n", @@ -134,7 +135,7 @@ }, "outputs": [], "source": [ - "# @title Create the chart using Vizro-AI\n", + "# @title ## Create the chart using Vizro-AI\n", "\n", "#@markdown <-- click the `Run cell` button to\n", "\n", @@ -147,7 +148,7 @@ " vizro_ai = VizroAI()\n", " button1.result = vizro_ai.plot(df, user_input, explain=True)\n", "\n", - "button1 = widgets.Button(description=\"Create chart!\")\n", + "button1 = widgets.Button(description=\"Create chart!\", button_style=\"info\")\n", "display(button1)\n", "\n", "button1.on_click(run_code)" @@ -163,7 +164,7 @@ }, "outputs": [], "source": [ - "# @title Show the chart\n", + "# @title ## Show the chart\n", "#@markdown <-- click the `Run cell` button to\n", "button1.result.show()" ] @@ -193,4 +194,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index aac2270a8..00492e0b0 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -21,21 +21,22 @@ { "cell_type": "code", "source": [ - "# @title Setup\n", + "# @title ## Setup\n", "#@markdown <-- click the `Run cell` button to\n", "#@markdown #### 1. Install Vizro-AI\n", - "print(\"Installing vizro-ai\")\n", + "print(\"Installing dependencies\")\n", "#@markdown (TODO: change to !pip install vizro-ai when this PR is ready to merge)\n", "# !pip install vizro-ai\n", + "!pip install \"orjson<3.10.7\" -q -q -q\n", "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\" -q -q -q\n", - "print(\"✅ vizro-ai installed\")\n", + "print(\"✅ Installation finished\")\n", "\n", "#@markdown #### 2. Secure your LLM API key as environment variable\n", "#@markdown - click the `Secrets` button on the left\n", "#@markdown - click `Add new secret`\n", "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", "#@markdown - insert the API key value under `Value`\n", - "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its values, based on the requirements from your API key provider.\n", + "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its value, based on the requirements from your API key provider.\n", "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", "\n", "import os\n", @@ -86,9 +87,38 @@ "# print(f\"Selected LLM: {LLM}\")\n", "\n", "#@markdown ---\n", - "#@markdown #### 2. Upload your CSV data (multiple dataframes accepted)\n", + "#@markdown #### 2. Input your dashboard question\n", + "#@markdown e.g. \"Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country\"\n", + "from ipywidgets import Textarea, Layout\n", + "from IPython.display import display, HTML\n", + "\n", + "default_user_input = \"\"\"\n", + "Create a 2 page dashboard.\n", + "\n", + " 1 bar chart, 1 filter\n", + "use a bar chart to show the average GDP per continent. Add a filter to filter the bar chart by country.\n", + "\n", + " 1 card, 1 table\n", + "create a card with text \"This is the Gapminder dataset\"\n", + "use a table to show the data details, showing features like GDP and life expectancy.\n", + "\n", + "page 2 layout: Image the page consists 6 grid units horizontally. The card takes 1 unit of the page space on the left and the table takes 5 units on the right.\n", + "\"\"\"\n", + "user_input = Textarea(\n", + " value=default_user_input,\n", + " placeholder='Input your requirements for the dashboard',\n", + " description='user_input:',\n", + " disabled=False,\n", + " rows=10, # This sets the number of visible lines\n", + " layout=Layout(width='auto', height='auto') # This makes the width automatic\n", + ")\n", + "display(user_input)\n", + "display(HTML(\"
\"))\n", + "\n", + "#@markdown ---\n", + "#@markdown #### 3. Upload your CSV data (multiple dataframes accepted)\n", "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", - "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", + "#@markdown - or click `Cancel upload` and use the default example data (plotly gapminder) for initial exploration\n", "\n", "import pandas as pd\n", "from plotly.express.data import gapminder\n", @@ -110,11 +140,6 @@ " df_uploaded = pd.read_csv(fn)\n", " dfs.append(df_uploaded)\n", "\n", - "#@markdown ---\n", - "#@markdown #### 3. Input your chart question\n", - "\n", - "# @markdown #### Instructions:\n", - "user_input = 'Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country' # @param {type:\"string\", placeholder:\"Enter the requirements for the dashboard\"}\n", "\n", "# print(user_input)" ], @@ -134,7 +159,9 @@ }, "outputs": [], "source": [ - "# @title 6. Build the dashboard using Vizro-AI\n", + "# @title ## Build the dashboard using Vizro-AI\n", + "\n", + "#@markdown NOTE: if you encounter the error \"LookupError: `Disconnect and delete runtime` and rerun the notebook\n", "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", @@ -149,13 +176,17 @@ "\n", " Vizro._reset()\n", " vizro_ai = VizroAI(model=LLM)\n", - " dashboard = vizro_ai.dashboard(dfs, user_input)\n", + " dashboard = vizro_ai.dashboard(dfs, user_input.value)\n", "\n", " vizro_dashboard = Vizro().build(dashboard)\n", "\n", " button1.result = vizro_dashboard\n", "\n", - "button1 = widgets.Button(description=\"Build Dashboard!\")\n", + "button1 = widgets.Button(\n", + " description=\"Build Dashboard!\",\n", + " button_style=\"info\",\n", + " tooltip=\"Click to build the dashboard using Vizro-AI\",\n", + " )\n", "display(button1)\n", "\n", "button1.on_click(run_code)" @@ -170,7 +201,7 @@ }, "outputs": [], "source": [ - "# @title 7. Render dashboard\n", + "# @title ## Render dashboard\n", "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", @@ -178,7 +209,11 @@ "def run_dashboard(button):\n", " button1.result.run()\n", "\n", - "button2 = widgets.Button(description=\"Run Dashboard!\")\n", + "button2 = widgets.Button(\n", + " description=\"Run Dashboard!\",\n", + " button_style=\"info\",\n", + " tooltip=\"Click to render the Vizro dashboard\",\n", + " )\n", "display(button2)\n", "\n", "button2.on_click(run_dashboard)" @@ -199,4 +234,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From e7f4406cd9be149f56a0f44540024976a7a2f2aa Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Thu, 8 Aug 2024 22:15:53 -0400 Subject: [PATCH 15/24] lint --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 2 +- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index adaf80cd2..cb9c9eb6b 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -194,4 +194,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb index 00492e0b0..cbff12b28 100644 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb @@ -234,4 +234,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From 8b44327beadbf405331d917682763bbf14dabb20 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Mon, 12 Aug 2024 22:52:59 -0400 Subject: [PATCH 16/24] remove dashboard notebook --- vizro-ai/README.md | 3 +- vizro-ai/examples/dashboard_by_vizro_ai.ipynb | 237 ------------------ 2 files changed, 1 insertion(+), 239 deletions(-) delete mode 100644 vizro-ai/examples/dashboard_by_vizro_ai.ipynb diff --git a/vizro-ai/README.md b/vizro-ai/README.md index 36475a321..6fb7f5bf9 100644 --- a/vizro-ai/README.md +++ b/vizro-ai/README.md @@ -7,8 +7,7 @@ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mckinsey/vizro/blob/main/LICENSE.md) [![Documentation](https://readthedocs.org/projects/vizro-ai/badge/?version=latest)](https://vizro-ai.readthedocs.io/) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7858/badge)](https://www.bestpractices.dev/projects/7858) -[![Create chart In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb) -[![Create dashboard In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/dashboard_by_vizro_ai.ipynb) +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb) Gif to demonstrate vizro-ai diff --git a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb b/vizro-ai/examples/dashboard_by_vizro_ai.ipynb deleted file mode 100644 index cbff12b28..000000000 --- a/vizro-ai/examples/dashboard_by_vizro_ai.ipynb +++ /dev/null @@ -1,237 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "npjw_Cstpr2I" - }, - "source": [ - "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/dashboard_by_vizro_ai.ipynb)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "dsR_4Smypr2L" - }, - "source": [ - "# Use Vizro-AI to generate Vizro dashboard" - ] - }, - { - "cell_type": "code", - "source": [ - "# @title ## Setup\n", - "#@markdown <-- click the `Run cell` button to\n", - "#@markdown #### 1. Install Vizro-AI\n", - "print(\"Installing dependencies\")\n", - "#@markdown (TODO: change to !pip install vizro-ai when this PR is ready to merge)\n", - "# !pip install vizro-ai\n", - "!pip install \"orjson<3.10.7\" -q -q -q\n", - "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\" -q -q -q\n", - "print(\"✅ Installation finished\")\n", - "\n", - "#@markdown #### 2. Secure your LLM API key as environment variable\n", - "#@markdown - click the `Secrets` button on the left\n", - "#@markdown - click `Add new secret`\n", - "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", - "#@markdown - insert the API key value under `Value`\n", - "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its value, based on the requirements from your API key provider.\n", - "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", - "\n", - "import os\n", - "from google.colab import userdata\n", - "\n", - "def safe_get_userdata(key):\n", - " try:\n", - " return userdata.get(key)\n", - " except Exception as e:\n", - " print(f\"Warning: Unable to access {key}. Reason: {str(e)}\")\n", - " return None\n", - "\n", - "# Always try to set the OPENAI_API_KEY\n", - "api_key = safe_get_userdata(\"OPENAI_API_KEY\")\n", - "if api_key:\n", - " os.environ[\"OPENAI_API_KEY\"] = api_key\n", - "else:\n", - " print(\"❌ OPENAI_API_KEY not set. Click `Secrets` icon on the left to setup.\")\n", - "\n", - "# Conditionally set OPENAI_BASE_URL if provided and accessible\n", - "openai_base_url = safe_get_userdata(\"OPENAI_BASE_URL\")\n", - "if openai_base_url:\n", - " os.environ[\"OPENAI_BASE_URL\"] = openai_base_url\n", - "else:\n", - " print(\"User defined OPENAI_BASE_URL not set. Using default URL.\")\n", - "\n", - "print(\"\\nCurrent environment variables:\")\n", - "print(f\"OPENAI_API_KEY: {'✅ Set' if 'OPENAI_API_KEY' in os.environ else 'Not set'}\")\n", - "print(f\"OPENAI_BASE_URL: {'✅ Set' if 'OPENAI_BASE_URL' in os.environ else 'Not set by user, use default'}\")" - ], - "metadata": { - "cellView": "form", - "id": "OfhUh-9bxXoD" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ - "# @title ## Set user input\n", - "\n", - "#@markdown <-- click the `Run cell` button to\n", - "#@markdown #### 1. Choose the LLM model\n", - "\n", - "LLM = 'gpt-4o' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", - "\n", - "# print(f\"Selected LLM: {LLM}\")\n", - "\n", - "#@markdown ---\n", - "#@markdown #### 2. Input your dashboard question\n", - "#@markdown e.g. \"Create a gdp dashboard with 1 page. use a bar chart to show gdp per continent. add a filter to filter data by country\"\n", - "from ipywidgets import Textarea, Layout\n", - "from IPython.display import display, HTML\n", - "\n", - "default_user_input = \"\"\"\n", - "Create a 2 page dashboard.\n", - "\n", - " 1 bar chart, 1 filter\n", - "use a bar chart to show the average GDP per continent. Add a filter to filter the bar chart by country.\n", - "\n", - " 1 card, 1 table\n", - "create a card with text \"This is the Gapminder dataset\"\n", - "use a table to show the data details, showing features like GDP and life expectancy.\n", - "\n", - "page 2 layout: Image the page consists 6 grid units horizontally. The card takes 1 unit of the page space on the left and the table takes 5 units on the right.\n", - "\"\"\"\n", - "user_input = Textarea(\n", - " value=default_user_input,\n", - " placeholder='Input your requirements for the dashboard',\n", - " description='user_input:',\n", - " disabled=False,\n", - " rows=10, # This sets the number of visible lines\n", - " layout=Layout(width='auto', height='auto') # This makes the width automatic\n", - ")\n", - "display(user_input)\n", - "display(HTML(\"
\"))\n", - "\n", - "#@markdown ---\n", - "#@markdown #### 3. Upload your CSV data (multiple dataframes accepted)\n", - "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", - "#@markdown - or click `Cancel upload` and use the default example data (plotly gapminder) for initial exploration\n", - "\n", - "import pandas as pd\n", - "from plotly.express.data import gapminder\n", - "from google.colab import files\n", - "\n", - "uploaded = files.upload()\n", - "\n", - "dfs = []\n", - "\n", - "if not uploaded:\n", - " print(\"No files uploaded. Use the plotly gapminder dataset as an example.\")\n", - " df = gapminder()\n", - " dfs.append(df)\n", - "else:\n", - " for fn in uploaded.keys():\n", - " print('User uploaded file \"{name}\"'.format(\n", - " name=fn, length=len(uploaded[fn])))\n", - "\n", - " df_uploaded = pd.read_csv(fn)\n", - " dfs.append(df_uploaded)\n", - "\n", - "\n", - "# print(user_input)" - ], - "metadata": { - "cellView": "form", - "id": "60H83HxUyc54" - }, - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "rEl8JajAxmMq" - }, - "outputs": [], - "source": [ - "# @title ## Build the dashboard using Vizro-AI\n", - "\n", - "#@markdown NOTE: if you encounter the error \"LookupError: `Disconnect and delete runtime` and rerun the notebook\n", - "\n", - "import ipywidgets as widgets\n", - "from IPython.display import display\n", - "# from vizro import Vizro\n", - "\n", - "# Vizro._reset()\n", - "# fig = None\n", - "\n", - "def run_code(button):\n", - " from vizro_ai import VizroAI\n", - " from vizro import Vizro\n", - "\n", - " Vizro._reset()\n", - " vizro_ai = VizroAI(model=LLM)\n", - " dashboard = vizro_ai.dashboard(dfs, user_input.value)\n", - "\n", - " vizro_dashboard = Vizro().build(dashboard)\n", - "\n", - " button1.result = vizro_dashboard\n", - "\n", - "button1 = widgets.Button(\n", - " description=\"Build Dashboard!\",\n", - " button_style=\"info\",\n", - " tooltip=\"Click to build the dashboard using Vizro-AI\",\n", - " )\n", - "display(button1)\n", - "\n", - "button1.on_click(run_code)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "cellView": "form", - "id": "as5y9yI8x-s5" - }, - "outputs": [], - "source": [ - "# @title ## Render dashboard\n", - "\n", - "import ipywidgets as widgets\n", - "from IPython.display import display\n", - "\n", - "def run_dashboard(button):\n", - " button1.result.run()\n", - "\n", - "button2 = widgets.Button(\n", - " description=\"Run Dashboard!\",\n", - " button_style=\"info\",\n", - " tooltip=\"Click to render the Vizro dashboard\",\n", - " )\n", - "display(button2)\n", - "\n", - "button2.on_click(run_dashboard)" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} From c3f0b105087101aaf2e1dbf46f00ccf6be0ab953 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 13 Aug 2024 00:01:45 -0400 Subject: [PATCH 17/24] add disclaimer --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 35 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index cb9c9eb6b..eec5b678f 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -20,6 +20,26 @@ "# Use Vizro-AI to generate Vizro charts" ] }, + { + "cell_type": "markdown", + "source": [ + "#### Disclaimer: Using Google Colab\n", + "Please read carefully before proceeding:\n", + "\n", + "1. Google's Servers: This notebook runs on Google's servers. Your code and data will be processed and temporarily stored on Google's infrastructure.\n", + "2. Data Privacy: Be mindful of the data you upload or process here. Avoid using sensitive, confidential, or personal information that shouldn't be shared with third parties.\n", + "3. Security Considerations: Colab is a shared environment. While Google implements security measures, treat it as a public environment and act accordingly.\n", + "4. Terms of Service: Ensure your usage complies with Google Colab's Terms of Service and Google Cloud's Terms of Service.\n", + "5. Data Persistence: Data in Colab notebooks is not permanently stored. Save important data and results to your local machine or a secure cloud storage.\n", + "6. Resource Limitations: Colab provides free resources, but these are subject to availability and usage limits.\n", + "\n", + "By using this Colab notebook, you acknowledge that you understand and accept these conditions. Please use Colab at your own discretion and responsibility." + ], + "metadata": { + "id": "zNloarZrwORG" + }, + "id": "zNloarZrwORG" + }, { "cell_type": "code", "execution_count": null, @@ -31,7 +51,7 @@ "outputs": [], "source": [ "# @title ## Setup\n", - "#@markdown <-- click the `Run cell` button to\n", + "#@markdown <-- click the `Run cell` button to activate this cell\n", "#@markdown #### 1. Install Vizro-AI\n", "print(\"Installing dependencies\")\n", "!pip install \"orjson<3.10.7\" -q -q -q\n", @@ -87,10 +107,10 @@ "source": [ "# @title ## Set user input\n", "\n", - "#@markdown <-- click the `Run cell` button to\n", + "#@markdown <-- click the `Run cell` button to activate this cell\n", "#@markdown #### 1. Choose the LLM model\n", "\n", - "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\"]\n", + "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\", \"gpt-4o-mini\"]\n", "\n", "# print(f\"Selected LLM: {LLM}\")\n", "\n", @@ -120,7 +140,7 @@ "#@markdown #### 3. Input your chart question\n", "\n", "# @markdown #### Instructions:\n", - "user_input = 'describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", + "user_input = 'Describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", "\n", "# print(user_input)" ] @@ -137,12 +157,13 @@ "source": [ "# @title ## Create the chart using Vizro-AI\n", "\n", - "#@markdown <-- click the `Run cell` button to\n", + "#@markdown <-- click the `Run cell` button to activate this cell\n", "\n", "import ipywidgets as widgets\n", "from IPython.display import display\n", "\n", "def run_code(button):\n", + " print(\"Running VizroAI...\")\n", " from vizro_ai import VizroAI\n", "\n", " vizro_ai = VizroAI()\n", @@ -165,7 +186,7 @@ "outputs": [], "source": [ "# @title ## Show the chart\n", - "#@markdown <-- click the `Run cell` button to\n", + "#@markdown <-- click the `Run cell` button to activate this cell\n", "button1.result.show()" ] } @@ -194,4 +215,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file From 3cece8924a6ad0428b563e07e72fc1554f98ff7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 04:15:19 +0000 Subject: [PATCH 18/24] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index eec5b678f..297cfe7fc 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -215,4 +215,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} From f66239a127999d99085db1b9babaa700498e7379 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 13 Aug 2024 00:15:37 -0400 Subject: [PATCH 19/24] lint --- vizro-ai/examples/chart_by_vizro_ai.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index eec5b678f..297cfe7fc 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -215,4 +215,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} From d4413c677dad1f5ba12ff2950bfb6e22c7ab07a0 Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Tue, 13 Aug 2024 11:14:08 -0400 Subject: [PATCH 20/24] update readme --- vizro-ai/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vizro-ai/README.md b/vizro-ai/README.md index 6fb7f5bf9..a9e9e7fd5 100644 --- a/vizro-ai/README.md +++ b/vizro-ai/README.md @@ -7,7 +7,6 @@ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mckinsey/vizro/blob/main/LICENSE.md) [![Documentation](https://readthedocs.org/projects/vizro-ai/badge/?version=latest)](https://vizro-ai.readthedocs.io/) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7858/badge)](https://www.bestpractices.dev/projects/7858) -[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/colab-example-chart.ipynb) Gif to demonstrate vizro-ai @@ -20,6 +19,12 @@ It serves as an extension to Vizro, leveraging natural language capabilities to +## Try out live + +| Platform | Chart creation | +| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Google colab | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/chart_by_vizro_ai.ipynb) | + ## Why Vizro-AI? ### Easy-to-use From e0d175742c759fd9e5b461720d47cb570a02536b Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 14 Aug 2024 01:19:00 -0400 Subject: [PATCH 21/24] address comments --- vizro-ai/README.md | 2 +- vizro-ai/examples/chart_by_vizro_ai.ipynb | 140 +++++++++++++--------- 2 files changed, 82 insertions(+), 60 deletions(-) diff --git a/vizro-ai/README.md b/vizro-ai/README.md index a9e9e7fd5..70487c4ab 100644 --- a/vizro-ai/README.md +++ b/vizro-ai/README.md @@ -23,7 +23,7 @@ It serves as an extension to Vizro, leveraging natural language capabilities to | Platform | Chart creation | | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Google colab | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/chart_by_vizro_ai.ipynb) | +| Google Colab | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mckinsey/vizro/blob/docs/add_colab_link/vizro-ai/examples/chart_by_vizro_ai.ipynb) | ## Why Vizro-AI? diff --git a/vizro-ai/examples/chart_by_vizro_ai.ipynb b/vizro-ai/examples/chart_by_vizro_ai.ipynb index 297cfe7fc..745ffc361 100644 --- a/vizro-ai/examples/chart_by_vizro_ai.ipynb +++ b/vizro-ai/examples/chart_by_vizro_ai.ipynb @@ -12,18 +12,18 @@ }, { "cell_type": "markdown", - "id": "fbc65f78", + "source": [ + "#### Disclaimer: Using Google Colab" + ], "metadata": { - "id": "fbc65f78" + "id": "e7qc8VvPyrMC" }, - "source": [ - "# Use Vizro-AI to generate Vizro charts" - ] + "id": "e7qc8VvPyrMC" }, { "cell_type": "markdown", "source": [ - "#### Disclaimer: Using Google Colab\n", + "\n", "Please read carefully before proceeding:\n", "\n", "1. Google's Servers: This notebook runs on Google's servers. Your code and data will be processed and temporarily stored on Google's infrastructure.\n", @@ -36,9 +36,46 @@ "By using this Colab notebook, you acknowledge that you understand and accept these conditions. Please use Colab at your own discretion and responsibility." ], "metadata": { - "id": "zNloarZrwORG" + "id": "yMDU0UZqyfDc" }, - "id": "zNloarZrwORG" + "id": "yMDU0UZqyfDc" + }, + { + "cell_type": "markdown", + "source": [ + "#### Setup the LLM API key" + ], + "metadata": { + "id": "6Och8D7u0ovX" + }, + "id": "6Och8D7u0ovX" + }, + { + "cell_type": "markdown", + "source": [ + "Secure your LLM API key as environment variable\n", + "- click the `Secrets` button on the left\n", + "- click `Add new secret`\n", + "- insert \"OPENAI_API_KEY\" under `Name`\n", + "- insert the API key value under `Value` (use raw string without quote. e.g., `xyz` instead of `\"xyz\"`)\n", + "- [optional] you might also need to insert \"OPENAI_BASE_URL\" and its value, based on the requirements from your API key provider (use raw string without quote. e.g., `xyz` instead of `\"xyz\"`)\n", + "- click the `Notebook access` toggle to make it available for the notebook run\n" + ], + "metadata": { + "id": "FlndiROX0bmX" + }, + "id": "FlndiROX0bmX" + }, + { + "cell_type": "markdown", + "id": "fbc65f78", + "metadata": { + "id": "fbc65f78" + }, + "source": [ + "# Use Vizro-AI to generate Vizro charts\n", + "# **At the top of this notebook, click `Runtime` -> `Run all`**" + ] }, { "cell_type": "code", @@ -51,21 +88,12 @@ "outputs": [], "source": [ "# @title ## Setup\n", - "#@markdown <-- click the `Run cell` button to activate this cell\n", "#@markdown #### 1. Install Vizro-AI\n", "print(\"Installing dependencies\")\n", - "!pip install \"orjson<3.10.7\" -q -q -q\n", - "!pip install vizro-ai -q -q -q\n", + "!pip install \"vizro-ai @ git+https://github.com/mckinsey/vizro.git@main#subdirectory=vizro-ai\" -q -q -q\n", "print(\"✅ Installation finished\")\n", "\n", - "#@markdown #### 2. Secure your LLM API key as environment variable\n", - "#@markdown - click the `Secrets` button on the left\n", - "#@markdown - click `Add new secret`\n", - "#@markdown - insert \"OPENAI_API_KEY\" under `Name`\n", - "#@markdown - insert the API key value under `Value`\n", - "#@markdown - [optional] you might also need to insert \"OPENAI_BASE_URL\" and its value, based on the requirements from your API key provider.\n", - "#@markdown - click the `Notebook access` toggle to make it available for the notebook run\n", - "\n", + "#@markdown #### 2. Setup LLM API access\n", "import os\n", "from google.colab import userdata\n", "\n", @@ -105,17 +133,9 @@ }, "outputs": [], "source": [ - "# @title ## Set user input\n", - "\n", - "#@markdown <-- click the `Run cell` button to activate this cell\n", - "#@markdown #### 1. Choose the LLM model\n", + "# @title ## Data upload\n", "\n", - "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\", \"gpt-4o-mini\"]\n", - "\n", - "# print(f\"Selected LLM: {LLM}\")\n", - "\n", - "#@markdown ---\n", - "#@markdown #### 2. Upload your CSV data (only 1 dataframe accepted per chart)\n", + "#@markdown #### Upload your CSV data (only 1 dataframe accepted per chart)\n", "#@markdown - click `Choose Files` if you'd like to upload and use your own data\n", "#@markdown - or click `Cancel upload` and use the default example data for initial exploration\n", "\n", @@ -135,14 +155,7 @@ "\n", " df = pd.read_csv(fn)\n", "print(f\"Dataframe used for plotting: \\n{df.head()}\")\n", - "\n", - "#@markdown ---\n", - "#@markdown #### 3. Input your chart question\n", - "\n", - "# @markdown #### Instructions:\n", - "user_input = 'Describe the composition of gdp in continent' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", - "\n", - "# print(user_input)" + "\n" ] }, { @@ -155,45 +168,54 @@ }, "outputs": [], "source": [ - "# @title ## Create the chart using Vizro-AI\n", + "# @title ## Input the LLM model choice and user prompt { run: \"auto\" }\n", "\n", - "#@markdown <-- click the `Run cell` button to activate this cell\n", + "#@markdown #### 1. Choose the LLM model\n", "\n", - "import ipywidgets as widgets\n", - "from IPython.display import display\n", + "LLM = 'gpt-3.5-turbo' # @param [\"gpt-4o\", \"gpt-3.5-turbo\", \"gpt-4-turbo\", \"gpt-4o-mini\"]\n", "\n", - "def run_code(button):\n", - " print(\"Running VizroAI...\")\n", - " from vizro_ai import VizroAI\n", + "print(f\"Selected LLM: {LLM}\")\n", "\n", - " vizro_ai = VizroAI()\n", - " button1.result = vizro_ai.plot(df, user_input, explain=True)\n", + "#@markdown ---\n", + "#@markdown #### 2. Input your chart question\n", "\n", - "button1 = widgets.Button(description=\"Create chart!\", button_style=\"info\")\n", - "display(button1)\n", + "# @markdown #### Instructions:\n", + "user_input = 'Describe the composition of gdp in continent.' # @param {type:\"string\", placeholder:\"Enter the requirements for the chart\"}\n", "\n", - "button1.on_click(run_code)" + "print(f\"User input: {user_input}\")" ] }, { "cell_type": "code", - "execution_count": null, - "id": "B9P0eNoqc7gd", + "source": [ + "from pickle import TRUE\n", + "# @title ## Create the chart using Vizro-AI\n", + "\n", + "print(\"Running VizroAI...\")\n", + "from vizro_ai import VizroAI\n", + "\n", + "vizro_ai = VizroAI()\n", + "result = vizro_ai.plot(df, user_input, return_elements=TRUE)\n", + "\n", + "print(\"✅ VizroAI finished\")\n", + "print(\"\\n-----\\nCode:\\n-----\\n\")\n", + "print(result.code)\n", + "print(\"\\n-------\\nFigure:\\n-------\\n\")\n", + "result.figure.show()" + ], "metadata": { "cellView": "form", - "id": "B9P0eNoqc7gd" + "id": "O-LSNhSA7j3r" }, - "outputs": [], - "source": [ - "# @title ## Show the chart\n", - "#@markdown <-- click the `Run cell` button to activate this cell\n", - "button1.result.show()" - ] + "id": "O-LSNhSA7j3r", + "execution_count": null, + "outputs": [] } ], "metadata": { "colab": { - "provenance": [] + "provenance": [], + "toc_visible": true }, "kernelspec": { "display_name": "Python 3 (ipykernel)", From 24c3af96033f2893c25766577dd8932ed5717b3b Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 14 Aug 2024 22:33:49 -0400 Subject: [PATCH 22/24] address comments --- ...20240807_005926_lingyi_zhang_add_colab_link.md | 5 ++--- vizro-ai/examples/chart_by_vizro_ai.ipynb | 15 +++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md b/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md index f1f65e73c..b684eadb5 100644 --- a/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md +++ b/vizro-ai/changelog.d/20240807_005926_lingyi_zhang_add_colab_link.md @@ -16,12 +16,11 @@ Uncomment the section that is right (remove the HTML comment wrapper). - A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) --> -