class_docstr: ModelCardToolkit provides utilities to generate a ModelCard.
  
  ModelCardToolkit is a tool for ML practitioners to create Model Cards,
  documentation for model information such as owners, use cases, training and
  evaluation data, performance, etc. A Model Card document can be displayed in
  output formats including HTML, Markdown, etc.
  
  The ModelCardToolkit includes an API designed for a human-in-the-loop process
  to elaborate the ModelCard. If model training is integrated with ML Metadata
  (e.g., TFX pipelines), the ModelCardToolkit can further populate ModelCard
  fields by extract metadata and lineage from the model's MLMD instance.
  
  The ModelCardToolkit organizes the ModelCard assets (e.g., structured data,
  plots, and UI templates) in a user-specified directory, and updates them
  incrementally via its API.
  
  
  Standard workflow:
  
  ```python
  import model_card_toolkit as mct
  
  # Initialize the Model Card Toolkit with a path to store generate assets
  model_card_dir_path = ...
  toolkit = mct.ModelCardToolkit(model_card_dir_path)
  
  # Initialize the ModelCard, which can be freely populated
  model_card = toolkit.scaffold_assets()
  model_card.model_details.name = 'My Model'
  
  # Write the model card data to a proto file
  toolkit.update_model_card(model_card)
  
  # Return the model card document as an HTML page
  html = toolkit.export_format()
  ```
class_docstr_tok: ["ModelCardToolkit","provides","utilities","to","generate","a","ModelCard",".","ModelCardToolkit","is","a","tool","for","ML","practitioners","to","create","Model","Cards",",","documentation","for","model","information","such","as","owners",",","use","cases",",","training","and","evaluation","data",",","performance",",","etc",".","A","Model","Card","document","can","be","displayed","in","output","formats","including","HTML",",","Markdown",",","etc",".","The","ModelCardToolkit","includes","an","API","designed","for","a","human-in-the-loop","process","to","elaborate","the","ModelCard",".","If","model","training","is","integrated","with","ML","Metadata","(","e.g.",",","TFX","pipelines",")",",","the","ModelCardToolkit","can","further","populate","ModelCard","fields","by","extract","metadata","and","lineage","from","the","model","'s","MLMD","instance",".","The","ModelCardToolkit","organizes","the","ModelCard","assets","(","e.g.",",","structured","data",",","plots",",","and","UI","templates",")","in","a","user-specified","directory",",","and","updates","them","incrementally","via","its","API",".","Standard","workflow",":","``","`","python","import","model_card_toolkit","as","mct","#","Initialize","the","Model","Card","Toolkit","with","a","path","to","store","generate","assets","model_card_dir_path","=","...","toolkit","=","mct.ModelCardToolkit","(","model_card_dir_path",")","#","Initialize","the","ModelCard",",","which","can","be","freely","populated","model_card","=","toolkit.scaffold_assets","(",")","model_card.model_details.name","=","'My","Model'","#","Write","the","model","card","data","to","a","proto","file","toolkit.update_model_card","(","model_card",")","#","Return","the","model","card","document","as","an","HTML","page","html","=","toolkit.export_format","(",")","``","`"]
docstr: Generates a model card document based on the MCT assets.
  
  The model card document is both returned by this function, as well as saved
  to output_file.
  
  Args:
    model_card: The ModelCard object, generated from `scaffold_assets()`. If
      not provided, it will be read from the ModelCard proto file in the
      assets directory.
    template_path: The file path of the Jinja template. If not provided, the
      default template will be used.
    output_file: The file name of the generated model card. If not provided,
      the default 'model_card.html' will be used. If the file already exists,
      then it will be overwritten.
    template_variables: A dictionary of variables to pass to the template in
      addition to model card fields.
  
  Returns:
    The model card file content.
  
  Raises:
    ValueError: If `export_format` is called before `scaffold_assets` has
      generated model card assets.
docstr_tok: ["Generates","a","model","card","document","based","on","the","MCT","assets",".","The","model","card","document","is","both","returned","by","this","function",",","as","well","as","saved","to","output_file",".","Args",":","model_card",":","The","ModelCard","object",",","generated","from","`","scaffold_assets","(",")","`",".","If","not","provided",",","it","will","be","read","from","the","ModelCard","proto","file","in","the","assets","directory",".","template_path",":","The","file","path","of","the","Jinja","template",".","If","not","provided",",","the","default","template","will","be","used",".","output_file",":","The","file","name","of","the","generated","model","card",".","If","not","provided",",","the","default","'model_card.html","'","will","be","used",".","If","the","file","already","exists",",","then","it","will","be","overwritten",".","template_variables",":","A","dictionary","of","variables","to","pass","to","the","template","in","addition","to","model","card","fields",".","Returns",":","The","model","card","file","content",".","Raises",":","ValueError",":","If","`","export_format","`","is","called","before","`","scaffold_assets","`","has","generated","model","card","assets","."]
code: def export_format(
      self,
      model_card: Optional[
          Union[ModelCard, model_card_pb2.ModelCard]
      ] = None,
      template_path: Optional[str] = None,
      output_file: Optional[str] = None,
      template_variables: Optional[Dict[str, Any]] = None,
  ) -> str:
      """Generates a model card document based on the MCT assets.
  
      The model card document is both returned by this function, as well as saved
      to output_file.
  
      Args:
        model_card: The ModelCard object, generated from `scaffold_assets()`. If
          not provided, it will be read from the ModelCard proto file in the
          assets directory.
        template_path: The file path of the Jinja template. If not provided, the
          default template will be used.
        output_file: The file name of the generated model card. If not provided,
          the default 'model_card.html' will be used. If the file already exists,
          then it will be overwritten.
        template_variables: A dictionary of variables to pass to the template in
          addition to model card fields.
  
      Returns:
        The model card file content.
  
      Raises:
        ValueError: If `export_format` is called before `scaffold_assets` has
          generated model card assets.
      """
      if not template_path:
          template_path = self.default_template
      if not output_file:
          output_file = _DEFAULT_MODEL_CARD_FILE_NAME
  
      # If model_card is passed in, write to Proto file.
      if model_card:
          self.update_model_card(model_card)
      # If model_card is not passed in, read from Proto file.
      else:
          try:
              model_card = load_model_card(self._mcta_proto_file)
          except FileNotFoundError as e:
              raise ValueError(
                  "ModelCard proto file could not be found. "
                  "Call scaffold_assets() to generate a Model Card."
              ) from e
  
      # Generate model card document.
      model_card_file_content = model_card.render(
          template_path=template_path,
          output_path=os.path.join(self._model_cards_dir, output_file),
          template_variables=template_variables,
      )
  
      return model_card_file_content
  
file_path: model-card-toolkit/model_card_toolkit/core.py
imports: import logging
  import os
  import pkgutil
  import tempfile
  from typing import Any, Dict, Optional, Union
  from model_card_toolkit import dependencies
  from model_card_toolkit.model_card import ModelCard, load_model_card
  from model_card_toolkit.proto import model_card_pb2
  from model_card_toolkit.utils import io_utils
label_desc: Use image node_id 9 for calling the ModelCardToolkit obj's underlying member method code with example usage: obj.export_format(model_card, template_path, output_file, template_variables) and returns: model_card_file_content