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