From 54f66c0730cf8197db8a4b1f7bb77e063338b8ab Mon Sep 17 00:00:00 2001 From: Lingyi Zhang Date: Wed, 7 Aug 2024 18:38:43 -0400 Subject: [PATCH] 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