Spaces:
Running
Running
P01yH3dr0n
commited on
Commit
•
af12ece
1
Parent(s):
cf5a805
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ def get_count():
|
|
19 |
if now != today:
|
20 |
today = now
|
21 |
today_count = 0
|
22 |
-
return
|
23 |
|
24 |
def control_ui():
|
25 |
prompt = gr.TextArea(value="{breast expansion},{gigantic breasts},[artist:ningen_mame],artist:ciloranko,[artist:sho_(sho_lwlw)],[artist:foifoi (marfoyfoyfoy)],1girl,skinny,narrow waist,loli,", elem_id='txt2img_prompt', label="提示词", lines=3)
|
@@ -57,20 +57,17 @@ def control_ui():
|
|
57 |
info_extract = gr.Slider(label='参考信息提取', value=1, minimum=0, maximum=1, step=0.1)
|
58 |
ref_str = gr.Slider(label='参考强度', value=0.6, minimum=0, maximum=1, step=0.1)
|
59 |
reuse_img_vibe = gr.Button(value='使用上一次生成的图片')
|
60 |
-
with gr.Accordion('
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
with gr.Row():
|
68 |
-
use_inp = gr.Checkbox(label='启用', value=False)
|
69 |
overlay = gr.Checkbox(label='覆盖原图', value=True)
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
'''
|
74 |
with gr.Row():
|
75 |
with gr.Column():
|
76 |
with gr.Accordion('高级选项', open=False):
|
@@ -89,26 +86,27 @@ def control_ui():
|
|
89 |
dyn_threshold = gr.Checkbox(False, label="Dynamic Thresholding")
|
90 |
cfg_rescale = gr.Slider(0, 1, 0, step=0.01, label="CFG rescale")
|
91 |
with gr.Column():
|
92 |
-
gr.Textbox(value=get_count, label='使用统计', every=10)
|
93 |
save = gr.Checkbox(value=True, label='云端保存图片')
|
94 |
gen_btn = gr.Button(value="生成", variant="primary")
|
95 |
rand_seed.click(fn=lambda: -1, inputs=None, outputs=seed)
|
96 |
width.change(lambda w, h: h if w*h<=1024*1024 else (1024*1024//w//64)*64, [width, height], height)
|
97 |
height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
|
98 |
-
|
|
|
|
|
99 |
|
100 |
-
def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str, i2i_image, i2i_str, i2i_noise, save):
|
101 |
global today_count
|
102 |
set_token(os.environ.get('token'))
|
103 |
img_data, payload = generate_novelai_image(
|
104 |
f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
|
105 |
width, height, steps, sampler, scheduler,
|
106 |
smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str,
|
107 |
-
i2i_image, i2i_str, i2i_noise
|
108 |
)
|
109 |
if not isinstance(img_data, bytes):
|
110 |
return gr.Image(value=None), payload
|
111 |
-
today_count
|
112 |
img = image_from_bytes(img_data)
|
113 |
if save:
|
114 |
save_path = client_config['save_path']
|
@@ -139,6 +137,7 @@ def main_ui():
|
|
139 |
others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
|
140 |
others[3].click(lambda i: i, inputs=image, outputs=paras[14])
|
141 |
others[4].click(lambda i: i, inputs=image, outputs=paras[17])
|
|
|
142 |
return page, paras[:14]
|
143 |
|
144 |
def util_ui():
|
@@ -171,7 +170,7 @@ def ui():
|
|
171 |
load_javascript()
|
172 |
with gr.Blocks(title="NAI Client", theme=gr.themes.Base()) as website:
|
173 |
with gr.Tabs():
|
174 |
-
with gr.TabItem("
|
175 |
_, paras = main_ui()
|
176 |
with gr.TabItem("图片信息读取"):
|
177 |
_, png2main, png_items, info, image = util_ui()
|
|
|
19 |
if now != today:
|
20 |
today = now
|
21 |
today_count = 0
|
22 |
+
return today_count
|
23 |
|
24 |
def control_ui():
|
25 |
prompt = gr.TextArea(value="{breast expansion},{gigantic breasts},[artist:ningen_mame],artist:ciloranko,[artist:sho_(sho_lwlw)],[artist:foifoi (marfoyfoyfoy)],1girl,skinny,narrow waist,loli,", elem_id='txt2img_prompt', label="提示词", lines=3)
|
|
|
57 |
info_extract = gr.Slider(label='参考信息提取', value=1, minimum=0, maximum=1, step=0.1)
|
58 |
ref_str = gr.Slider(label='参考强度', value=0.6, minimum=0, maximum=1, step=0.1)
|
59 |
reuse_img_vibe = gr.Button(value='使用上一次生成的图片')
|
60 |
+
with gr.Accordion('附加输入', open=False):
|
61 |
+
with gr.Tab('图生图') as i2i:
|
62 |
+
i2i_image = gr.Image(label="上传图片", value=None, sources=["upload", "clipboard", "webcam"], interactive=True, type="pil")
|
63 |
+
i2i_str = gr.Slider(label='去噪强度', value=0.7, minimum=0, maximum=0.99, step=0.01)
|
64 |
+
i2i_noise = gr.Slider(label='噪声', value=0, minimum=0, maximum=1, step=0.1)
|
65 |
+
reuse_img_i2i = gr.Button(value='使用上一次生成的图片')
|
66 |
+
with gr.Tab('局部重绘') as inp:
|
|
|
|
|
67 |
overlay = gr.Checkbox(label='覆盖原图', value=True)
|
68 |
+
inp_img = gr.ImageMask(label="上传图片", value=None, sources=["upload", "clipboard", "webcam"], interactive=True, type="pil", eraser=False, transforms=None)
|
69 |
+
reuse_img_inp = gr.Button(value='使用上一次生成的图片')
|
70 |
+
selection = gr.Radio(choices=['i2i', 'inp'], value='i2i', visible=False)
|
|
|
71 |
with gr.Row():
|
72 |
with gr.Column():
|
73 |
with gr.Accordion('高级选项', open=False):
|
|
|
86 |
dyn_threshold = gr.Checkbox(False, label="Dynamic Thresholding")
|
87 |
cfg_rescale = gr.Slider(0, 1, 0, step=0.01, label="CFG rescale")
|
88 |
with gr.Column():
|
|
|
89 |
save = gr.Checkbox(value=True, label='云端保存图片')
|
90 |
gen_btn = gr.Button(value="生成", variant="primary")
|
91 |
rand_seed.click(fn=lambda: -1, inputs=None, outputs=seed)
|
92 |
width.change(lambda w, h: h if w*h<=1024*1024 else (1024*1024//w//64)*64, [width, height], height)
|
93 |
height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
|
94 |
+
i2i.select(lambda: 'i2i', inputs=None, outputs=selection)
|
95 |
+
inp.select(lambda: 'inp', inputs=None, outputs=selection)
|
96 |
+
return gen_btn, [prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection], [save, rand_seed, reuse_seed, reuse_img_vibe, reuse_img_i2i, reuse_img_inp]
|
97 |
|
98 |
+
def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection, save):
|
99 |
global today_count
|
100 |
set_token(os.environ.get('token'))
|
101 |
img_data, payload = generate_novelai_image(
|
102 |
f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
|
103 |
width, height, steps, sampler, scheduler,
|
104 |
smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str,
|
105 |
+
i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection
|
106 |
)
|
107 |
if not isinstance(img_data, bytes):
|
108 |
return gr.Image(value=None), payload
|
109 |
+
today_count = get_count() + 1
|
110 |
img = image_from_bytes(img_data)
|
111 |
if save:
|
112 |
save_path = client_config['save_path']
|
|
|
137 |
others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
|
138 |
others[3].click(lambda i: i, inputs=image, outputs=paras[14])
|
139 |
others[4].click(lambda i: i, inputs=image, outputs=paras[17])
|
140 |
+
others[5].click(lambda i: i, inputs=image, outputs=paras[21])
|
141 |
return page, paras[:14]
|
142 |
|
143 |
def util_ui():
|
|
|
170 |
load_javascript()
|
171 |
with gr.Blocks(title="NAI Client", theme=gr.themes.Base()) as website:
|
172 |
with gr.Tabs():
|
173 |
+
with gr.TabItem("图片生成", elem_id="client_ui_main"):
|
174 |
_, paras = main_ui()
|
175 |
with gr.TabItem("图片信息读取"):
|
176 |
_, png2main, png_items, info, image = util_ui()
|