From b09cf1b53a3466da34a11fccead7fc2aa0ad67d5 Mon Sep 17 00:00:00 2001 From: db0 Date: Sun, 12 Nov 2023 16:25:59 +0100 Subject: [PATCH 1/2] fix: support SDXL loras --- LucidCreations.tscn | 2 +- addons/stable_horde_client/AIImageTexture.gd | 1 - addons/stable_horde_client/civitai_lora_model_fetch.gd | 4 ++-- addons/stable_horde_client/civitai_lora_reference.gd | 4 ++-- addons/stable_horde_client/civitai_ti_model_fetch.gd | 4 ++-- addons/stable_horde_client/civitai_ti_reference.gd | 4 ++-- addons/stable_horde_client/stable_horde_client.gd | 8 ++++++-- src/Lora/Lora.gd | 1 + 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/LucidCreations.tscn b/LucidCreations.tscn index 895140e..78396c7 100644 --- a/LucidCreations.tscn +++ b/LucidCreations.tscn @@ -1137,7 +1137,7 @@ margin_top = 218.0 margin_right = 300.0 margin_bottom = 246.0 text = "k_lms" -items = [ "k_lms", null, false, 0, null, "k_heun", null, false, 1, null, "k_euler", null, false, 2, null, "k_euler_a", null, false, 3, null, "k_dpm_2", null, false, 4, null, "k_dpm_2_a", null, false, 5, null, "k_dpm_fast", null, false, 6, null, "k_dpm_adaptive", null, false, 7, null, "k_dpmpp_2s_a", null, false, 8, null, "k_dpmpp_2m", null, false, 9, null, "dpmsolver", null, false, 10, null ] +items = [ "k_lms", null, false, 0, null, "k_heun", null, false, 1, null, "k_euler", null, false, 2, null, "k_euler_a", null, false, 3, null, "k_dpm_2", null, false, 4, null, "k_dpm_2_a", null, false, 5, null, "k_dpm_fast", null, false, 6, null, "k_dpm_adaptive", null, false, 7, null, "k_dpmpp_2s_a", null, false, 8, null, "k_dpmpp_2m", null, false, 9, null, "dpmsolver", null, false, 10, null, "k_dpmpp_sde", null, false, 11, null ] selected = 0 [node name="SeedLabel" type="Label" parent="Margin/Panel/Display/Panels/Controls/Advanced"] diff --git a/addons/stable_horde_client/AIImageTexture.gd b/addons/stable_horde_client/AIImageTexture.gd index 6def5c1..1943117 100644 --- a/addons/stable_horde_client/AIImageTexture.gd +++ b/addons/stable_horde_client/AIImageTexture.gd @@ -150,5 +150,4 @@ static func sanitize_filename(filename: String) -> String: ] for c in replace_chars: filename = filename.replace(c,'_') - print_debug(filename) return(filename) diff --git a/addons/stable_horde_client/civitai_lora_model_fetch.gd b/addons/stable_horde_client/civitai_lora_model_fetch.gd index e1e0442..d4c5749 100644 --- a/addons/stable_horde_client/civitai_lora_model_fetch.gd +++ b/addons/stable_horde_client/civitai_lora_model_fetch.gd @@ -107,8 +107,8 @@ func _parse_civitai_lora_data(civitai_entry) -> Dictionary: lora_details["unusable"] = 'Attention! This LoRa is unusable because it does not provide file validation.' elif not lora_details["url"]: lora_details["unusable"] = 'Attention! This LoRa is unusable because it appears to have no valid safetensors upload.' - elif not is_default and lora_details["size_mb"] > 150: - lora_details["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 150Mb filesize we allow on the AI Horde.' + elif not is_default and lora_details["size_mb"] > 230: + lora_details["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.' lora_details["images"] = [] for img in versions[0]["images"]: if img["nsfw"] in ["Mature", "X"]: diff --git a/addons/stable_horde_client/civitai_lora_reference.gd b/addons/stable_horde_client/civitai_lora_reference.gd index 6e7497e..69a3f46 100644 --- a/addons/stable_horde_client/civitai_lora_reference.gd +++ b/addons/stable_horde_client/civitai_lora_reference.gd @@ -226,8 +226,8 @@ func _parse_civitai_lora_data(civitai_entry) -> Dictionary: lora_details["unusable"] = 'Attention! This LoRa is unusable because it does not provide file validation.' elif not lora_details["url"]: lora_details["unusable"] = 'Attention! This LoRa is unusable because it appears to have no valid safetensors upload.' - elif lora_details["size_mb"] > 150: - lora_details["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 150Mb filesize we allow on the AI Horde.' + elif lora_details["size_mb"] > 230: + lora_details["unusable"] = 'Attention! This LoRa is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.' lora_details["images"] = [] for img in versions[0]["images"]: if img["nsfw"] in ["Mature", "X"]: diff --git a/addons/stable_horde_client/civitai_ti_model_fetch.gd b/addons/stable_horde_client/civitai_ti_model_fetch.gd index 6331a9e..389201c 100644 --- a/addons/stable_horde_client/civitai_ti_model_fetch.gd +++ b/addons/stable_horde_client/civitai_ti_model_fetch.gd @@ -105,8 +105,8 @@ func _parse_civitai_ti_data(civitai_entry) -> Dictionary: ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because it does not provide file validation.' elif not ti_details["url"]: ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because it appears to have no valid safetensors upload.' - elif not is_default and ti_details["size_mb"] > 150: - ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because is exceeds the max 150Mb filesize we allow on the AI Horde.' + elif not is_default and ti_details["size_mb"] > 230: + ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.' ti_details["images"] = [] for img in versions[0]["images"]: if img["nsfw"] in ["Mature", "X"]: diff --git a/addons/stable_horde_client/civitai_ti_reference.gd b/addons/stable_horde_client/civitai_ti_reference.gd index 91239a7..30f62f3 100644 --- a/addons/stable_horde_client/civitai_ti_reference.gd +++ b/addons/stable_horde_client/civitai_ti_reference.gd @@ -198,8 +198,8 @@ func _parse_civitai_ti_data(civitai_entry) -> Dictionary: ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because it does not provide file validation.' elif not ti_details["url"]: ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because it appears to have no valid safetensors upload.' - elif ti_details["size_mb"] > 150: - ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because is exceeds the max 150Mb filesize we allow on the AI Horde.' + elif ti_details["size_mb"] > 230: + ti_details["unusable"] = 'Attention! This Textual Inversion is unusable because is exceeds the max 230Mb filesize we allow on the AI Horde.' ti_details["images"] = [] for img in versions[0]["images"]: if img["nsfw"] in ["Mature", "X"]: diff --git a/addons/stable_horde_client/stable_horde_client.gd b/addons/stable_horde_client/stable_horde_client.gd index 485e111..ad319c0 100644 --- a/addons/stable_horde_client/stable_horde_client.gd +++ b/addons/stable_horde_client/stable_horde_client.gd @@ -16,6 +16,7 @@ enum SamplerMethods { k_dpm_adaptive k_dpmpp_2s_a k_dpmpp_2m + k_dpmpp_sde dpmsolver } @@ -55,7 +56,7 @@ export(int,64,1024,64) var height := 512 # Generally there's usually no reason to go above 50 unless you know what you're doing. export(int,1,100) var steps := 30 # Advanced: The sampler used to generate. Provides slight variations on the same prompt. -export(String, "k_lms", "k_heun", "k_euler", "k_euler_a", "k_dpm_2", "k_dpm_2_a", "k_dpm_fast", "k_dpm_adaptive", "k_dpmpp_2s_a", "k_dpmpp_2m", "dpmsolver") var sampler_name := "k_euler_a" +export(String, "k_lms", "k_heun", "k_euler", "k_euler_a", "k_dpm_2", "k_dpm_2_a", "k_dpm_fast", "k_dpm_adaptive", "k_dpmpp_2s_a", "k_dpmpp_2m", "k_dpmpp_sde", "dpmsolver") var sampler_name := "k_euler_a" # How closely to follow the prompt given export(float,0,30,0.5) var cfg_scale := 7.5 # The number of CLIP language processor layers to skip. @@ -150,7 +151,10 @@ func generate(replacement_prompt := '', replacement_params := {}) -> void: "r2": r2, "shared": shared, "dry_run": dry_run, -# "workers": ["dc0704ab-5b42-4c65-8471-561be16ad696"], # debug + "workers": [ + "ba9937fb-8558-4d42-9059-926de5f0fe4e", #pama + "dc0704ab-5b42-4c65-8471-561be16ad696", #portal + ], # debug } # print_debug(submit_dict) if source_image: diff --git a/src/Lora/Lora.gd b/src/Lora/Lora.gd index f8c7877..73ae46a 100644 --- a/src/Lora/Lora.gd +++ b/src/Lora/Lora.gd @@ -271,6 +271,7 @@ func check_baseline_compatibility(lora_name) -> int: if baselines.size() == 0: return LoraCompatible.MAYBE var lora_to_model_baseline_map = { + "SDXL 1.0": "stable_diffusion_xl", "SD 1.5": "stable diffusion 1", "SD 2.1 768": "stable diffusion 2", "SD 2.1 512": "stable diffusion 2", From e5c78b5876bbf713d69dc4fdf4f4861ab7538737 Mon Sep 17 00:00:00 2001 From: db0 Date: Sun, 12 Nov 2023 17:16:37 +0100 Subject: [PATCH 2/2] feat: add button to wipe civitAI caches --- LucidCreations.tscn | 8 ++++++++ Options.gd | 7 ++++++- PopupInfoPanel.gd | 1 + StableHordeClient.gd | 5 +++++ addons/stable_horde_client/civitai_lora_reference.gd | 8 ++++++++ addons/stable_horde_client/civitai_ti_reference.gd | 7 +++++++ bus.gd | 1 + src/Lora/Lora.gd | 8 ++++++++ src/Lora/TextualInversion.gd | 8 ++++++++ 9 files changed, 52 insertions(+), 1 deletion(-) diff --git a/LucidCreations.tscn b/LucidCreations.tscn index 78396c7..a05682c 100644 --- a/LucidCreations.tscn +++ b/LucidCreations.tscn @@ -1342,6 +1342,14 @@ margin_right = 507.0 margin_bottom = 385.251 text = "Share Images" +[node name="WipeCache" type="Button" parent="Margin/Panel/Display/Panels/Controls/Options/VBC/VBCLeft"] +unique_name_in_owner = true +margin_left = 273.0 +margin_top = 25.0 +margin_right = 320.0 +margin_bottom = 53.0 +text = "Wipe CivitAI Cache" + [node name="Information" type="VBoxContainer" parent="Margin/Panel/Display/Panels/Controls"] visible = false margin_left = 10.0 diff --git a/Options.gd b/Options.gd index f030cfa..336ed30 100644 --- a/Options.gd +++ b/Options.gd @@ -10,6 +10,7 @@ onready var api_key_label := $"%APIKeyLabel" onready var login_button = $"%LoginButton" onready var stable_horde_login = $"%StableHordeLogin" onready var load_seed_from_disk = $"%LoadSeedFromDisk" +onready var wipe_cache = $"%WipeCache" func _ready(): remember_prompt.pressed = globals.config.get_value("Options", "remember_prompt", false) @@ -22,6 +23,7 @@ func _ready(): shared.connect("toggled",self,"_on_shared_pressed") # warning-ignore:return_value_discarded login_button.connect("pressed",self,"_on_login_pressed") + wipe_cache.connect("pressed",self,"_on_wipe_cache_pressed") EventBus.connect("generation_completed",self,"_on_generation_completed") # save_dir.connect("text_changed",self,"_on_savedir_changed") # warning-ignore:return_value_discarded @@ -118,7 +120,10 @@ func _on_login_pressed() -> void: stable_horde_login.login() $"%LoggedInDetails".visible = false api_key.modulate = Color(1,1,0) - + +func _on_wipe_cache_pressed() -> void: + EventBus.emit_signal("cache_wipe_requested") + func _on_login_succesful(_user_data) -> void: $"%LoggedInDetails".visible = true $"%LoggedInUsername".text = "Username: " + stable_horde_login.get_username() diff --git a/PopupInfoPanel.gd b/PopupInfoPanel.gd index 769d58e..60c8534 100644 --- a/PopupInfoPanel.gd +++ b/PopupInfoPanel.gd @@ -36,6 +36,7 @@ const DESCRIPTIONS = { "ShowAllModels": "Will display an list of all known models, from which to select one manually.", "ShowAllLoras": "Will display an list of all known LoRas, from which to select one manually.", "ShowAllTIs": "Will display an list of all known Textual Inversions, from which to select one manually.", + "WipeCache": "Will remove all CivitAI cached information. You will have to search for your loras once more after this.", } const META_DESCRIPTIONS = { diff --git a/StableHordeClient.gd b/StableHordeClient.gd index 137fc2a..6381cb8 100644 --- a/StableHordeClient.gd +++ b/StableHordeClient.gd @@ -103,6 +103,7 @@ func _ready(): select_image.connect("image_selected",self,"_on_source_image_selected") # warning-ignore:return_value_discarded EventBus.connect("kudos_calculated",self, "_on_kudos_calculated") + EventBus.connect("cache_wipe_requested",self, "_on_cache_wipe_requested") stable_horde_client.client_agent = "Lucid Creations:" + ToolConsts.VERSION + ":(discord)db0#1625" stable_horde_client.aihorde_url = globals.aihorde_url @@ -525,6 +526,7 @@ func _connect_hover_signals() -> void: $"%ShowAllLoras", $"%FetchTIsFromCivitAI", $"%ShowAllTIs", + $"%WipeCache", ]: node.connect("mouse_entered", EventBus, "_on_node_hovered", [node]) node.connect("mouse_exited", EventBus, "_on_node_unhovered", [node]) @@ -752,3 +754,6 @@ func _on_kudos_calculated(kudos: int) -> void: if kudos > options.stable_horde_login.get_kudos(): fmt["color"] = "#FFA500" kudos_text.bbcode_text = "[color={color}]Kudos: {kudos}[/color]".format(fmt) + +func _on_cache_wipe_requested() -> void: + status_text.text = 'CivitAI Caches Wiped' diff --git a/addons/stable_horde_client/civitai_lora_reference.gd b/addons/stable_horde_client/civitai_lora_reference.gd index 69a3f46..a4f9616 100644 --- a/addons/stable_horde_client/civitai_lora_reference.gd +++ b/addons/stable_horde_client/civitai_lora_reference.gd @@ -2,6 +2,7 @@ class_name CivitAILoraReference extends StableHordeHTTPRequest signal reference_retrieved(models_list) +signal cache_wiped export(String) var loras_refence_url := "https://civitai.com/api/v1/models?types=LORA&sort=Highest%20Rated&primaryFileOnly=true&limit=100" export(String) var horde_default_loras := "https://raw.githubusercontent.com/Haidra-Org/AI-Horde-image-model-reference/main/lora.json" @@ -242,3 +243,10 @@ func _store_lora(lora_data: Dictionary) -> void: var lora_name = lora_data["name"] lora_reference[lora_name] = lora_data lora_id_index[int(lora_data["id"])] = lora_name + +func wipe_cache() -> void: + var dir = Directory.new() + dir.remove("user://civitai_lora_reference") + emit_signal("cache_wiped") + lora_reference = {} + get_lora_reference() diff --git a/addons/stable_horde_client/civitai_ti_reference.gd b/addons/stable_horde_client/civitai_ti_reference.gd index 30f62f3..7c1f77b 100644 --- a/addons/stable_horde_client/civitai_ti_reference.gd +++ b/addons/stable_horde_client/civitai_ti_reference.gd @@ -2,6 +2,7 @@ class_name CivitAITIReference extends StableHordeHTTPRequest signal reference_retrieved(models_list) +signal cache_wiped export(String) var tis_refence_url := "https://civitai.com/api/v1/models?types=TextualInversion&sort=Highest%20Rated&primaryFileOnly=true&limit=100" @@ -214,3 +215,9 @@ func _store_ti(ti_data: Dictionary) -> void: var ti_name = ti_data["name"] ti_reference[ti_name] = ti_data ti_id_index[int(ti_data["id"])] = ti_name + +func wipe_cache() -> void: + var dir = Directory.new() + dir.remove("user://civitai_ti_reference") + emit_signal("cache_wiped") + ti_reference = {} diff --git a/bus.gd b/bus.gd index 43ff3ff..a3d69b7 100644 --- a/bus.gd +++ b/bus.gd @@ -22,6 +22,7 @@ signal lora_selected(lora_details) signal model_selected(model_details) signal kudos_calculated(kudos) signal generation_completed +signal cache_wipe_requested func _on_node_hovered(node: Control): emit_signal("node_hovered", node) diff --git a/src/Lora/Lora.gd b/src/Lora/Lora.gd index 73ae46a..db96497 100644 --- a/src/Lora/Lora.gd +++ b/src/Lora/Lora.gd @@ -34,10 +34,12 @@ onready var fetch_from_civitai = $"%FetchFromCivitAI" func _ready(): # warning-ignore:return_value_discarded EventBus.connect("model_selected",self,"on_model_selection_changed") + EventBus.connect("cache_wipe_requested",self,"on_cache_wipe_requested") lora_reference_node = CivitAILoraReference.new() lora_reference_node.nsfw = globals.config.get_value("Parameters", "nsfw") # warning-ignore:return_value_discarded lora_reference_node.connect("reference_retrieved",self, "_on_reference_retrieved") + lora_reference_node.connect("cache_wiped",self, "_on_cache_wiped") add_child(lora_reference_node) # warning-ignore:return_value_discarded # warning-ignore:return_value_discarded @@ -286,3 +288,9 @@ func check_baseline_compatibility(lora_name) -> int: else: return LoraCompatible.YES return LoraCompatible.NO + +func _on_cache_wiped() -> void: + replace_loras([]) + +func on_cache_wipe_requested() -> void: + lora_reference_node.wipe_cache() diff --git a/src/Lora/TextualInversion.gd b/src/Lora/TextualInversion.gd index bc1ae3c..c3216a9 100644 --- a/src/Lora/TextualInversion.gd +++ b/src/Lora/TextualInversion.gd @@ -34,10 +34,12 @@ onready var fetch_tis_from_civitai = $"%FetchTIsFromCivitAI" func _ready(): # warning-ignore:return_value_discarded EventBus.connect("model_selected",self,"on_model_selection_changed") + EventBus.connect("cache_wipe_requested",self,"on_cache_wipe_requested") ti_reference_node = CivitAITIReference.new() ti_reference_node.nsfw = globals.config.get_value("Parameters", "nsfw") # warning-ignore:return_value_discarded ti_reference_node.connect("reference_retrieved",self, "_on_reference_retrieved") + ti_reference_node.connect("cache_wiped",self, "_on_cache_wiped") add_child(ti_reference_node) # warning-ignore:return_value_discarded # warning-ignore:return_value_discarded @@ -311,3 +313,9 @@ func check_baseline_compatibility(ti_name) -> int: else: return TICompatible.YES return TICompatible.NO + +func _on_cache_wiped() -> void: + replace_tis([]) + +func on_cache_wipe_requested() -> void: + ti_reference_node.wipe_cache()