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
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'
towhee/models/clip/clip.py