Skip to content

How to run Vizro-AI

This guide offers insights into different options of running Vizro-AI, including Jupyter notebook, Python scripts, and integration into your applications.

1. Jupyter notebook

To run Vizro-AI in jupyter, create a new cell and execute the code below to render the described visualization. You should see the chart as an output.

Note: API key

Make sure you have followed the environment setup guide and your api key is set up in a .env file in the same folder as your ipynb file.

Bar chart

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")

BarChart

Please note that the chart's appearance may not precisely resemble the one displayed below, as it is generated by a generative AI and can vary.

2. Python script

You can utilize Vizro-AI in any standard development environment by creating a .py file and executing the following code. As a result, the rendered chart will display in a browser window.

Note: API key

Make sure you have followed environment setup guide and your API key is set up in the environment where your .py script is running with command as below:

export OPENAI_API_KEY="your api key"

Line chart

import vizro.plotly.express as px
from vizro_ai import VizroAI

vizro_ai = VizroAI()

df = px.data.gapminder()
vizro_ai.plot(df, "describe life expectancy per continent over time")

LineChart

3. Application integration

You have the possibility to integrate Vizro-AI into your application. For example, this can be achieved through a frontend that allows users to input prompts using a text field.

Vizro-AI's _get_chart_code method returns the Python code string that can be used to prepare the data and create the visualization. This code is validated and debugged to ensure that it is executable and ready to be integrated.

Application integration

import vizro.plotly.express as px
from vizro_ai import VizroAI

vizro_ai = VizroAI()

df = px.data.gapminder()
code_string = vizro_ai._get_chart_code(df, "describe life expectancy per continent over time")

ResultCode

The returned code_string can be used to dynamically render charts within your application. You may have the option to encapsulate the chart within a fig object or convert the figure into a JSON string for further integration. In case you would like to use the insights or code explanation, you can use vizro_ai._run_plot_tasks(df, ..., explain=True), which returns a dictionary containing the code explanation and chart insights alongside the code.

4. max_debug_retry parameter in plot function

  • Default Value: 3
  • Type: int
  • Brief: By default, the max_debug_retry is set to 3, the function will attempt to debug errors up to three times. If the errors are not resolved after the maximum number of retries, the function will cease further debugging attempts. E.g. if you would like adjust to 5 debugging attempts, you can set max_debug_retry = 5 in the plot function:
     vizro_ai.plot(df = df, user_input = "your user input", max_debug_retry= 5)