From 1e994233b6c4e6559b2fdcbf0e88d968a100f240 Mon Sep 17 00:00:00 2001 From: pharmapsychotic Date: Fri, 20 Dec 2024 18:56:06 -0600 Subject: [PATCH] auto download model from huggingface --- __init__.py | 12 ++++++++++-- requirements.txt | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/__init__.py b/__init__.py index 6f749b3..e928b76 100644 --- a/__init__.py +++ b/__init__.py @@ -6,13 +6,13 @@ from typing import List import torch import torch.nn as nn import torch.nn.functional as F +from huggingface_hub import hf_hub_download from safetensors import safe_open from transformers import CLIPTokenizer import comfy.model_management import comfy.sample import comfy.utils -import folder_paths class DecoderBlock(nn.Module): @@ -447,8 +447,16 @@ class CLIPtionLoader: def load(self, clip, clip_vision): state_dict = {} + file = "CLIPtion_20241219_fp16.safetensors" base_path = os.path.dirname(os.path.abspath(__file__)) - model_path = os.path.join(base_path, "CLIPtion_20241219_fp16.safetensors") + if os.path.exists(os.path.join(base_path, file)): + model_path = os.path.join(base_path, file) + else: + repo_id = "pharmapsychotic/CLIPtion" + revision = "15ee8cb77a902616478a033332011ff640e72277" + model_path = hf_hub_download( + repo_id=repo_id, filename=file, revision=revision + ) with safe_open(model_path, framework="pt", device="cpu") as f: for key in f.keys(): state_dict[key] = f.get_tensor(key) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cff171e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +huggingface-hub +safetensors +transformers \ No newline at end of file