Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyongliang committed Mar 11, 2023
2 parents 9f7dec7 + bdd7135 commit d6a61ab
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 357 deletions.
35 changes: 27 additions & 8 deletions localizations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,13 @@
"[wiki]": "[wiki文档]",
"Embedding": "Embedding",
"Embedding Learning rate": "Embedding 学习率",
"Gradient accumulation steps": "梯度累计步数",
"Shuffle tags by ',' when creating prompts.": "创建提示时按“,”打乱标签。",
"Drop out tags when creating prompts.": "创建提示时删除标签。",
"Choose latent sampling method": "选择隐采样方法",
"Hypernetwork Learning rate": "Hypernetwork 学习率",
"Select activation function of hypernetwork. Recommended : Swish / Linear(none)": "选择 Hypernetwork 的激活函数,推荐Swish / Linear(none)",
"Select Layer weights initialization. Recommended: Kaiming for relu-like, Xavier for sigmoid-like, Normal otherwise": "选择图层权重初始化。 推荐:Kaiming 用于 relu-like,Xavier 用于 sigmoid-like,否则为 Normal",
"Dataset directory": "数据集目录",
"Log directory": "日志目录",
"Prompt template file": "提示词模版文件",
Expand Down Expand Up @@ -625,17 +631,11 @@
"Train settings": "训练设置",
"Train an hypernetwork; you must specify a directory with a set of 1:1 ratio images": "训练 hypernetwork; 必须指定一组具有 1:1 比例图像的目录",
"Hypernetwork settings": "Hypernetwork 设置",
"Sign Options": "登陆选项",
"Sign In": "登入",
"Sign Up": "注册",
"Sign Out": "登出",
"Username": "用户名",
"Password": "密码",
"Email": "电子邮箱",
"Mismatched username/password or not existed username": "用户名/密码不匹配或用户不存在",
"Signup failed, please check and retry again": "注册失败,请检查后并重试",
"Update failed, please check and retry again": "更新失败,请检查后并重试",
"Options": "选项",
"Output": "输出",
"User management (Only available for admin user)": "用户管理 (仅管理员用户可用)",
"Images S3 URI": "图像 S3 位置",
"Models S3 URI": "模型 S3 位置",
"Instance type": "实例类型",
Expand Down Expand Up @@ -754,6 +754,25 @@
"Sample CFG Scale": "采样扩散度",
"Sample Steps": "采样步数",
"Cancel": "取消",
"Invert colors if your image has white background.": "如果您的图像有白色背景,请反转颜色。 ",
"Change your brush width to make it thinner if you want to draw something.": "如果你想画东西,改变你的画笔宽度让它更细。",
"Enable": "启用",
"Invert Input Color": "反转输入颜色",
"RGB to BGR": "RGB 转为 BGR",
"Low VRAM": "低 VRAM",
"Guess Mode": "猜测模式",
"Preprocessor": "预处理器",
"Weight": "权重",
"Guidance strength (T)": "引导强度 (T)",
"Resize Mode": "调整模式",
"Envelope (Outer Fit)": "信封(外部适配)",
"Scale to Fit (Inner Fit)": "缩放以适合 (内部适配)",
"Just Resize": "调整大小",
"Canvas Width": "画布宽度",
"Canvas Height": "画布高度",
"Create blank canvas": "创建空白画布",
"Preview annotator result": "预览标注结果",
"Hide annotator result": "隐藏标注结果",

"--------": "--------"
}
30 changes: 26 additions & 4 deletions localizations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,12 @@
"[wiki]": "[wiki文件]",
"Embedding": "Embedding",
"Embedding Learning rate": "Embedding 學習率",
"Hypernetwork Learning rate": "超網路(Hypernetwork)學習率",
"Gradient accumulation steps": "梯度累計步數",
"Shuffle tags by ',' when creating prompts.": "創建提示時按“,”打亂標籤。",
"Drop out tags when creating prompts.": "創建提示時刪除標籤。",
"Choose latent sampling method": "選擇隱採樣方法",
"Hypernetwork Learning rate": "Hypernetwork 學習率",
"Select activation function of hypernetwork. Recommended : Swish / Linear(none)": "選擇 Hypernetwork 的激活函數,推薦Swish / Linear(none)",
"Learning rate": "學習率",
"Dataset directory": "資料集目錄",
"Log directory": "日誌目錄",
Expand Down Expand Up @@ -338,7 +343,6 @@
"End Page": "尾頁",
"number of images to delete consecutively next": "接下來要連續刪除的圖像數",
"delete next": "刪除下一張",
"Delete": "刪除",
"sort by": "排序方式",
"path name": "路徑名",
"date": "日期",
Expand Down Expand Up @@ -489,7 +493,6 @@
"Check for updates": "檢查更新",
"Extension": "擴充",
"URL": "網址",
"Update": "更新",
"a1111-sd-webui-tagcomplete": "標記自動補全",
"unknown": "未知",
"deforum-for-automatic1111-webui": "Deforum",
Expand Down Expand Up @@ -744,6 +747,25 @@
"Sample CFG Scale": "採樣擴散度",
"Sample Steps": "採樣步數",
"Cancel": "取消",

"Invert colors if your image has white background.": "如果您的圖像有白色背景,請反轉顏色。 ",
"Change your brush width to make it thinner if you want to draw something.": "如果你想畫東西,改變你的畫筆寬度讓它更細。",
"Enable": "啟用",
"Invert Input Color": "反轉輸入顏色",
"RGB to BGR": "RGB 轉為 BGR",
"Low VRAM": "低 VRAM",
"Guess Mode": "猜測模式",
"Preprocessor": "預處理器",
"Weight": "權重",
"Guidance strength (T)": "引導強度 (T)",
"Resize Mode": "調整模式",
"Envelope (Outer Fit)": "信封(外部適配)",
"Scale to Fit (Inner Fit)": "縮放以適合 (內部適配)",
"Just Resize": "調整大小",
"Canvas Width": "畫布寬度",
"Canvas Height": "畫布高度",
"Create blank canvas": "創建空白畫布",
"Preview annotator result": "預覽標註結果",
"Hide annotator result": "隱藏標註結果",

"--------": "--------"
}
24 changes: 17 additions & 7 deletions modules/call_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from PIL import Image, ImageOps, ImageFilter, ImageEnhance, ImageChops

from modules import shared
import gradio as gr

queue_lock = threading.Lock()

Expand All @@ -31,7 +32,7 @@ def f(*args, **kwargs):

return f

def wrap_gradio_gpu_call(func, extra_outputs=None):
def wrap_gradio_gpu_call(func, extra_outputs=None):
def encode_image_to_base64(image):
if isinstance(image, bytes):
encoded_string = base64.b64encode(image)
Expand Down Expand Up @@ -408,19 +409,16 @@ def sagemaker_inference(task, infer, username, sagemaker_endpoint, *args, **kwar
info = processed['html_info']
return images, modules.ui.plaintext_to_html(info), ''

def f(*args, **kwargs):
def f(username, *args, **kwargs):
if cmd_opts.pureui and func == modules.txt2img.txt2img:
username = args[len(args) - 2]
sagemaker_endpoint = args[len(args) -1]
args = args[:-2]
res = sagemaker_inference('text-to-image', 'sync', username, sagemaker_endpoint, *args, **kwargs)
elif cmd_opts.pureui and func == modules.img2img.img2img:
username = args[len(args) - 2]
sagemaker_endpoint = args[len(args) -1]
args = args[:-2]
res = sagemaker_inference('image-to-image', 'sync', username, sagemaker_endpoint, *args, **kwargs)
elif cmd_opts.pureui and func == modules.extras.run_extras:
username = args[len(args) - 2]
sagemaker_endpoint = args[len(args) -1]
args = args[:-2]
res = sagemaker_inference('extras', 'sync', username, sagemaker_endpoint, *args, **kwargs)
Expand All @@ -436,14 +434,26 @@ def f(*args, **kwargs):


def wrap_gradio_call(func, extra_outputs=None, add_stats=False):
def f(*args, extra_outputs_array=extra_outputs, **kwargs):
def f(request: gr.Request, *args, extra_outputs_array=extra_outputs, **kwargs):
tokens = shared.demo.server_app.tokens
cookies = request.headers['cookie'].split('; ')
access_token = None
for cookie in cookies:
if cookie.startswith('access-token'):
access_token = cookie[len('access-token=') : ]
break
username = tokens[access_token]

run_memmon = shared.opts.memmon_poll_rate > 0 and not shared.mem_mon.disabled and add_stats
if run_memmon:
shared.mem_mon.monitor()
t = time.perf_counter()

try:
res = list(func(*args, **kwargs))
if func.__name__ == 'f':
res = list(func(username, *args, **kwargs))
else:
res = list(func(*args, **kwargs))
except Exception as e:
# When printing out our debug argument list, do not print out more than a MB of text
max_debug_str_len = 131072 # (1024*1024)/8
Expand Down
39 changes: 21 additions & 18 deletions modules/sd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,27 @@ def modeltitle(path, shorthash):
return f'{name} [{shorthash}]', shortname

if shared.cmd_opts.pureui:
params = {
'module': 'Stable-diffusion', 'endpoint_name': sagemaker_endpoint
}
response = requests.get(url=f'{api_endpoint}/sd/models', params=params)
if response.status_code == 200:
model_list = json.loads(response.text)

for model in model_list:
h = model['hash']
filename = model['filename']
title = model['title']
short_model_name = model['model_name']
config = model['config']

if 'sd_model_checkpoint' not in shared.opts.data:
shared.opts.data['sd_model_checkpoint'] = title

checkpoints_list[title] = CheckpointInfo(filename, title, h, short_model_name, config)
if sagemaker_endpoint:
params = {
'module': 'Stable-diffusion', 'endpoint_name': sagemaker_endpoint
}
response = requests.get(url=f'{api_endpoint}/sd/models', params=params)
if response.status_code == 200:
model_list = json.loads(response.text)

for model in model_list:
h = model['hash']
filename = model['filename']
title = model['title']
short_model_name = model['model_name']
config = model['config']

if 'sd_model_checkpoint' not in shared.opts.data:
shared.opts.data['sd_model_checkpoint'] = title

checkpoints_list[title] = CheckpointInfo(filename, title, h, short_model_name, config)
else:
print(response.text)

sd_model_checkpoint = shared.opts.data['sd_model_checkpoint']
if sd_model_checkpoint and sd_model_checkpoint in checkpoints_list:
Expand Down
7 changes: 5 additions & 2 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
sagemaker_endpoint_component = None
sd_model_checkpoint_component = None
create_train_dreambooth_component = None
username = ''

response = requests.get(url=f'{api_endpoint}/sd/industrialmodel')
if response.status_code == 200:
Expand Down Expand Up @@ -301,7 +302,9 @@ def list_checkpoint_tiles():

def refresh_checkpoints(sagemaker_endpoint=None):
import modules.sd_models
return modules.sd_models.list_models(sagemaker_endpoint)
modules.sd_models.list_models(sagemaker_endpoint)
checkpoints = modules.sd_models.checkpoints_list
return checkpoints


def list_samplers():
Expand All @@ -320,7 +323,7 @@ def list_sagemaker_endpoints():

return sagemaker_endpoints

def refresh_sagemaker_endpoints(username=None):
def refresh_sagemaker_endpoints(username):
global industrial_model, api_endpoint, sagemaker_endpoints

sagemaker_endpoints = []
Expand Down
Loading

0 comments on commit d6a61ab

Please sign in to comment.