run-vizro-ai.md•2.85 kB
# How to run Vizro-AI
This guide offers insights into different ways of running `VizroAI.plot` to generate Plotly charts. We cover how to use:
- [a Jupyter Notebook](#jupyter-notebook)
- [a Python script](#python-script)
- [integration into an application](#application-integration)
## Jupyter Notebook
To run Vizro-AI code in a Jupyter Notebook, create a new cell and execute the code below to render the described visualization as output.
??? note "Note: API key"
Make sure you have followed the [LLM setup guide](../user-guides/install.md#set-up-access-to-a-large-language-model) and that your api key is set up in a `.env` file in the same folder as your Notebook file (`.ipynb`).
!!! example "Ask Vizro-AI to generate a bar chart"
=== "Code for the cell"
```py
import vizro.plotly.express as px
from vizro_ai import VizroAI
vizro_ai = VizroAI()
df = px.data.gapminder()
vizro_ai.plot(df, "visualize the life expectancy per continent and color each continent")
```
=== "Result"
[![BarChart]][barchart]
Note that if you run this code, its appearance may not precisely resemble the one displayed, as it is generated by a generative AI and can vary.
## Python script
You can use Vizro-AI in any standard development environment by creating a `.py` file and executing the code, which displays the output in a browser window. As Vizro-AI returns the `fig` object, you need to append `fig.show()` to the response object.
??? note "Note: API key"
Make sure you have followed [LLM setup guide](../user-guides/install.md#set-up-access-to-a-large-language-model) and that your API key is set up in the environment where your `.py` script is running with command as below:
```bash
export OPENAI_API_KEY="your api key"
```
!!! example "Ask Vizro-AI to generate a line chart"
=== "example.py"
```py
import vizro.plotly.express as px
from vizro_ai import VizroAI
vizro_ai = VizroAI()
df = px.data.gapminder()
fig = vizro_ai.plot(df, "describe life expectancy per continent over time")
fig.show()
```
=== "Result"
[![LineChart]][linechart]
## Application integration
You may prefer to integrate Vizro-AI into an application that offers a UI for users to input prompts. For that you can take the `fig` object from the `.plot` call, and use it elsewhere in any application (you might also want to process it further, for example, by serializing it or similar). It is also possible to obtain the code that would produce the object. For any advanced usage options, refer to [our advanced options guide](advanced-options.md).
[barchart]: ../../assets/user_guides/bar_chart_gdp_per_continent.png
[linechart]: ../../assets/user_guides/line_chart_life_expect.png