Spaces:
Sleeping
Sleeping
大幅改善。
Browse files
app.py
CHANGED
|
@@ -110,6 +110,13 @@ def make_html_table(caption):
|
|
| 110 |
def create_dummy_image(width=512, height=512, alpha=0):
|
| 111 |
return Image.new("RGBA", (width, height), (0, 0, 0, alpha))
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
def update_history():
|
| 114 |
tables_html = "".join(
|
| 115 |
f'<div style="margin-bottom:12px">{make_html_table(item[1])}</div>'
|
|
@@ -159,7 +166,11 @@ def infer(prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type,
|
|
| 159 |
progress(1.0, desc="Done!")
|
| 160 |
|
| 161 |
gallery_items = [(item[0], item[1]) for item in history]
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
import gc
|
| 165 |
import torch
|
|
@@ -307,17 +318,17 @@ with gr.Blocks(css=css, theme=gr.themes.Default(font=[gr.themes.GoogleFont("Play
|
|
| 307 |
gr.HTML('<section class="nobackground"><a href="https://civitai.com/models/1553716?modelVersionId=1855218" target="_blank">Link: Civitai</a></section>')
|
| 308 |
|
| 309 |
with gr.Row():
|
| 310 |
-
prompt = gr.Textbox(lines=1, placeholder="Prompt…", value="1girl, cocoart, masterpiece, anime,", label="Prompt")
|
| 311 |
-
neg = gr.Textbox(lines=1, placeholder="Negative prompt", value="low quality, worst quality, bad
|
| 312 |
with gr.Row():
|
| 313 |
seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
|
| 314 |
rand = gr.Checkbox(True, label="Randomize seed")
|
| 315 |
with gr.Row():
|
| 316 |
-
width = gr.Slider(256,
|
| 317 |
-
height = gr.Slider(256,
|
| 318 |
with gr.Row():
|
| 319 |
-
cfg = gr.Slider(1.0, 30.0, step=0.5, value=
|
| 320 |
-
steps = gr.Slider(1,
|
| 321 |
with gr.Row():
|
| 322 |
scheduler_type = gr.Radio(choices=["Euler Ancestral", "DPM++ 2M SDE"], value="Euler Ancestral", label="Scheduler")
|
| 323 |
run = gr.Button("Generate")
|
|
@@ -390,22 +401,31 @@ window.addEventListener('load', () => {
|
|
| 390 |
run.click(
|
| 391 |
fn=infer,
|
| 392 |
inputs=[prompt, neg, seed_sl, rand, width, height, cfg, steps, scheduler_type],
|
| 393 |
-
outputs=[img_out, history_gallery]
|
| 394 |
-
)
|
| 395 |
-
|
| 396 |
-
|
|
|
|
| 397 |
outputs=[history_tables]
|
| 398 |
)
|
| 399 |
|
| 400 |
# ページロード時に history から初期表示
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
demo.load(
|
| 402 |
fn=lambda: (
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
inputs=[],
|
| 407 |
outputs=[history_gallery, history_tables]
|
| 408 |
-
)
|
| 409 |
|
| 410 |
demo.queue()
|
| 411 |
demo.launch()
|
|
|
|
| 110 |
def create_dummy_image(width=512, height=512, alpha=0):
|
| 111 |
return Image.new("RGBA", (width, height), (0, 0, 0, alpha))
|
| 112 |
|
| 113 |
+
def update_history_tables_on_select(evt: gr.SelectData):
|
| 114 |
+
if evt.index is not None and 0 <= evt.index < len(history):
|
| 115 |
+
# 選択された画像のキャプションを取得
|
| 116 |
+
selected_caption = history[evt.index][1]
|
| 117 |
+
return make_html_table(selected_caption)
|
| 118 |
+
return "" # 何も選択されていない場合は空文字列を返す
|
| 119 |
+
|
| 120 |
def update_history():
|
| 121 |
tables_html = "".join(
|
| 122 |
f'<div style="margin-bottom:12px">{make_html_table(item[1])}</div>'
|
|
|
|
| 166 |
progress(1.0, desc="Done!")
|
| 167 |
|
| 168 |
gallery_items = [(item[0], item[1]) for item in history]
|
| 169 |
+
|
| 170 |
+
processed_img, processed_gallery_items = process_image(img, gallery_items)
|
| 171 |
+
|
| 172 |
+
latest_caption_table = make_html_table(caption_text)
|
| 173 |
+
return processed_img, processed_gallery_items, latest_caption_table
|
| 174 |
|
| 175 |
import gc
|
| 176 |
import torch
|
|
|
|
| 318 |
gr.HTML('<section class="nobackground"><a href="https://civitai.com/models/1553716?modelVersionId=1855218" target="_blank">Link: Civitai</a></section>')
|
| 319 |
|
| 320 |
with gr.Row():
|
| 321 |
+
prompt = gr.Textbox(lines=1, placeholder="Prompt…", value="1girl, cocoart, masterpiece, anime, high quality lighting,", label="Prompt")
|
| 322 |
+
neg = gr.Textbox(lines=1, placeholder="Negative prompt", value="low quality, worst quality, bad, lowres, error, miss stroke, smoke, ugly, extra digits, creepy, imprecise, blurry,", label="Negative prompt")
|
| 323 |
with gr.Row():
|
| 324 |
seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
|
| 325 |
rand = gr.Checkbox(True, label="Randomize seed")
|
| 326 |
with gr.Row():
|
| 327 |
+
width = gr.Slider(256, 768, step=32, value=512, label="Width")
|
| 328 |
+
height = gr.Slider(256, 1024, step=32, value=512, label="Height")
|
| 329 |
with gr.Row():
|
| 330 |
+
cfg = gr.Slider(1.0, 30.0, step=0.5, value=6, label="CFG Scale")
|
| 331 |
+
steps = gr.Slider(1, 12, step=1, value=12, label="Steps")
|
| 332 |
with gr.Row():
|
| 333 |
scheduler_type = gr.Radio(choices=["Euler Ancestral", "DPM++ 2M SDE"], value="Euler Ancestral", label="Scheduler")
|
| 334 |
run = gr.Button("Generate")
|
|
|
|
| 401 |
run.click(
|
| 402 |
fn=infer,
|
| 403 |
inputs=[prompt, neg, seed_sl, rand, width, height, cfg, steps, scheduler_type],
|
| 404 |
+
outputs=[img_out, history_gallery, history_tables]
|
| 405 |
+
)
|
| 406 |
+
history_gallery.select(
|
| 407 |
+
fn=update_history_tables_on_select,
|
| 408 |
+
inputs=None, # select イベントは自動的にイベントデータ (gr.SelectData) を渡す
|
| 409 |
outputs=[history_tables]
|
| 410 |
)
|
| 411 |
|
| 412 |
# ページロード時に history から初期表示
|
| 413 |
+
# demo.load(
|
| 414 |
+
# fn=lambda: (
|
| 415 |
+
# [(img_or_url, caption) for img_or_url, caption in history],
|
| 416 |
+
# "".join(f'<div style="margin-bottom:12px">{make_html_table(caption)}</div>' for _, caption in history)
|
| 417 |
+
# ),
|
| 418 |
+
# inputs=[],
|
| 419 |
+
# outputs=[history_gallery, history_tables]
|
| 420 |
+
# )
|
| 421 |
demo.load(
|
| 422 |
fn=lambda: (
|
| 423 |
+
[(img_or_url, caption) for img_or_url, caption in history],
|
| 424 |
+
make_html_table(history[0][1]) if history else ""
|
| 425 |
+
),
|
| 426 |
inputs=[],
|
| 427 |
outputs=[history_gallery, history_tables]
|
| 428 |
+
)
|
| 429 |
|
| 430 |
demo.queue()
|
| 431 |
demo.launch()
|