|
| 1 | +""" |
| 2 | +* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 3 | +* SPDX-License-Identifier: Apache-2.0 |
| 4 | +* |
| 5 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +* you may not use this file except in compliance with the License. |
| 7 | +* You may obtain a copy of the License at |
| 8 | +* |
| 9 | +* https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +* |
| 11 | +* Unless required by applicable law or agreed to in writing, software |
| 12 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +* See the License for the specific language governing permissions and |
| 15 | +* limitations under the License. |
| 16 | +""" |
| 17 | + |
| 18 | +from __future__ import annotations |
| 19 | + |
| 20 | +__all__ = ["NODE_UI_CONFIGS", "NodeUIConfig"] |
| 21 | + |
| 22 | +from enum import Enum |
| 23 | + |
| 24 | +from ..models import ( |
| 25 | + DynamicHelp, |
| 26 | + HelpContent, |
| 27 | + NodeUI, |
| 28 | + UrlHandler, |
| 29 | + UrlParser, |
| 30 | + WidgetVisibility, |
| 31 | +) |
| 32 | +from ...nodes.constant import ModelSource |
| 33 | + |
| 34 | + |
| 35 | +class NodeUIConfig(str, Enum): |
| 36 | + RTX_REMIX_DOWNLOAD_MODEL = "RTXRemixDownloadModel" |
| 37 | + |
| 38 | + |
| 39 | +NODE_UI_CONFIGS: dict[NodeUIConfig, NodeUI] = { |
| 40 | + NodeUIConfig.RTX_REMIX_DOWNLOAD_MODEL: NodeUI( |
| 41 | + url_handler=UrlHandler( |
| 42 | + source_field="model_source", |
| 43 | + host_patterns={ |
| 44 | + ModelSource.HUGGINGFACE: "huggingface.co", |
| 45 | + ModelSource.CIVITAI: "civitai.com", |
| 46 | + }, |
| 47 | + parsers={ |
| 48 | + ModelSource.HUGGINGFACE: UrlParser( |
| 49 | + populate={"repo_id": "hf_repo_id", "filename": "hf_filename"}, |
| 50 | + reset=["civitai_model_id", "custom_filename"], |
| 51 | + ), |
| 52 | + ModelSource.CIVITAI: UrlParser( |
| 53 | + populate={"version_id": "civitai_model_id"}, |
| 54 | + reset=["hf_repo_id", "hf_filename", "custom_filename"], |
| 55 | + ), |
| 56 | + ModelSource.CUSTOM: UrlParser( |
| 57 | + populate={"filename": "custom_filename"}, |
| 58 | + reset=["hf_repo_id", "hf_filename", "civitai_model_id"], |
| 59 | + ), |
| 60 | + }, |
| 61 | + ), |
| 62 | + visibility_rules=[ |
| 63 | + # Show model_source only after a URL is entered |
| 64 | + WidgetVisibility( |
| 65 | + source_field="url", |
| 66 | + show_when_filled=["model_source"], |
| 67 | + ), |
| 68 | + # Show source-specific fields based on detected source |
| 69 | + WidgetVisibility( |
| 70 | + source_field="model_source", |
| 71 | + mapping={ |
| 72 | + ModelSource.HUGGINGFACE: [ |
| 73 | + "hf_repo_id", |
| 74 | + "hf_filename", |
| 75 | + "hf_token", |
| 76 | + ], |
| 77 | + ModelSource.CIVITAI: ["civitai_model_id", "civitai_api_key"], |
| 78 | + ModelSource.CUSTOM: ["custom_filename", "custom_hash"], |
| 79 | + }, |
| 80 | + ), |
| 81 | + # Show archive fields when extract_archive is enabled |
| 82 | + WidgetVisibility( |
| 83 | + source_field="extract_archive", |
| 84 | + mapping={ |
| 85 | + True: ["archive_model_filename", "extracted_model_hash"], |
| 86 | + }, |
| 87 | + ), |
| 88 | + ], |
| 89 | + info_button=DynamicHelp( |
| 90 | + source_field="model_source", |
| 91 | + configs={ |
| 92 | + "": HelpContent( |
| 93 | + label="🛈 How to use this node", |
| 94 | + title="Download Model", |
| 95 | + template="rtx-remix-download-generic-info-template", |
| 96 | + ), |
| 97 | + ModelSource.HUGGINGFACE: HelpContent( |
| 98 | + label="🛈 HuggingFace Help", |
| 99 | + title="Download from HuggingFace", |
| 100 | + template="rtx-remix-download-huggingface-token-info-template", |
| 101 | + ), |
| 102 | + ModelSource.CIVITAI: HelpContent( |
| 103 | + label="🛈 CivitAI Help", |
| 104 | + title="Download from CivitAI", |
| 105 | + template="rtx-remix-download-civitai-apikey-info-template", |
| 106 | + ), |
| 107 | + ModelSource.CUSTOM: HelpContent( |
| 108 | + label="🛈 Custom URL Help", |
| 109 | + title="Custom URL Download", |
| 110 | + template="rtx-remix-download-custom-howto-info-template", |
| 111 | + ), |
| 112 | + }, |
| 113 | + ), |
| 114 | + ) |
| 115 | +} |
0 commit comments