Vertex AI Pipelines 提供一組預先定義的視覺化類型,用於評估 pipeline 工作的結果 (例如 Metrics、ClassificationMetrics)。不過,在許多情況下,您需要自訂視覺化效果。Vertex AI Pipelines 提供兩種主要方法,可輸出自訂視覺化構件:Markdown 和 HTML 檔案。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Output HTML and Markdown\n\nVertex AI Pipelines provides a set of predefined visualization types\nfor evaluating the result of a pipeline job (for example, `Metrics`,\n`ClassificationMetrics`). However, there are many cases where custom\nvisualization is needed. Vertex AI Pipelines provides two main\napproaches to output custom visualization artifacts: Markdown and HTML files.\n\n### Import required dependencies\n\nIn your development environment import the required dependencies. \n\n from kfp import dsl\n from kfp.dsl import (\n Output,\n HTML,\n Markdown\n )\n\n### Output HTML\n\nTo export an HTML file, define a component with the `Output[HTML]` artifact.\nYou also must write HTML content to the artifact's path. In this example you\nuse a string variable to represent HTML content.\n\n\n| **Note:** HTML and Markdown files are stored under the `pipeline_root` path in Cloud Storage. You must have sufficient permission to the Cloud Storage bucket to view visualization content.\n\n\u003cbr /\u003e\n\n @dsl.component\n def html_visualization(html_artifact: Output[HTML]):\n public_url = 'https://user-images.githubusercontent.com/37026441/140434086-d9e1099b-82c7-4df8-ae25-83fda2929088.png'\n html_content = \\\n '\u003chtml\u003e\u003chead\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eGlobal Feature Importance\u003c/h1\u003e\\n\u003cimg src=\"{}\" width=\"97%\"/\u003e\u003c/body\u003e\u003c/html\u003e'.format(public_url)\n with open(html_artifact.path, 'w') as f:\n f.write(html_content)\n\n**HTML artifact in the Google Cloud console:**\n\n**HTML artifact information in the Google Cloud console:**\n\n**Click \"View HTML\" to open HTML file on a new tab**\n\n### Output Markdown\n\nTo export a Markdown file, define a component with the `Output[Markdown]`\nartifact. You also must write Markdown content to the artifact's path. In this\nexample you use a string variable to represent Markdown content.\n\n\n| **Note:** HTML and Markdown files are stored under the `pipeline_root` path in Cloud Storage. You must have sufficient permission to the Cloud Storage bucket to view visualization content.\n\n\u003cbr /\u003e\n\n @dsl.component\n def markdown_visualization(markdown_artifact: Output[Markdown]):\n import urllib.request\n\n with urllib.request.urlopen('https://gist.githubusercontent.com/zijianjoy/a288d582e477f8021a1fcffcfd9a1803/raw/68519f72abb59152d92cf891b4719cd95c40e4b6/table_visualization.md') as table:\n markdown_content = table.read().decode('utf-8')\n with open(markdown_artifact.path, 'w') as f:\n f.write(markdown_content)\n\n**Markdown artifact in the Google Cloud console:**\n\n**Markdown artifact information in the Google Cloud console:**\n\n### Create your pipeline\n\nAfter you have defined your component with the HTML or Markdown artifact create\nand run a pipeline that use the component. \n\n @dsl.pipeline(\n name=f'metrics-visualization-pipeline')\n def metrics_visualization_pipeline():\n html_visualization_op = html_visualization()\n markdown_visualization_op = markdown_visualization()\n\nAfter submitting the pipeline run, you can view the graph for this run in\nthe Google Cloud console. This graph includes the HTML and Markdown artifacts\nyou declared in corresponding components. You can select these artifacts\nto view detailed visualization."]]