Skip to content

Commit

Permalink
consolidate cells
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyielia committed Aug 7, 2024
1 parent 68836ba commit 54f66c0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 113 deletions.
85 changes: 32 additions & 53 deletions vizro-ai/examples/chart_by_vizro_ai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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'}\")"
]
},
{
Expand All @@ -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",
Expand All @@ -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)"
]
},
{
Expand All @@ -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",
Expand All @@ -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()"
]
}
Expand Down Expand Up @@ -214,4 +193,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
103 changes: 43 additions & 60 deletions vizro-ai/examples/dashboard_by_vizro_ai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -216,4 +199,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}

0 comments on commit 54f66c0

Please sign in to comment.