-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5652f6e
commit 7f9b198
Showing
2 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |