P01yH3dr0n commited on
Commit
6a54251
1 Parent(s): 76a000e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -1,11 +1,16 @@
1
  import os
2
  import datetime
3
 
 
4
  import gradio as gr
5
  from pnginfo import read_info_from_image, send_paras
 
6
 
7
  from utils import set_token, generate_novelai_image, image_from_bytes
 
8
 
 
 
9
  today_count = 0
10
  today = datetime.date.today().strftime('%Y-%m-%d')
11
 
@@ -21,11 +26,11 @@ def control_ui():
21
  prompt = gr.TextArea(label="Prompt", lines=3)
22
  quality_tags = gr.TextArea(
23
  label="Quality Tags", lines=1,
24
- value="best quality, amazing quality, very aesthetic, absurdres",
25
  )
26
  neg_prompt = gr.TextArea(
27
  label="Negative Prompt", lines=1,
28
- value="wide hip,thick thighs,plump,lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract],pubic hair",
29
  )
30
  with gr.Row():
31
  sampler = gr.Dropdown(
@@ -75,10 +80,10 @@ def control_ui():
75
  return gen_btn,[prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale], [save, rand_seed, reuse_seed]
76
 
77
 
78
- async def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, save):
79
  global today_count
80
- set_token(os.environ.get('token'))
81
- img_data, payload = await generate_novelai_image(
82
  f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
83
  width, height, steps, sampler, scheduler,
84
  smea, dyn, dyn_threshold, cfg_rescale
@@ -88,6 +93,18 @@ async def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height,
88
  today_count += 1
89
  img = image_from_bytes(img_data)
90
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  return img, payload
92
 
93
 
@@ -130,6 +147,8 @@ def ui():
130
  _, paras = main_ui()
131
  with gr.TabItem("PNG Info"):
132
  _, png2main, png_items, info, image = util_ui()
 
 
133
  png2main.click(fn=send_paras,
134
  inputs=[png_items] + paras,
135
  outputs=paras)
@@ -137,6 +156,13 @@ def ui():
137
  js="(x) => { if (x !== null) document.getElementById('client_ui_main-button').click(); "
138
  "return null; }",
139
  inputs=image)
 
 
 
 
 
 
 
140
  image.change(read_info_from_image, inputs=image, outputs=[info, png_items])
141
  return website
142
 
@@ -144,4 +170,4 @@ def ui():
144
  if __name__ == '__main__':
145
  website = ui()
146
  website.queue()
147
- website.launch(auth=(os.environ.get('account'), os.environ.get('password')))
 
1
  import os
2
  import datetime
3
 
4
+ import toml
5
  import gradio as gr
6
  from pnginfo import read_info_from_image, send_paras
7
+ from images_history import img_history_ui
8
 
9
  from utils import set_token, generate_novelai_image, image_from_bytes
10
+ from PIL import PngImagePlugin
11
 
12
+
13
+ client_config = toml.load("config.toml")['client']
14
  today_count = 0
15
  today = datetime.date.today().strftime('%Y-%m-%d')
16
 
 
26
  prompt = gr.TextArea(label="Prompt", lines=3)
27
  quality_tags = gr.TextArea(
28
  label="Quality Tags", lines=1,
29
+ value=client_config['default_quality'],
30
  )
31
  neg_prompt = gr.TextArea(
32
  label="Negative Prompt", lines=1,
33
+ value=client_config['default_neg'],
34
  )
35
  with gr.Row():
36
  sampler = gr.Dropdown(
 
80
  return gen_btn,[prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale], [save, rand_seed, reuse_seed]
81
 
82
 
83
+ def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, save):
84
  global today_count
85
+ set_token(client_config['token'])
86
+ img_data, payload = generate_novelai_image(
87
  f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
88
  width, height, steps, sampler, scheduler,
89
  smea, dyn, dyn_threshold, cfg_rescale
 
93
  today_count += 1
94
  img = image_from_bytes(img_data)
95
 
96
+ if save:
97
+ save_path = client_config['save_path']
98
+ today = datetime.date.today().strftime('%Y-%m-%d')
99
+ today_path = os.path.join(save_path, today)
100
+ if not os.path.exists(today_path):
101
+ os.makedirs(today_path, mode=777, exist_ok=True)
102
+ filename = str(today_count).rjust(5, '0') + '-' + str(payload['parameters']['seed']) + '.png'
103
+ pnginfo_data = PngImagePlugin.PngInfo()
104
+ for k, v in img.info.items():
105
+ pnginfo_data.add_text(k, str(v))
106
+ img.save(os.path.join(today_path, filename), pnginfo=pnginfo_data)
107
+
108
  return img, payload
109
 
110
 
 
147
  _, paras = main_ui()
148
  with gr.TabItem("PNG Info"):
149
  _, png2main, png_items, info, image = util_ui()
150
+ with gr.TabItem("Image Browser") as tab:
151
+ gal2main, gal_items = img_history_ui(tab)
152
  png2main.click(fn=send_paras,
153
  inputs=[png_items] + paras,
154
  outputs=paras)
 
156
  js="(x) => { if (x !== null) document.getElementById('client_ui_main-button').click(); "
157
  "return null; }",
158
  inputs=image)
159
+ gal2main.click(fn=send_paras,
160
+ inputs=[gal_items] + paras,
161
+ outputs=paras)
162
+ gal2main.click(fn=None,
163
+ js="(x) => { if (x !== null) document.getElementById('client_ui_main-button').click(); "
164
+ "return null; }",
165
+ inputs=gal_items)
166
  image.change(read_info_from_image, inputs=image, outputs=[info, png_items])
167
  return website
168
 
 
170
  if __name__ == '__main__':
171
  website = ui()
172
  website.queue()
173
+ website.launch()