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)}"]}}