Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for SDXL loras #115

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion LucidCreations.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Options.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions PopupInfoPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
5 changes: 5 additions & 0 deletions StableHordeClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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'
1 change: 0 additions & 1 deletion addons/stable_horde_client/AIImageTexture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions addons/stable_horde_client/civitai_lora_model_fetch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
12 changes: 10 additions & 2 deletions addons/stable_horde_client/civitai_lora_reference.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -226,8 +227,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"]:
Expand All @@ -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()
4 changes: 2 additions & 2 deletions addons/stable_horde_client/civitai_ti_model_fetch.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
11 changes: 9 additions & 2 deletions addons/stable_horde_client/civitai_ti_reference.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -198,8 +199,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"]:
Expand All @@ -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 = {}
8 changes: 6 additions & 2 deletions addons/stable_horde_client/stable_horde_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum SamplerMethods {
k_dpm_adaptive
k_dpmpp_2s_a
k_dpmpp_2m
k_dpmpp_sde
dpmsolver
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions bus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/Lora/Lora.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -271,6 +273,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",
Expand All @@ -285,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()
8 changes: 8 additions & 0 deletions src/Lora/TextualInversion.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()