Skip to content

Commit

Permalink
Feat: Support for all Textual Inversions on CivitAI (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 authored Aug 31, 2023
1 parent fec441c commit 0c76ad9
Show file tree
Hide file tree
Showing 13 changed files with 948 additions and 5 deletions.
6 changes: 6 additions & 0 deletions PopupInfoPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const DESCRIPTIONS = {
"ControlType": "By selecting a Control Type, you will request that the horde utilize the ControlNet technology to process the source image, which will provide significantly more accurate conversion, at the cost of processing time. Using this option will triple the kudos cost for this request and limit the amount of steps you can use.",
"ImageIsControl": "When this option is selected, the source image will be treated the intermediate step of a ControlNet processing.",
"FetchFromCivitAI": "Will search CivitAI for LoRa which match the provided text.",
"FetchTIsFromCivitAI": "Will search CivitAI for Textual Inversions which match the provided text.",
"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.",
}

const META_DESCRIPTIONS = {
Expand All @@ -46,6 +48,10 @@ const META_DESCRIPTIONS = {
"LoRaHover": "Click to show information about this LoRa.",
"LoRaDelete": "Click to remove this LoRa from the list.",
"LoRaTrigger": "Click to inject this LoRa's triggers into your prompt.",
"TIHover": "Click to show information about this Textual Inversion.",
"TIDelete": "Click to remove this Textual Inversion from the list.",
"TITrigger": "Click to inject this Textual Inversion's triggers into your prompt.",
"TIEmbed": "Click to inject this Textual Inversion's embedding and strength into your prompt. Use this only if you've not autoinjecting this into your prompt.",
}

var current_hovered_node: Control
Expand Down
20 changes: 18 additions & 2 deletions StableHordeClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ onready var image_is_control = $"%ImageIsControl"
# model
onready var model = $"%Model"
onready var lora = $"%Lora"
onready var ti = $"%TextualInversions"
# post-processing
onready var pp = $"%PP"
# ratings
Expand Down Expand Up @@ -113,6 +114,7 @@ func _ready():
cancel_button.connect("pressed",self,"_on_CancelButton_pressed")
model.connect("prompt_inject_requested",self,"_on_prompt_inject")
lora.connect("prompt_inject_requested",self,"_on_prompt_inject")
ti.connect("prompt_inject_requested",self,"_on_prompt_inject")
# Ratings
EventBus.connect("shared_toggled", self, "_on_shared_toggled")
best_of.connect("toggled",self,"on_bestof_toggled")
Expand Down Expand Up @@ -180,7 +182,8 @@ func _ready():
image_preview,
options.shared,
control_type,
lora
lora,
ti
)
# _models_node: ModelSelection,
# _img2img_node: CheckButton,
Expand Down Expand Up @@ -269,7 +272,7 @@ func _on_image_process_update(stats: Dictionary) -> void:
stats_format["restarted"] = " Restarted:" + str(stats.restarted) + '.'
progress_text.text = " {waiting} Waiting. {processing} Processing.{restarted} {finished} Finished. ETA {eta} sec. Elapsed {elapsed} sec.".format(stats_format)
if stats.queue_position == 0:
status_text.bbcode_text = "Thank you for using the horde! "\
status_text.bbcode_text = "Thank you for using the AI Horde! "\
+ "If you enjoy this service join us in [url=discord]discord[/url] or subscribe on [url=patreon]patreon[/url] if you haven't already."
status_text.modulate = Color(0,1,0)
elif stats.wait_time > 200 or stats.elapsed_time / 1000> 150:
Expand Down Expand Up @@ -518,6 +521,8 @@ func _connect_hover_signals() -> void:
$"%FetchFromCivitAI",
$"%ShowAllModels",
$"%ShowAllLoras",
$"%FetchTIsFromCivitAI",
$"%ShowAllTIs",
]:
node.connect("mouse_entered", EventBus, "_on_node_hovered", [node])
node.connect("mouse_exited", EventBus, "_on_node_unhovered", [node])
Expand Down Expand Up @@ -612,7 +617,9 @@ func _on_generation_rating_failed(message: String) -> void:

func _on_nsfw_toggled(button_pressed: bool) -> void:
lora.lora_reference_node.nsfw = button_pressed
ti.ti_reference_node.nsfw = button_pressed
lora.update_selected_loras_label()
ti.update_selected_tis_label()

func _accept_settings() -> void:
for slider_config in [
Expand Down Expand Up @@ -641,6 +648,10 @@ func _accept_settings() -> void:
var loras = lora.selected_loras_list
globals.set_setting("loras",loras)
stable_horde_client.set("lora", loras)
var tis = ti.selected_tis_list
globals.set_setting("tis",tis)
stable_horde_client.set("tis", tis)
print_debug(tis)
stable_horde_client.set("api_key", options.get_api_key())
stable_horde_client.set("karras", karras.pressed)
globals.set_setting("karras", karras.pressed)
Expand All @@ -656,6 +667,7 @@ func _accept_settings() -> void:
stable_horde_client.set("gen_seed", seed_edit.text)
stable_horde_client.set("post_processing", globals.config.get_value("Parameters", "post_processing", stable_horde_client.post_processing))
stable_horde_client.set("lora", globals.config.get_value("Parameters", "loras", stable_horde_client.lora))
stable_horde_client.set("tis", globals.config.get_value("Parameters", "tis", stable_horde_client.tis))
if prompt_line_edit.text == '':
prompt_line_edit.text = _get_random_placeholder_prompt()
stable_horde_client.prompt = prompt_line_edit.text
Expand Down Expand Up @@ -691,6 +703,10 @@ func _on_load_from_disk_gensettings_loaded(settings) -> void:
lora.replace_loras(settings["loras"])
else:
lora.replace_loras([])
if settings.has("tis"):
ti.replace_tis(settings["tis"])
else:
ti.replace_tis([])
denoising_strength.set_value(settings.get("denoising_strength", 0.7))
if settings.has("control_type"):
for idx in range(control_type.get_item_count()):
Expand Down
174 changes: 173 additions & 1 deletion StableHordeClient.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=54 format=2]
[gd_scene load_steps=56 format=2]

[ext_resource path="res://StableHordeClient.gd" type="Script" id=1]
[ext_resource path="res://addons/stable_horde_client/stable_horde_client.gd" type="Script" id=2]
Expand Down Expand Up @@ -42,6 +42,8 @@
[ext_resource path="res://theme/fonts/noto/type/type_body_strong.tres" type="DynamicFont" id=40]
[ext_resource path="res://Panel.gd" type="Script" id=41]
[ext_resource path="res://theme/components/dark/small_normal_0.tres" type="StyleBox" id=42]
[ext_resource path="res://src/Lora/TextualInversion.gd" type="Script" id=43]
[ext_resource path="res://src/Lora/TIInject.tscn" type="PackedScene" id=44]

[sub_resource type="StreamTexture" id=9]
flags = 4
Expand Down Expand Up @@ -847,6 +849,176 @@ unique_name_in_owner = true
script = ExtResource( 28 )
showcase_index = 1

[node name="TextualInversions" type="VBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic"]
unique_name_in_owner = true
margin_top = 84.0
margin_right = 320.0
margin_bottom = 116.0
script = ExtResource( 43 )

[node name="TIAutocompleteHBC" type="HBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions"]
margin_right = 320.0
margin_bottom = 32.0

[node name="TISelectLabel" type="Label" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/TIAutocompleteHBC"]
margin_top = 6.0
margin_right = 50.0
margin_bottom = 26.0
rect_min_size = Vector2( 50, 0 )
custom_fonts/font = ExtResource( 40 )
text = "Textual Inversions"

[node name="TIAutoComplete" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/TIAutocompleteHBC" instance=ExtResource( 26 )]
unique_name_in_owner = true
margin_left = 54.0
margin_right = 248.0
margin_bottom = 32.0
size_flags_horizontal = 3
text = ""
placeholder_text = "TI Name"
seek_keys = [ "name", "description", "id" ]
popup_position = 1

[node name="FetchTIsFromCivitAI" type="Button" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/TIAutocompleteHBC"]
unique_name_in_owner = true
margin_left = 252.0
margin_right = 284.0
margin_bottom = 32.0
rect_min_size = Vector2( 32, 32 )
disabled = true
icon = ExtResource( 14 )
flat = true
icon_align = 1
expand_icon = true

[node name="ShowAllTIs" type="Button" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/TIAutocompleteHBC"]
unique_name_in_owner = true
margin_left = 288.0
margin_right = 320.0
margin_bottom = 32.0
rect_min_size = Vector2( 32, 32 )
icon = ExtResource( 15 )
flat = true
expand_icon = true

[node name="TIPopupInfo" type="PopupPanel" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions"]
margin_top = 36.0
margin_right = 512.0
margin_bottom = 153.0

[node name="TIPopupInfoLabel" type="RichTextLabel" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/TIPopupInfo"]
margin_left = 6.0
margin_top = 6.0
margin_right = 506.0
margin_bottom = 111.0
rect_min_size = Vector2( 500, 0 )
bbcode_enabled = true
bbcode_text = "This is some model info
blah blah blah
url: https://example.com"
text = "This is some model info
blah blah blah
url: https://example.com"
fit_content_height = true
deselect_on_focus_loss_enabled = false

[node name="SelectedTIs" type="RichTextLabel" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions"]
unique_name_in_owner = true
visible = false
margin_top = 36.0
margin_right = 320.0
margin_bottom = 86.0
rect_min_size = Vector2( 0, 50 )
bbcode_enabled = true
fit_content_height = true

[node name="TITriggerSelection" type="PopupMenu" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs"]
unique_name_in_owner = true
margin_left = 43.0
margin_top = -63.0
margin_right = 63.0
margin_bottom = -43.0
hide_on_checkable_item_selection = false

[node name="TIInfoCard" type="PopupPanel" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs"]
unique_name_in_owner = true
margin_left = 151.0
margin_top = -63.0
margin_right = 671.0
margin_bottom = 51.0
custom_styles/panel = ExtResource( 39 )

[node name="VBoxContainer" type="VBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard"]
margin_left = 10.0
margin_top = 10.0
margin_right = 614.0
margin_bottom = 483.0

[node name="TIInfoLabel" type="RichTextLabel" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer"]
unique_name_in_owner = true
margin_right = 604.0
margin_bottom = 105.0
rect_min_size = Vector2( 500, 0 )
focus_mode = 2
bbcode_enabled = true
bbcode_text = "This is some model info
blah blah blah
url: https://example.com"
text = "This is some model info
blah blah blah
url: https://example.com"
fit_content_height = true
selection_enabled = true

[node name="TIModelStrength" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer" instance=ExtResource( 13 )]
unique_name_in_owner = true
margin_left = 0.0
margin_top = 109.0
margin_right = 604.0
margin_bottom = 137.0
slider_name = "Model Strength"

[node name="TIInject" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer" instance=ExtResource( 44 )]

[node name="HBoxContainer" type="HBoxContainer" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer"]
margin_top = 173.0
margin_right = 604.0
margin_bottom = 473.0

[node name="TIShowcase0" type="TextureRect" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
margin_right = 300.0
margin_bottom = 300.0
rect_min_size = Vector2( 300, 300 )
expand = true
stretch_mode = 6

[node name="TICivitAIShowcase0" type="HTTPRequest" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer/HBoxContainer/TIShowcase0"]
unique_name_in_owner = true
script = ExtResource( 28 )

[node name="TIShowcase1" type="TextureRect" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
margin_left = 304.0
margin_right = 604.0
margin_bottom = 300.0
rect_min_size = Vector2( 300, 300 )
expand = true
stretch_mode = 6

[node name="TICivitAIShowcase1" type="HTTPRequest" parent="Margin/Panel/Display/Panels/Controls/Basic/TextualInversions/SelectedTIs/TIInfoCard/VBoxContainer/HBoxContainer/TIShowcase1"]
unique_name_in_owner = true
script = ExtResource( 28 )
showcase_index = 1

[node name="TrustedWorkers" type="CheckButton" parent="Margin/Panel/Display/Panels/Controls/Basic"]
unique_name_in_owner = true
margin_top = 124.0
Expand Down
Loading

0 comments on commit 0c76ad9

Please sign in to comment.