code: def create_model(
      model_name: str = None,
      pretrained: bool = False,
      weights_path: str = None,
      jit: bool = False,
      device: str = None,
      **kwargs,
  ) -> CLIP:
      """
      Create a CLIP model.
      Args:
          model_name (`str`):
              CLIP model name, can be one of 'clip_resnet_r50', 'clip_resnet_r101', 'clip_vit_b16', 'clip_vit_b32'
          pretrained (`bool`):
              Whether to load pretrained weights.
          weights_path (`str`):
              Path to the weights file.
          jit (`bool`):
              Whether returned one is a jit model, only useful when `pretrained` is True.
          device (`str`):
              Model device to use.
          **kwargs (`dict`):
              Extra arguments to pass to the model.
  
      Returns:
          model (`CLIP`):
              The CLIP model.
  
      >>> from towhee.models import clip
      >>> model = clip.create_model("clip_resnet_r50")
      >>> model.__class__.__name__
      'CLIP'
      """
      if device is None:
          device = "cuda" if torch.cuda.is_available() else "cpu"
  
      if model_name is None:
          if pretrained:
              raise AttributeError(
                  "Fail to load pretrained model: no model name is specified."
              )
          model = CLIP(**kwargs).to(device)
      else:
          configs = get_configs(model_name)
          configs.update(**kwargs)
          if "url" in configs:
              url = configs["url"]
              configs.pop("url")
          model = CLIP(**configs).to(device)
  
          if pretrained:
              if weights_path:
                  local_path = weights_path
              elif url:
                  cache_dir = os.path.expanduser("~/.cache/clip")
                  local_path = download_from_url(
                      url=url, root=cache_dir, hash_prefix="default"
                  )
              else:
                  raise AttributeError(
                      "No url or local path is provided for pretrained model."
                  )
  
              try:
                  try:
                      import torchvision  # pylint: disable=unused-import, import-outside-toplevel
                  except ModuleNotFoundError:
                      warnings.warn(
                          "Additional package is required for jit: torchvision"
                      )
  
                  # loading JIT archive
                  model = torch.jit.load(
                      local_path, map_location=device
                  ).eval()
                  state_dict = model.state_dict()
              except RuntimeError:
                  # loading saved state dict
                  if jit:
                      warnings.warn(
                          f"File {local_path} is not a JIT archive. Loading as a state dict instead"
                      )
                      jit = False
                  state_dict = torch.load(
                      local_path, map_location="cpu"
                  )
  
              if not jit:
                  clip_model = CLIP(**configs).to(device)
                  for key in [
                      "input_resolution",
                      "context_length",
                      "vocab_size",
                  ]:
                      if key in state_dict:
                          del state_dict[key]
  
                  convert_weights(model)
                  clip_model.load_state_dict(state_dict)
                  model = clip_model
                  model.eval()
                  if str(device) == "cpu":
                      model.float()
              else:
                  patch_device(model, device)
                  if device == "cpu":
                      patch_float(model)
      return model
  
imports: import os
  import warnings
  from collections import OrderedDict
  from typing import Tuple, Union, Callable
  import numpy
  from PIL import Image
  import torch
  from torch import nn
  from torchvision.transforms import Compose, Resize, CenterCrop, ToTensor, Normalize
  from towhee.models.utils.download import download_from_url
  from towhee.models.clip.clip_utils import get_configs, convert_weights, patch_device, patch_float, tokenize
  from towhee.models.clip.auxilary import multi_head_attention_forward, MultiheadAttention
label_desc: Use image node_id 2 for calling a global function with example usage: create_model(model_name, pretrained, weights_path, jit, device) and returns: model