code: def _save_model_and_config_for_hf_hub(
      model: Any, save_dir: str, arch: str, task: str
  ) -> None:
      """Save model and config to disk for pushing to huggingface hub
  
      Args:
      ----
          model: TF or PyTorch model to be saved
          save_dir: directory to save model and config
          arch: architecture name
          task: task name
      """
      save_directory = Path(save_dir)
  
      if is_torch_available():
          weights_path = save_directory / "pytorch_model.bin"
          torch.save(model.state_dict(), weights_path)
      elif is_tf_available():
          weights_path = save_directory / "tf_model" / "weights"
          model.save_weights(str(weights_path))
  
      config_path = save_directory / "config.json"
  
      # add model configuration
      model_config = model.cfg
      model_config["arch"] = arch
      model_config["task"] = task
  
      with config_path.open("w") as f:
          json.dump(model_config, f, indent=2, ensure_ascii=False)
  
file_path: doctr/doctr/models/factory/hub.py
imports: import json
  import logging
  import os
  import subprocess
  import textwrap
  from pathlib import Path
  from typing import Any
  from huggingface_hub import HfApi, Repository, get_token, get_token_permission, hf_hub_download, login, snapshot_download
  from doctr import models
  from doctr.file_utils import is_tf_available, is_torch_available
label_desc: Use image node_id 2 for calling a global function with example usage: _save_model_and_config_for_hf_hub(model, save_dir, arch, task) without return types