Only show needed custom lora settings
This commit is contained in:
+4
-1
@@ -1,8 +1,9 @@
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import folder_paths
|
||||
from .src.dynamic_lora_loader import generate_lora_node_class
|
||||
from .src.dynamic_scheduler_loader import generate_scheduler_node_class
|
||||
from .src.check_folder_paths import check_lora_folders
|
||||
from .sn0w import ConfigReader, Logger
|
||||
|
||||
from .src.lora_selector import LoraSelectorNode
|
||||
@@ -52,6 +53,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
|
||||
WEB_DIRECTORY = "./web"
|
||||
|
||||
check_lora_folders()
|
||||
|
||||
current_unique_id = 0 # Global variable to track the unique ID
|
||||
logger = Logger()
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import folder_paths
|
||||
import json
|
||||
import os
|
||||
|
||||
from ..sn0w import Logger
|
||||
|
||||
def check_lora_folders():
|
||||
logger = Logger()
|
||||
custom_paths = ["loras_15", "loras_xl", "loras_3"]
|
||||
existing_paths = []
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
if os.path.basename(dir_path) == "src":
|
||||
dir_path = os.path.dirname(dir_path)
|
||||
json_path = os.path.join(dir_path, 'web/settings/sn0w_settings.json')
|
||||
# Ensure the directory exists
|
||||
os.makedirs(os.path.dirname(json_path), exist_ok=True)
|
||||
|
||||
for path in custom_paths:
|
||||
try:
|
||||
lora_path = folder_paths.get_filename_list(path)
|
||||
if lora_path:
|
||||
existing_paths.append(path)
|
||||
except Exception as e:
|
||||
logger.log(f"{path} doesn't exist: {e}", "WARNING")
|
||||
|
||||
print(existing_paths)
|
||||
# Write the result to a JSON file in /web/settings
|
||||
data = {"loaders_enabled": existing_paths}
|
||||
with open(json_path, "w") as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
||||
|
||||
return existing_paths
|
||||
@@ -1,9 +1,30 @@
|
||||
import { SettingUtils } from './sn0w.js';
|
||||
import { app } from "../../../scripts/app.js";
|
||||
import { api } from "../../../scripts/api.js";
|
||||
|
||||
async function fetchExtensionSettings() {
|
||||
try {
|
||||
const response = await api.fetchApi('/extensions/ComfyUI-Sn0w-Scripts/settings/sn0w_settings.json');
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
}
|
||||
}
|
||||
|
||||
const sn0wSettings = await fetchExtensionSettings();
|
||||
const defaultValue = "ExampleName1:Value1\nExampleName2:Value2";
|
||||
const tooltip = "Enter each name-value pair on a new line, separated by a colon (:).";
|
||||
|
||||
const settingsMap = {
|
||||
"sn0w.CustomLoraLoaders1.5": "loras_15",
|
||||
"sn0w.CustomLoraLoadersXL": "loras_xl",
|
||||
"sn0w.CustomLoraLoaders3": "loras_3"
|
||||
}
|
||||
|
||||
const settingsDefinitions = [
|
||||
{
|
||||
id: "sn0w.CustomLoraLoadersXL",
|
||||
@@ -42,4 +63,8 @@ const registerSetting = (settingDefinition) => {
|
||||
};
|
||||
|
||||
// Register settings
|
||||
settingsDefinitions.forEach(registerSetting);
|
||||
settingsDefinitions.forEach(setting => {
|
||||
if (sn0wSettings["loaders_enabled"].includes(settingsMap[setting.id])) {
|
||||
registerSetting(setting);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user