Skip to content

Commit a32195b

Browse files
committed
revise for user authentication
1 parent 541d7c5 commit a32195b

9 files changed

+166
-107
lines changed

localizations/zh_CN.json

+20-8
Original file line numberDiff line numberDiff line change
@@ -625,17 +625,11 @@
625625
"Train settings": "训练设置",
626626
"Train an hypernetwork; you must specify a directory with a set of 1:1 ratio images": "训练 hypernetwork; 必须指定一组具有 1:1 比例图像的目录",
627627
"Hypernetwork settings": "Hypernetwork 设置",
628-
"Sign Options": "登陆选项",
629-
"Sign In": "登入",
630-
"Sign Up": "注册",
631-
"Sign Out": "登出",
632628
"Username": "用户名",
633629
"Password": "密码",
634-
"Email": "电子邮箱",
635-
"Mismatched username/password or not existed username": "用户名/密码不匹配或用户不存在",
636-
"Signup failed, please check and retry again": "注册失败,请检查后并重试",
637-
"Update failed, please check and retry again": "更新失败,请检查后并重试",
630+
"Options": "选项",
638631
"Output": "输出",
632+
"User management (Only available for admin user)": "用户管理 (仅管理员用户可用)",
639633
"Images S3 URI": "图像 S3 位置",
640634
"Models S3 URI": "模型 S3 位置",
641635
"Instance type": "实例类型",
@@ -754,6 +748,24 @@
754748
"Sample CFG Scale": "采样扩散度",
755749
"Sample Steps": "采样步数",
756750
"Cancel": "取消",
751+
"Invert colors if your image has white background. Change your brush width to make it thinner if you want to draw something.": "如果您的图像有白色背景,请反转颜色。 如果你想画东西,改变你的画笔宽度让它更细",
752+
"Enable": "启用",
753+
"Invert Input Color": "反转输入颜色",
754+
"RGB to BGR": "RGB 转为 BGR",
755+
"Low VRAM": "低 VRAM",
756+
"Guess Mode": "猜测模式",
757+
"Preprocessor": "预处理器",
758+
"Weight": "权重",
759+
"Guidance strength (T)": "引导强度 (T)",
760+
"Resize Mode": "调整模式",
761+
"Envelope (Outer Fit)": "信封(外部适配)",
762+
"Scale to Fit (Inner Fit)": "缩放以适合 (内部适配)",
763+
"Just Resize": "调整大小",
764+
"Canvas Width": "画布宽度",
765+
"Canvas Height": "画布高度",
766+
"Create blank canvas": "创建空白画布",
767+
"Preview annotator result": "预览标注结果",
768+
"Hide annotator result": "隐藏标注结果",
757769

758770
"--------": "--------"
759771
}

localizations/zh_TW.json

+19-1
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,24 @@
744744
"Sample CFG Scale": "採樣擴散度",
745745
"Sample Steps": "採樣步數",
746746
"Cancel": "取消",
747-
747+
"Invert colors if your image has white background. Change your brush width to make it thinner if you want to draw something.": "如果您的圖像有白色背景,請反轉顏色。 如果你想畫東西,改變你的畫筆寬度讓它更細",
748+
"Enable": "啟用",
749+
"Invert Input Color": "反轉輸入顏色",
750+
"RGB to BGR": "RGB 轉為 BGR",
751+
"Low VRAM": "低 VRAM",
752+
"Guess Mode": "猜測模式",
753+
"Preprocessor": "預處理器",
754+
"Weight": "權重",
755+
"Guidance strength (T)": "引導強度 (T)",
756+
"Resize Mode": "調整模式",
757+
"Envelope (Outer Fit)": "信封(外部適配)",
758+
"Scale to Fit (Inner Fit)": "縮放以適合 (內部適配)",
759+
"Just Resize": "調整大小",
760+
"Canvas Width": "畫布寬度",
761+
"Canvas Height": "畫布高度",
762+
"Create blank canvas": "創建空白畫布",
763+
"Preview annotator result": "預覽標註結果",
764+
"Hide annotator result": "隱藏標註結果",
765+
748766
"--------": "--------"
749767
}

modules/sd_models.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,27 @@ def modeltitle(path, shorthash):
7979
return f'{name} [{shorthash}]', shortname
8080

8181
if shared.cmd_opts.pureui:
82-
params = {
83-
'module': 'Stable-diffusion', 'endpoint_name': sagemaker_endpoint
84-
}
85-
response = requests.get(url=f'{api_endpoint}/sd/models', params=params)
86-
if response.status_code == 200:
87-
model_list = json.loads(response.text)
88-
89-
for model in model_list:
90-
h = model['hash']
91-
filename = model['filename']
92-
title = model['title']
93-
short_model_name = model['model_name']
94-
config = model['config']
95-
96-
if 'sd_model_checkpoint' not in shared.opts.data:
97-
shared.opts.data['sd_model_checkpoint'] = title
98-
99-
checkpoints_list[title] = CheckpointInfo(filename, title, h, short_model_name, config)
82+
if sagemaker_endpoint:
83+
params = {
84+
'module': 'Stable-diffusion', 'endpoint_name': sagemaker_endpoint
85+
}
86+
response = requests.get(url=f'{api_endpoint}/sd/models', params=params)
87+
if response.status_code == 200:
88+
model_list = json.loads(response.text)
89+
90+
for model in model_list:
91+
h = model['hash']
92+
filename = model['filename']
93+
title = model['title']
94+
short_model_name = model['model_name']
95+
config = model['config']
96+
97+
if 'sd_model_checkpoint' not in shared.opts.data:
98+
shared.opts.data['sd_model_checkpoint'] = title
99+
100+
checkpoints_list[title] = CheckpointInfo(filename, title, h, short_model_name, config)
101+
else:
102+
print(response.text)
100103

101104
sd_model_checkpoint = shared.opts.data['sd_model_checkpoint']
102105
if sd_model_checkpoint and sd_model_checkpoint in checkpoints_list:

modules/shared.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,31 @@
144144
sagemaker_endpoint_component = None
145145
sd_model_checkpoint_component = None
146146
create_train_dreambooth_component = None
147+
username = ''
148+
149+
response = requests.get(url=f'{api_endpoint}/sd/industrialmodel')
150+
if response.status_code == 200:
151+
industrial_model = response.text
152+
else:
153+
model_name = 'stable-diffusion-webui'
154+
model_description = model_name
155+
inputs = {
156+
'model_algorithm': 'stable-diffusion-webui',
157+
'model_name': model_name,
158+
'model_description': model_description,
159+
'model_extra': '{"visible": "false"}',
160+
'model_samples': '',
161+
'file_content': {
162+
'data': [(lambda x: int(x))(x) for x in open(os.path.join(script_path, 'logo.ico'), 'rb').read()]
163+
}
164+
}
147165

148-
response = requests.get(url=f'{api_endpoint}/sd/industrialmodel')
166+
response = requests.post(url=f'{api_endpoint}/industrialmodel', json = inputs)
149167
if response.status_code == 200:
150-
industrial_model = response.text
168+
body = json.loads(response.text)
169+
industrial_model = body['id']
151170
else:
152-
model_name = 'stable-diffusion-webui'
153-
model_description = model_name
154-
inputs = {
155-
'model_algorithm': 'stable-diffusion-webui',
156-
'model_name': model_name,
157-
'model_description': model_description,
158-
'model_extra': '{"visible": "false"}',
159-
'model_samples': '',
160-
'file_content': {
161-
'data': [(lambda x: int(x))(x) for x in open(os.path.join(script_path, 'logo.ico'), 'rb').read()]
162-
}
163-
}
164-
165-
response = requests.post(url=f'{api_endpoint}/industrialmodel', json = inputs)
166-
if response.status_code == 200:
167-
body = json.loads(response.text)
168-
industrial_model = body['id']
169-
else:
170-
print(response.text)
171+
print(response.text)
171172

172173
def reload_hypernetworks():
173174
from modules.hypernetworks import hypernetwork
@@ -301,7 +302,9 @@ def list_checkpoint_tiles():
301302

302303
def refresh_checkpoints(sagemaker_endpoint=None):
303304
import modules.sd_models
304-
return modules.sd_models.list_models(sagemaker_endpoint)
305+
modules.sd_models.list_models(sagemaker_endpoint)
306+
checkpoints = modules.sd_models.checkpoints_list
307+
return checkpoints
305308

306309

307310
def list_samplers():
@@ -320,7 +323,7 @@ def list_sagemaker_endpoints():
320323

321324
return sagemaker_endpoints
322325

323-
def refresh_sagemaker_endpoints(username=None):
326+
def refresh_sagemaker_endpoints(username):
324327
global industrial_model, api_endpoint, sagemaker_endpoints
325328

326329
sagemaker_endpoints = []

modules/ui.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ def create_toprow(is_img2img):
416416
with gr.Column(scale=1, elem_id="roll_col"):
417417
roll = gr.Button(value=art_symbol, elem_id="roll", visible=len(shared.artist_db.artists) > 0)
418418
paste = gr.Button(value=paste_symbol, elem_id="paste")
419-
save_style = gr.Button(value=save_style_symbol, elem_id="style_create")
420-
prompt_style_apply = gr.Button(value=apply_style_symbol, elem_id="style_apply")
419+
save_style = gr.Button(value=save_style_symbol, elem_id="style_create", visible=False)
420+
prompt_style_apply = gr.Button(value=apply_style_symbol, elem_id="style_apply", visible=False)
421421

422422
token_counter = gr.HTML(value="<span></span>", elem_id=f"{id_part}_token_counter")
423423
token_button = gr.Button(visible=False, elem_id=f"{id_part}_token_button")
@@ -671,6 +671,15 @@ def open_folder(f):
671671
img2img_submit = None
672672
extras_submit = None
673673

674+
def update_sagemaker_endpoint():
675+
return gr.update(value=shared.opts.sagemaker_endpoint, choices=shared.sagemaker_endpoints)
676+
677+
def update_sd_model_checkpoint():
678+
return gr.update(value=shared.opts.sd_model_checkpoint, choices=modules.sd_models.checkpoint_tiles())
679+
680+
def update_username():
681+
return gr.update(value=shared.username)
682+
674683
def create_ui():
675684
import modules.img2img
676685
import modules.txt2img
@@ -1971,11 +1980,14 @@ def sagemaker_train_hypernetwork(
19711980
)
19721981

19731982
with gr.Blocks(analytics_enabled=False) as user_interface:
1983+
username_state = gr.Textbox(value="", elem_id="username", visible=False)
1984+
username_state.change(fn=None, inputs=[username_state], outputs=None, _js="function(username){var x=gradioApp().querySelector('#tabs').querySelectorAll('button')[5];x.style.display=(username=='admin'?'block':'none')}")
1985+
19741986
user_dataframe = gr.Dataframe(
1975-
headers=["username", "password", "options"],
1987+
headers=["Username", "Password", "Options"],
19761988
row_count=2,
19771989
col_count=(3,"fixed"),
1978-
label="Input Data",
1990+
label="User management (Only available for admin user)",
19791991
interactive=True,
19801992
visible=True,
19811993
datatype=["str","str","str"],
@@ -2049,9 +2061,14 @@ def save_userdata(user_dataframe, request: gr.Request):
20492061
save_userdata_btn.click(
20502062
save_userdata,
20512063
inputs=[user_dataframe],
2052-
outputs=[user_dataframe]
2064+
outputs=[user_dataframe],
2065+
_js="var if alert('Only admin user can save user data')"
20532066
)
20542067

2068+
user_interface.load(update_sagemaker_endpoint, inputs=None, outputs=[shared.sagemaker_endpoint_component])
2069+
user_interface.load(update_sd_model_checkpoint, inputs=None, outputs=[shared.sd_model_checkpoint_component])
2070+
user_interface.load(update_username, inputs=None, outputs=[username_state])
2071+
20552072
if cmd_opts.pureui:
20562073
interfaces += [
20572074
(txt2img_interface, "txt2img", "txt2img"),

modules/ui_extensions.py

+46-46
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def extension_table():
9191

9292
code += f"""
9393
<tr>
94-
<td><label><input class="gr-check-radio gr-checkbox" name="enable_{html.escape(ext.name)}" type="checkbox" {'checked="checked"' if ext.enabled else ''}>{html.escape(ext.name)}</label></td>
94+
<td><label><input class="gr-check-radio gr-checkbox" name="enable_{html.escape(ext.name)}" type="checkbox" disabled="true" {'checked="checked"' if ext.enabled else ''}>{html.escape(ext.name)}</label></td>
9595
<td>{remote}</td>
9696
<td{' class="extension_status"' if ext.remote is not None else ''}>{ext_status}</td>
9797
</tr>
@@ -243,8 +243,8 @@ def create_ui():
243243
with gr.TabItem("Installed"):
244244

245245
with gr.Row():
246-
apply = gr.Button(value="Apply and restart UI", variant="primary")
247-
check = gr.Button(value="Check for updates")
246+
apply = gr.Button(value="Apply and restart UI", variant="primary", visible=False)
247+
check = gr.Button(value="Check for updates", visible=False)
248248
extensions_disabled_list = gr.Text(elem_id="extensions_disabled_list", visible=False).style(container=False)
249249
extensions_update_list = gr.Text(elem_id="extensions_update_list", visible=False).style(container=False)
250250

@@ -263,48 +263,48 @@ def create_ui():
263263
inputs=[],
264264
outputs=[extensions_table],
265265
)
266-
267-
with gr.TabItem("Available"):
268-
with gr.Row():
269-
refresh_available_extensions_button = gr.Button(value="Load from:", variant="primary")
270-
available_extensions_index = gr.Text(value="https://raw.githubusercontent.com/wiki/AUTOMATIC1111/stable-diffusion-webui/Extensions-index.md", label="Extension index URL").style(container=False)
271-
extension_to_install = gr.Text(elem_id="extension_to_install", visible=False)
272-
install_extension_button = gr.Button(elem_id="install_extension_button", visible=False)
273-
274-
with gr.Row():
275-
hide_tags = gr.CheckboxGroup(value=["ads", "localization"], label="Hide extensions with tags", choices=["script", "ads", "localization"])
276-
277-
install_result = gr.HTML()
278-
available_extensions_table = gr.HTML()
279-
280-
refresh_available_extensions_button.click(
281-
fn=modules.ui.wrap_gradio_call(refresh_available_extensions, extra_outputs=[gr.update(), gr.update(), gr.update()]),
282-
inputs=[available_extensions_index, hide_tags],
283-
outputs=[available_extensions_index, available_extensions_table, hide_tags, install_result],
284-
)
285-
286-
install_extension_button.click(
287-
fn=modules.ui.wrap_gradio_call(install_extension_from_index, extra_outputs=[gr.update(), gr.update()]),
288-
inputs=[extension_to_install, hide_tags],
289-
outputs=[available_extensions_table, extensions_table, install_result],
290-
)
291-
292-
hide_tags.change(
293-
fn=modules.ui.wrap_gradio_call(refresh_available_extensions_for_tags, extra_outputs=[gr.update()]),
294-
inputs=[hide_tags],
295-
outputs=[available_extensions_table, install_result]
296-
)
297-
298-
with gr.TabItem("Install from URL"):
299-
install_url = gr.Text(label="URL for extension's git repository")
300-
install_dirname = gr.Text(label="Local directory name", placeholder="Leave empty for auto")
301-
install_button = gr.Button(value="Install", variant="primary")
302-
install_result = gr.HTML(elem_id="extension_install_result")
303-
304-
install_button.click(
305-
fn=modules.ui.wrap_gradio_call(install_extension_from_url, extra_outputs=[gr.update()]),
306-
inputs=[install_dirname, install_url],
307-
outputs=[extensions_table, install_result],
308-
)
266+
if not shared.cmd_opts.pureui:
267+
with gr.TabItem("Available"):
268+
with gr.Row():
269+
refresh_available_extensions_button = gr.Button(value="Load from:", variant="primary")
270+
available_extensions_index = gr.Text(value="https://raw.githubusercontent.com/wiki/AUTOMATIC1111/stable-diffusion-webui/Extensions-index.md", label="Extension index URL").style(container=False)
271+
extension_to_install = gr.Text(elem_id="extension_to_install", visible=False)
272+
install_extension_button = gr.Button(elem_id="install_extension_button", visible=False)
273+
274+
with gr.Row():
275+
hide_tags = gr.CheckboxGroup(value=["ads", "localization"], label="Hide extensions with tags", choices=["script", "ads", "localization"])
276+
277+
install_result = gr.HTML()
278+
available_extensions_table = gr.HTML()
279+
280+
refresh_available_extensions_button.click(
281+
fn=modules.ui.wrap_gradio_call(refresh_available_extensions, extra_outputs=[gr.update(), gr.update(), gr.update()]),
282+
inputs=[available_extensions_index, hide_tags],
283+
outputs=[available_extensions_index, available_extensions_table, hide_tags, install_result],
284+
)
285+
286+
install_extension_button.click(
287+
fn=modules.ui.wrap_gradio_call(install_extension_from_index, extra_outputs=[gr.update(), gr.update()]),
288+
inputs=[extension_to_install, hide_tags],
289+
outputs=[available_extensions_table, extensions_table, install_result],
290+
)
291+
292+
hide_tags.change(
293+
fn=modules.ui.wrap_gradio_call(refresh_available_extensions_for_tags, extra_outputs=[gr.update()]),
294+
inputs=[hide_tags],
295+
outputs=[available_extensions_table, install_result]
296+
)
297+
298+
with gr.TabItem("Install from URL"):
299+
install_url = gr.Text(label="URL for extension's git repository")
300+
install_dirname = gr.Text(label="Local directory name", placeholder="Leave empty for auto")
301+
install_button = gr.Button(value="Install", variant="primary")
302+
install_result = gr.HTML(elem_id="extension_install_result")
303+
304+
install_button.click(
305+
fn=modules.ui.wrap_gradio_call(install_extension_from_url, extra_outputs=[gr.update()]),
306+
inputs=[install_dirname, install_url],
307+
outputs=[extensions_table, install_result],
308+
)
309309

310310
return ui

requirements_versions.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ diffusers==0.3.0
33
accelerate==0.12.0
44
basicsr==1.4.2
55
gfpgan==1.3.8
6-
gradio==3.9
6+
gradio==3.16.2
77
numpy==1.23.3
88
Pillow==9.2.0
99
realesrgan==0.3.0

requirements_versions.txt.cn

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ diffusers==0.3.0
44
accelerate==0.12.0
55
basicsr==1.4.2
66
gfpgan==1.3.8
7-
gradio==3.9
7+
gradio==3.16.2
88
numpy==1.23.3
99
Pillow==9.2.0
1010
realesrgan==0.3.0

0 commit comments

Comments
 (0)