Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,30 +21,27 @@ model_path = hf_hub_download(
|
|
| 21 |
filename="recocoamixXL3_coamixXL3.safetensors"
|
| 22 |
)
|
| 23 |
|
| 24 |
-
#
|
| 25 |
pipe = StableDiffusionXLPipeline.from_single_file(
|
| 26 |
model_path,
|
| 27 |
torch_dtype=torch_dtype,
|
| 28 |
use_safetensors=True
|
| 29 |
).to(device)
|
| 30 |
|
| 31 |
-
#
|
| 32 |
euler_scheduler = EulerAncestralDiscreteScheduler.from_config(
|
| 33 |
pipe.scheduler.config,
|
| 34 |
use_karras_sigmas=True
|
| 35 |
)
|
| 36 |
-
dpm_scheduler = DPMSolverMultistepScheduler.from_config(
|
| 37 |
-
pipe.scheduler.config
|
| 38 |
-
)
|
| 39 |
pipe.scheduler = euler_scheduler
|
| 40 |
|
| 41 |
-
#
|
| 42 |
history = []
|
| 43 |
|
| 44 |
-
# HTMLテーブル生成ヘルパー
|
| 45 |
def make_html_table(caption):
|
| 46 |
rows = caption.split("\n")
|
| 47 |
-
html = '<table style="width:100%;border-collapse:collapse;">'
|
| 48 |
for row in rows:
|
| 49 |
if ": " in row:
|
| 50 |
key, val = row.split(": ", 1)
|
|
@@ -55,19 +52,12 @@ def make_html_table(caption):
|
|
| 55 |
html += '</table>'
|
| 56 |
return html
|
| 57 |
|
| 58 |
-
|
| 59 |
-
def infer(
|
| 60 |
-
prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type,
|
| 61 |
-
progress=gr.Progress(track_tqdm=True)
|
| 62 |
-
):
|
| 63 |
if rand:
|
| 64 |
seed = random.randint(0, MAX_SEED)
|
| 65 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
pipe.scheduler = (
|
| 69 |
-
euler_scheduler if scheduler_type == "Euler Ancestral" else dpm_scheduler
|
| 70 |
-
)
|
| 71 |
pipe.scheduler.set_timesteps(steps)
|
| 72 |
|
| 73 |
def _callback(pipeline, step_idx, timestep, callback_kwargs):
|
|
@@ -86,7 +76,6 @@ def infer(
|
|
| 86 |
)
|
| 87 |
img = output.images[0]
|
| 88 |
|
| 89 |
-
# キャプション構築
|
| 90 |
caption_text = (
|
| 91 |
f"Prompt: {prompt}\n"
|
| 92 |
f"Negative: {neg or 'None'}\n"
|
|
@@ -96,27 +85,22 @@ def infer(
|
|
| 96 |
f"Steps: {steps}\n"
|
| 97 |
f"Scheduler: {scheduler_type}"
|
| 98 |
)
|
| 99 |
-
|
| 100 |
-
# 履歴に追加(最新を先頭)
|
| 101 |
history.insert(0, (img, caption_text))
|
| 102 |
progress(1.0, desc="Done!")
|
| 103 |
|
| 104 |
-
|
| 105 |
-
gallery_items = [
|
| 106 |
-
(item[0], make_html_table(item[1])) for item in history
|
| 107 |
-
]
|
| 108 |
return img, gallery_items
|
| 109 |
|
| 110 |
-
# CSS
|
| 111 |
css = """
|
| 112 |
body {
|
| 113 |
-
background-color: #f4e1c1;
|
| 114 |
-
color: #3b2f2f;
|
| 115 |
font-family: 'Georgia', serif;
|
|
|
|
| 116 |
}
|
| 117 |
-
|
| 118 |
-
background
|
| 119 |
-
color: #
|
| 120 |
}
|
| 121 |
#col-container {
|
| 122 |
background: #fffaf1;
|
|
@@ -126,11 +110,6 @@ body.dark {
|
|
| 126 |
margin: auto;
|
| 127 |
max-width: 780px;
|
| 128 |
}
|
| 129 |
-
#col-container a {
|
| 130 |
-
color: #8b5e3c;
|
| 131 |
-
text-decoration: none;
|
| 132 |
-
border-bottom: 1px dotted #8b5e3c;
|
| 133 |
-
}
|
| 134 |
.gr-button {
|
| 135 |
background-color: #d4a373 !important;
|
| 136 |
color: white !important;
|
|
@@ -183,19 +162,16 @@ with gr.Blocks(css=css) as demo:
|
|
| 183 |
|
| 184 |
with gr.Row():
|
| 185 |
prompt = gr.Textbox(lines=1, placeholder="Prompt…", value="1girl, cocoart, masterpiece, anime,")
|
| 186 |
-
neg = gr.Textbox(lines=1, placeholder="Negative prompt", value=
|
| 187 |
-
"low quality, worst quality, bad shadow, lowres, error, miss stroke, "
|
| 188 |
-
"sketch art, smoke, ugly, extra digits, creepy, imprecise, glowing blur,"
|
| 189 |
-
))
|
| 190 |
with gr.Row():
|
| 191 |
seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
|
| 192 |
-
rand
|
| 193 |
with gr.Row():
|
| 194 |
-
width
|
| 195 |
height = gr.Slider(256, MAX_SIZE, step=32, value=512, label="Height")
|
| 196 |
with gr.Row():
|
| 197 |
-
cfg
|
| 198 |
-
steps
|
| 199 |
with gr.Row():
|
| 200 |
scheduler_type = gr.Radio(choices=["Euler Ancestral", "DPM++ 2M SDE"], value="Euler Ancestral", label="Scheduler")
|
| 201 |
run = gr.Button("Generate")
|
|
@@ -220,7 +196,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 220 |
)
|
| 221 |
|
| 222 |
img_out = gr.Image()
|
| 223 |
-
state
|
| 224 |
history_gallery = gr.Gallery(label="生成履歴", columns=4, height=280, show_label=False, interactive=True, type="pil")
|
| 225 |
|
| 226 |
run.click(
|
|
|
|
| 21 |
filename="recocoamixXL3_coamixXL3.safetensors"
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# パイプライン構築
|
| 25 |
pipe = StableDiffusionXLPipeline.from_single_file(
|
| 26 |
model_path,
|
| 27 |
torch_dtype=torch_dtype,
|
| 28 |
use_safetensors=True
|
| 29 |
).to(device)
|
| 30 |
|
| 31 |
+
# スケジューラ設定
|
| 32 |
euler_scheduler = EulerAncestralDiscreteScheduler.from_config(
|
| 33 |
pipe.scheduler.config,
|
| 34 |
use_karras_sigmas=True
|
| 35 |
)
|
| 36 |
+
dpm_scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
| 37 |
pipe.scheduler = euler_scheduler
|
| 38 |
|
| 39 |
+
# 履歴保存
|
| 40 |
history = []
|
| 41 |
|
|
|
|
| 42 |
def make_html_table(caption):
|
| 43 |
rows = caption.split("\n")
|
| 44 |
+
html = '<table style="width:100%;border-collapse:collapse;background:#fffaf1;color:#000">'
|
| 45 |
for row in rows:
|
| 46 |
if ": " in row:
|
| 47 |
key, val = row.split(": ", 1)
|
|
|
|
| 52 |
html += '</table>'
|
| 53 |
return html
|
| 54 |
|
| 55 |
+
def infer(prompt, neg, seed, rand, w, h, cfg, steps, scheduler_type, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
if rand:
|
| 57 |
seed = random.randint(0, MAX_SEED)
|
| 58 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 59 |
|
| 60 |
+
pipe.scheduler = euler_scheduler if scheduler_type == "Euler Ancestral" else dpm_scheduler
|
|
|
|
|
|
|
|
|
|
| 61 |
pipe.scheduler.set_timesteps(steps)
|
| 62 |
|
| 63 |
def _callback(pipeline, step_idx, timestep, callback_kwargs):
|
|
|
|
| 76 |
)
|
| 77 |
img = output.images[0]
|
| 78 |
|
|
|
|
| 79 |
caption_text = (
|
| 80 |
f"Prompt: {prompt}\n"
|
| 81 |
f"Negative: {neg or 'None'}\n"
|
|
|
|
| 85 |
f"Steps: {steps}\n"
|
| 86 |
f"Scheduler: {scheduler_type}"
|
| 87 |
)
|
|
|
|
|
|
|
| 88 |
history.insert(0, (img, caption_text))
|
| 89 |
progress(1.0, desc="Done!")
|
| 90 |
|
| 91 |
+
gallery_items = [(item[0], make_html_table(item[1])) for item in history]
|
|
|
|
|
|
|
|
|
|
| 92 |
return img, gallery_items
|
| 93 |
|
| 94 |
+
# CSS 設定(ダークモード強制防止+カフェ風テーマ)
|
| 95 |
css = """
|
| 96 |
body {
|
| 97 |
+
background-color: #f4e1c1 !important;
|
|
|
|
| 98 |
font-family: 'Georgia', serif;
|
| 99 |
+
color: #000 !important;
|
| 100 |
}
|
| 101 |
+
html, .gradio-container, .dark, .dark * {
|
| 102 |
+
background: #fffaf1 !important;
|
| 103 |
+
color: #000 !important;
|
| 104 |
}
|
| 105 |
#col-container {
|
| 106 |
background: #fffaf1;
|
|
|
|
| 110 |
margin: auto;
|
| 111 |
max-width: 780px;
|
| 112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
.gr-button {
|
| 114 |
background-color: #d4a373 !important;
|
| 115 |
color: white !important;
|
|
|
|
| 162 |
|
| 163 |
with gr.Row():
|
| 164 |
prompt = gr.Textbox(lines=1, placeholder="Prompt…", value="1girl, cocoart, masterpiece, anime,")
|
| 165 |
+
neg = gr.Textbox(lines=1, placeholder="Negative prompt", value="low quality, worst quality, bad shadow, lowres, error, miss stroke, sketch art, smoke, ugly, extra digits, creepy, imprecise, glowing blur,")
|
|
|
|
|
|
|
|
|
|
| 166 |
with gr.Row():
|
| 167 |
seed_sl = gr.Slider(0, MAX_SEED, step=1, value=0, label="Seed")
|
| 168 |
+
rand = gr.Checkbox(True, label="Randomize seed")
|
| 169 |
with gr.Row():
|
| 170 |
+
width = gr.Slider(256, MAX_SIZE, step=32, value=512, label="Width")
|
| 171 |
height = gr.Slider(256, MAX_SIZE, step=32, value=512, label="Height")
|
| 172 |
with gr.Row():
|
| 173 |
+
cfg = gr.Slider(1.0, 30.0, step=0.1, value=7.5, label="CFG Scale")
|
| 174 |
+
steps = gr.Slider(1, 50, step=1, value=12, label="Steps")
|
| 175 |
with gr.Row():
|
| 176 |
scheduler_type = gr.Radio(choices=["Euler Ancestral", "DPM++ 2M SDE"], value="Euler Ancestral", label="Scheduler")
|
| 177 |
run = gr.Button("Generate")
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
img_out = gr.Image()
|
| 199 |
+
state = gr.State([])
|
| 200 |
history_gallery = gr.Gallery(label="生成履歴", columns=4, height=280, show_label=False, interactive=True, type="pil")
|
| 201 |
|
| 202 |
run.click(
|