Skip to content

Commit

Permalink
add dashboard nb
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyielia committed Aug 7, 2024
1 parent 5652f6e commit 7f9b198
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vizro-ai/examples/colab-example-chart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"id": "fbc65f78",
"metadata": {},
"source": [
"# Use Vizro-AI in Google Colab"
"# Use Vizro-AI to generate Vizro charts"
]
},
{
Expand All @@ -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,
Expand Down
182 changes: 182 additions & 0 deletions vizro-ai/examples/colab-example-dashboard.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7f9b198

Please sign in to comment.