File size: 2,177 Bytes
68c610c 778217e 409f4de 68c610c 778217e ad89604 778217e 005427c 778217e 409f4de 778217e 409f4de 3f13ec4 778217e 005427c 409f4de 778217e 3c8351b 778217e 3f13ec4 3c8351b 3f13ec4 ad89604 778217e 3f13ec4 778217e 409f4de 3f13ec4 778217e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import os
from huggingface_hub import HfApi
import folder_paths
class MilaHFSync:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {"required": {
"workflow_name": ("STRING", {"default": "t2i_k4b_d_simple_1.json"}),
"token_path": ("STRING", {"default": "/content/ComfyUI/mila_token.txt"}),
"execute_sync": ("BOOLEAN", {"default": True}),
}}
RETURN_TYPES = ()
FUNCTION = "sync_to_hf"
OUTPUT_NODE = True
CATEGORY = "Mila"
def sync_to_hf(self, workflow_name, token_path, execute_sync):
if not execute_sync: return {"ui": {"message": ["Sync disabled"]}}
# 1. Читаем токен
try:
with open(token_path, "r") as f:
hf_token = f.read().strip()
except Exception as e:
return {"ui": {"message": [f"Error: Could not read token at {token_path}"]}}
# 2. Ищем файл воркфлоу (добавили путь к user/default/workflows)
possible_paths = [
os.path.join("/content/ComfyUI/user/default/workflows", workflow_name),
os.path.join("/content/ComfyUI/workflows", workflow_name),
os.path.join("/content/ComfyUI", workflow_name)
]
file_path = next((p for p in possible_paths if os.path.exists(p)), None)
if not file_path:
return {"ui": {"message": [f"Error: {workflow_name} not found in {possible_paths}"]}}
# 3. Синхронизация
try:
api = HfApi(token=hf_token)
api.upload_file(
path_or_fileobj=file_path,
path_in_repo=f"workflows/{workflow_name}",
repo_id="PacifistH/Workflows",
commit_message="Manual Sync from ComfyUI Node"
)
msg = f"SUCCESS: {workflow_name} uploaded!"
print(f"DEBUG: {msg}")
return {"ui": {"message": [msg]}}
except Exception as e:
return {"ui": {"message": [f"Failed: {str(e)}"]}} |