Skip to content

Commit

Permalink
removed globals from the addon (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
db0 authored Oct 17, 2023
1 parent 6307c3d commit 2412860
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion StableHordeClient.tscn → LucidCreations.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ margin_bottom = 20.0
[node name="Title" type="Label" parent="Margin/Panel/Display/Panels/Controls/Information/HBC"]
margin_right = 130.0
margin_bottom = 20.0
text = "Stable Horde Client"
text = "Lucid Creations"

[node name="Version" type="Label" parent="Margin/Panel/Display/Panels/Controls/Information/HBC"]
margin_left = 134.0
Expand Down
2 changes: 2 additions & 0 deletions StableHordeClient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ 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")
stable_horde_client.client_agent = "Lucid Creations:" + ToolConsts.VERSION + ":(discord)db0#1625"
stable_horde_client.aihorde_url = globals.aihorde_url

_connect_hover_signals()
save.connect("pressed", self, "_on_save_pressed")
Expand Down
2 changes: 2 additions & 0 deletions addons/stable_horde_client/AIImageTexture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ static func sanitize_filename(filename: String) -> String:
'(',
')',
' ',
'\n',
]
for c in replace_chars:
filename = filename.replace(c,'_')
print_debug(filename)
return(filename)
12 changes: 6 additions & 6 deletions addons/stable_horde_client/stable_horde_client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func generate(replacement_prompt := '', replacement_params := {}) -> void:
var headers = [
"Content-Type: application/json",
"apikey: " + api_key,
"Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625",
"Client-Agent: " + client_agent,
]
var error = request(globals.aihorde_url + "/api/v2/generate/async", headers, false, HTTPClient.METHOD_POST, body)
var error = request(aihorde_url + "/api/v2/generate/async", headers, false, HTTPClient.METHOD_POST, body)
if error != OK:
var error_msg := "Something went wrong when initiating the stable horde request"
push_error(error_msg)
Expand Down Expand Up @@ -206,17 +206,17 @@ func process_request(json_ret) -> void:
func check_request_process(operation := OngoingRequestOperations.CHECK) -> void:
# We do one check request per second
yield(get_tree().create_timer(1), "timeout")
var url = globals.aihorde_url + "/api/v2/generate/check/" + async_request_id
var url = aihorde_url + "/api/v2/generate/check/" + async_request_id
var method = HTTPClient.METHOD_GET
if operation == OngoingRequestOperations.GET:
url = globals.aihorde_url + "/api/v2/generate/status/" + async_request_id
url = aihorde_url + "/api/v2/generate/status/" + async_request_id
elif operation == OngoingRequestOperations.CANCEL:
url = globals.aihorde_url + "/api/v2/generate/status/" + async_request_id
url = aihorde_url + "/api/v2/generate/status/" + async_request_id
method = HTTPClient.METHOD_DELETE
delete_sent = true
var error = request(
url,
["Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625"],
["Client-Agent: " + client_agent],
false,
method)
if state == States.WORKING and error != OK:
Expand Down
2 changes: 2 additions & 0 deletions addons/stable_horde_client/stable_horde_httpclient.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ enum States {
CANCELLING
}
# When set to true, we will abort the current generation and try to retrieve whatever images we can
export(String) var aihorde_url = "https://aihorde.net"
export(String) var client_agent = "AI Horde Godot Addon:2.7.0:db0#1625"
var state : int = States.READY
var service_name :String = "AI Horde"

Expand Down
5 changes: 2 additions & 3 deletions addons/stable_horde_client/stable_horde_login.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class_name StableHordeLogin
extends StableHordeHTTPRequest

signal login_successful(user_details)

var user_details: Dictionary

export(String) var api_key := '0000000000'
Expand All @@ -15,9 +14,9 @@ func login() -> void:
state = States.WORKING
var headers = [
"Content-Type: application/json", "apikey: " + api_key,
"Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":db0#1625"
"Client-Agent: " + client_agent
]
var error = request(globals.aihorde_url + "/api/v2/find_user", headers, false, HTTPClient.METHOD_GET)
var error = request(aihorde_url + "/api/v2/find_user", headers, false, HTTPClient.METHOD_GET)
if error != OK:
var error_msg := "Something went wrong when initiating the stable horde request"
push_error(error_msg)
Expand Down
2 changes: 1 addition & 1 deletion addons/stable_horde_client/stable_horde_models.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func get_models() -> void:
print_debug("Models currently working. Cannot do more than 1 request at a time with the same Stable Horde Models.")
return
state = States.WORKING
var error = request(globals.aihorde_url + "/api/v2/status/models", [], false, HTTPClient.METHOD_GET)
var error = request(aihorde_url + "/api/v2/status/models", [], false, HTTPClient.METHOD_GET)
if error != OK:
var error_msg := "Something went wrong when initiating the stable horde request"
push_error(error_msg)
Expand Down
5 changes: 2 additions & 3 deletions addons/stable_horde_client/stable_horde_rate_generation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ extends StableHordeHTTPRequest

signal generation_rated(awarded_kudos)


func submit_rating(request_id: String, ratings_payload: Dictionary) -> void:
if state != States.READY:
print_debug("Rating is already being processed")
return
state = States.WORKING
var body = to_json(ratings_payload)
var url = globals.aihorde_url + "/api/v2/generate/rate/" + request_id
var url = aihorde_url + "/api/v2/generate/rate/" + request_id
var headers = [
"Content-Type: application/json",
"Client-Agent: " + "Lucid Creations:" + ToolConsts.VERSION + ":(discord)db0#1625"
"Client-Agent: " + client_agent
]
# print_debug(url)
# print_debug(body)
Expand Down
4 changes: 2 additions & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ _global_script_class_icons={
[application]

config/name="Lucid Creations"
config/description="Generate images using the Stable Diffusion AI and the Stable Horde crowdsourced cluster"
run/main_scene="res://StableHordeClient.tscn"
config/description="Generate images using the Stable Diffusion AI and the AI Horde crowdsourced cluster"
run/main_scene="res://LucidCreations.tscn"
config/icon="res://icon.png"
config/windows_native_icon="res://icon.ico"

Expand Down
1 change: 0 additions & 1 deletion src/ParamBus.gd
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func get_loras() -> Array:
return loras_node.selected_loras_list

func get_tis() -> Array:
print_debug(tis_node.selected_tis_list)
return tis_node.selected_tis_list

func _on_line_edit_changed(line_edit_node) -> void:
Expand Down

0 comments on commit 2412860

Please sign in to comment.