From b29d4cef29cb367204e2cf028ef601ba663b3879 Mon Sep 17 00:00:00 2001 From: ebolam Date: Thu, 9 Feb 2023 10:54:38 -0500 Subject: [PATCH] Add basic authentication option for webUI image generation --- aiserver.py | 7 ++++++- gensettings.py | 30 +++++++++++++++++++++++++++++- koboldai_settings.py | 2 ++ templates/settings flyout.html | 2 +- templates/settings item.html | 2 ++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/aiserver.py b/aiserver.py index 50952239..a1ffceb9 100644 --- a/aiserver.py +++ b/aiserver.py @@ -9932,7 +9932,12 @@ def text2img_api(prompt, art_guide="") -> Image.Image: logger.debug(final_imgen_params) try: - submit_req = requests.post(url=apiaddress, data=payload_json) + logger.info("Gen Image API: Username: {}".format(koboldai_vars.img_gen_api_username)) + if koboldai_vars.img_gen_api_username != "": + basic = requests.auth.HTTPBasicAuth(koboldai_vars.img_gen_api_username, koboldai_vars.img_gen_api_password) + submit_req = requests.post(url=apiaddress, data=payload_json, auth=basic) + else: + submit_req = requests.post(url=apiaddress, data=payload_json) except requests.exceptions.ConnectionError: show_error_notification( "SD Web API Failure", diff --git a/gensettings.py b/gensettings.py index a57e1de5..5b1dea42 100644 --- a/gensettings.py +++ b/gensettings.py @@ -623,6 +623,34 @@ gensettingstf = [ "ui_level": 2 }, { + "UI_V2_Only": True, + "uitype": "text", + "unit": "text", + "label": "Img API Username", + "id": "img_gen_api_username", + "default": "", + "tooltip": "If your web-ui is behind basic web authentication, enter the username here", + "menu_path": "Interface", + "sub_path": "Images", + "classname": "user", + "name": "img_gen_api_username", + "ui_level": 2 + }, + { + "UI_V2_Only": True, + "uitype": "password", + "unit": "text", + "label": "Img API Password", + "id": "img_gen_api_password", + "default": "", + "tooltip": "If your web-ui is behind basic web authentication, enter the password here", + "menu_path": "Interface", + "sub_path": "Images", + "classname": "user", + "name": "img_gen_api_password", + "ui_level": 2 + }, + { "UI_V2_Only": True, "uitype": "text", "unit": "text", @@ -740,7 +768,7 @@ gensettingstf = [ }, { "UI_V2_Only": True, - "uitype": "text", + "uitype": "password", "unit": "text", "label": "Privacy Password", "id": "privacy_password", diff --git a/koboldai_settings.py b/koboldai_settings.py index 5318e09a..894ebc6d 100644 --- a/koboldai_settings.py +++ b/koboldai_settings.py @@ -1164,6 +1164,8 @@ class user_settings(settings): self.img_gen_api_url = "http://127.0.0.1:7860" self.img_gen_art_guide = "masterpiece, digital painting, <|>, dramatic lighting, highly detailed, trending" self.img_gen_negative_prompt = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name" + self.img_gen_api_username = "" + self.img_gen_api_password = "" self.img_gen_steps = 30 self.img_gen_cfg_scale = 7.0 self.cluster_requested_models = [] # The models which we allow to generate during cluster mode diff --git a/templates/settings flyout.html b/templates/settings flyout.html index b5307461..c9d908c3 100644 --- a/templates/settings flyout.html +++ b/templates/settings flyout.html @@ -474,7 +474,7 @@ diff --git a/templates/settings item.html b/templates/settings item.html index 88571fe1..face93d9 100644 --- a/templates/settings item.html +++ b/templates/settings item.html @@ -31,6 +31,8 @@ {% endfor %} + {% elif item['uitype'] == "password" %} + {% elif item['uitype'] == "text" %} {% endif %}