From 856181ddeba417b8c99cdcc64eee32a20d2c943b Mon Sep 17 00:00:00 2001 From: Fillip Isgro Date: Tue, 25 Mar 2025 05:50:31 -0500 Subject: [PATCH] added hugging face downloader --- __init__.py | 3 ++ nodes/FL_HFDatasetDownloader.py | 58 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 nodes/FL_HFDatasetDownloader.py diff --git a/__init__.py b/__init__.py index 7587dfb..0513b52 100644 --- a/__init__.py +++ b/__init__.py @@ -96,6 +96,7 @@ from .nodes.FL_ClipScanner import FL_ClipScanner from .nodes.FL_SceneCut import FL_SceneCut from .nodes.FL_GeminiTextAPI import FL_GeminiTextAPI from .nodes.FL_JS import FL_JS +from .nodes.FL_HFDatasetDownloader import FL_HFDatasetDownloader NODE_CLASS_MAPPINGS = { @@ -198,6 +199,7 @@ NODE_CLASS_MAPPINGS = { "FL_SceneCut": FL_SceneCut, "FL_GeminiTextAPI": FL_GeminiTextAPI, "FL_JS": FL_JS, + "FL_HFDatasetDownloader": FL_HFDatasetDownloader, } @@ -301,6 +303,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "FL_SceneCut": "FL Scene Cut Detector", "FL_GeminiTextAPI": "FL Gemini Text API", "FL_JS": "FL JavaScript", + "FL_HFDatasetDownloader": "FL HF Dataset Downloader", } diff --git a/nodes/FL_HFDatasetDownloader.py b/nodes/FL_HFDatasetDownloader.py new file mode 100644 index 0000000..5131b53 --- /dev/null +++ b/nodes/FL_HFDatasetDownloader.py @@ -0,0 +1,58 @@ +import os +from huggingface_hub import snapshot_download + +class FL_HFDatasetDownloader: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "repo_id": ("STRING", { + "default": "jjuik2014/FaceVid-1K-Part", + "multiline": False + }), + "repo_type": (["dataset", "model", "space"], { + "default": "dataset" + }), + "local_dir": ("STRING", { + "default": "./downloads", + "multiline": False + }), + "max_workers": ("INT", { + "default": 10, + "min": 1, + "max": 20, + "step": 1 + }), + "download_trigger": ("BOOLEAN", { + "default": False, + "label": "Start Download" + }) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("download_path",) + FUNCTION = "download_repo" + CATEGORY = "🏵️Fill Nodes/Hugging Face" + + def download_repo(self, repo_id, repo_type, local_dir, max_workers, download_trigger): + if not download_trigger: + return (local_dir,) + + try: + # Ensure the directory exists + os.makedirs(local_dir, exist_ok=True) + + # Download the repository + download_path = snapshot_download( + repo_id=repo_id, + repo_type=repo_type, + local_dir=local_dir, + max_workers=max_workers + ) + + return (download_path,) + + except Exception as e: + print(f"Error downloading repository: {str(e)}") + return (local_dir,) \ No newline at end of file