Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve custom visualization docs #2855

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ To create visualizations, you need to:

As an example, check out the implementation of the [zenml.materializers.NumpyMaterializer](https://github.com/zenml-io/zenml/blob/main/src/zenml/materializers/numpy\_materializer.py) that use matplotlib to automatically save or plot certain arrays.

Read more about visualizations [here](visualize-artifacts.md).
Read more about visualizations [here](../visualize-artifacts/creating-custom-visualizations.md).

#### (Optional) Which Metadata to Extract for the Artifact

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ description: Creating your own visualizations.

# Creating Custom Visualizations

It is simple to associate a custom visualization with an artifact in ZenML, if
the visualization is one of the supported visualization types.
Currently, the following visualization types are supported:

* **HTML:** Embedded HTML visualizations such as data validation reports,
* **Image:** Visualizations of image data such as Pillow images (e.g. `PIL.Image`) or certain numeric numpy arrays,
* **CSV:** Tables, such as the pandas DataFrame `.describe()` output,
* **Markdown:** Markdown strings or pages.

There are two ways how you can add custom visualizations to the dashboard:

* If you are already handling HTML, Markdown, or CSV data in one of your steps, you can have them visualized in just a few lines of code by casting them to a [special class](#visualization-via-special-return-types) inside your step.
Expand Down Expand Up @@ -31,13 +40,15 @@ def my_step() -> CSVString:

This would create the following visualization in the dashboard:

![CSV Visualization Example](../../.gitbook/assets/artifact\_visualization\_csv.png)
![CSV Visualization Example](../../.gitbook/assets/artifact_visualization_csv.png)

## Visualization via Materializers

If you want to automatically extract visualizations for all artifacts of a certain data type, you can do so by overriding the `save_visualizations()` method of the corresponding materializer. See the [materializer docs page](../handle-data-artifacts/handle-custom-data-types.md#optional-how-to-visualize-the-artifact) for more information on how to create custom materializers that do this.

## Visualization via Custom Return Type and Materializer
Or, see a code example on [GitHub](https://github.com/zenml-io/zenml/blob/main/src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py) where we visualize Hugging Face datasets by embedding their preview viewer.

## How to think about creating a custom visualization

By combining the ideas behind the above two visualization approaches, you can visualize virtually anything you want inside your ZenML dashboard in three simple steps:

Expand Down
11 changes: 6 additions & 5 deletions docs/book/how-to/visualize-artifacts/types-of-visualizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ Alternatively, any of these visualizations can also be displayed in Jupyter note

![output.visualize() Output](../../.gitbook/assets/artifact_visualization_evidently.png)

Currently, the following visualization types are supported:
Some examples of default visualizations are:

* **HTML:** Embedded HTML visualizations such as data validation reports,
* **Image:** Visualizations of image data such as Pillow images or certain numeric numpy arrays,
* **CSV:** Tables, such as the pandas DataFrame `.describe()` output,
* **Markdown:** Markdown strings or pages.
- A statistical representation of a [Pandas](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) Dataframe represented as a png image.
- Drift detection reports by [Evidently](../../component-guide/data-validators/evidently.md), [Great Expectations](../../component-guide/data-validators/great-expectations.md), and [whylogs](../../component-guide/data-validators/whylogs.md).
- A [Hugging Face](https://zenml.io/integrations/huggingface) datasets viewer embedded as a HTML iframe.
-
![output.visualize() output for the Hugging Face datasets viewer](../../.gitbook/assets/artifact_visualization_huggingface.gif)

<figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure>