Skip to content

Commit

Permalink
feat: add button to wipe civitAI caches
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 committed Nov 12, 2023
1 parent b09cf1b commit e5c78b5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1 deletion.
8 changes: 8 additions & 0 deletions LucidCreations.tscn
Original file line number Diff line number Diff line change
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'
8 changes: 8 additions & 0 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 @@ -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()
7 changes: 7 additions & 0 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 @@ -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 = {}
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
8 changes: 8 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 @@ -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()
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()

0 comments on commit e5c78b5

Please sign in to comment.