Update app.py
Browse files
app.py
CHANGED
|
@@ -375,7 +375,7 @@ def resize_image(image, max_size=512):
|
|
| 375 |
return image
|
| 376 |
|
| 377 |
# ===== Functions =====
|
| 378 |
-
def colorize(sketch, base_model, anime_model, prompt, seed, steps, scale, cn_weight):
|
| 379 |
try:
|
| 380 |
# ตรวจสอบว่าเป็น SDXL model หรือไม่
|
| 381 |
if is_sdxl_model(base_model):
|
|
@@ -410,6 +410,7 @@ def colorize(sketch, base_model, anime_model, prompt, seed, steps, scale, cn_wei
|
|
| 410 |
with torch.inference_mode():
|
| 411 |
out = pipe(
|
| 412 |
prompt,
|
|
|
|
| 413 |
image=lineart,
|
| 414 |
num_inference_steps=int(steps),
|
| 415 |
guidance_scale=float(scale),
|
|
@@ -427,7 +428,7 @@ def colorize(sketch, base_model, anime_model, prompt, seed, steps, scale, cn_wei
|
|
| 427 |
error_img = Image.new('RGB', (512, 512), color='red')
|
| 428 |
return error_img, Image.new('RGB', (512, 512), color='gray')
|
| 429 |
|
| 430 |
-
def t2i(prompt, model, seed, steps, scale, w, h):
|
| 431 |
try:
|
| 432 |
load_t2i_model(model)
|
| 433 |
print(f"🖼️ Using T2I model: {model}")
|
|
@@ -442,6 +443,7 @@ def t2i(prompt, model, seed, steps, scale, w, h):
|
|
| 442 |
height = max(int(h), 512)
|
| 443 |
result = CURRENT_T2I_PIPE(
|
| 444 |
prompt,
|
|
|
|
| 445 |
width=width,
|
| 446 |
height=height,
|
| 447 |
num_inference_steps=int(steps),
|
|
@@ -451,6 +453,7 @@ def t2i(prompt, model, seed, steps, scale, w, h):
|
|
| 451 |
else:
|
| 452 |
result = CURRENT_T2I_PIPE(
|
| 453 |
prompt,
|
|
|
|
| 454 |
width=int(w),
|
| 455 |
height=int(h),
|
| 456 |
num_inference_steps=int(steps),
|
|
@@ -573,9 +576,14 @@ with gr.Blocks(title="🎨 Advanced Image Generation Suite", theme=gr.themes.Sof
|
|
| 573 |
placeholder="e.g., 1girl, blonde hair, blue eyes, beautiful, masterpiece",
|
| 574 |
lines=2
|
| 575 |
)
|
| 576 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
|
| 578 |
with gr.Row():
|
|
|
|
| 579 |
steps = gr.Slider(10, 50, 25, step=1, label="Steps")
|
| 580 |
scale = gr.Slider(1, 20, 8, step=0.5, label="CFG Scale")
|
| 581 |
cn_weight = gr.Slider(0.5, 1.5, 1.0, step=0.1, label="ControlNet Weight")
|
|
@@ -583,7 +591,7 @@ with gr.Blocks(title="🎨 Advanced Image Generation Suite", theme=gr.themes.Sof
|
|
| 583 |
run = gr.Button("🎨 Colorize", variant="primary")
|
| 584 |
run.click(
|
| 585 |
colorize,
|
| 586 |
-
[inp, base_model, anime_chk, prompt, seed, steps, scale, cn_weight],
|
| 587 |
[out, sketch_out]
|
| 588 |
)
|
| 589 |
|
|
@@ -603,13 +611,18 @@ with gr.Blocks(title="🎨 Advanced Image Generation Suite", theme=gr.themes.Sof
|
|
| 603 |
lines=3,
|
| 604 |
placeholder="e.g., a beautiful landscape with mountains and a lake at sunset, highly detailed, 4k"
|
| 605 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
t2i_model = gr.Dropdown(
|
| 607 |
choices=ALL_MODELS, # ใช้ทั้ง SD1.5 และ SDXL
|
| 608 |
value="digiplay/ChikMix_V3",
|
| 609 |
label="Model"
|
| 610 |
)
|
| 611 |
-
|
| 612 |
-
with gr.Row():
|
| 613 |
t2i_seed = gr.Number(value=42, label="Seed")
|
| 614 |
t2i_steps = gr.Slider(10, 50, 30, step=1, label="Steps")
|
| 615 |
t2i_scale = gr.Slider(1, 20, 7.5, step=0.5, label="CFG Scale")
|
|
@@ -622,7 +635,7 @@ with gr.Blocks(title="🎨 Advanced Image Generation Suite", theme=gr.themes.Sof
|
|
| 622 |
gen_btn = gr.Button("🖼️ Generate", variant="primary")
|
| 623 |
gen_btn.click(
|
| 624 |
t2i,
|
| 625 |
-
[t2i_prompt, t2i_model, t2i_seed, t2i_steps, t2i_scale, w, h],
|
| 626 |
t2i_out
|
| 627 |
)
|
| 628 |
|
|
|
|
| 375 |
return image
|
| 376 |
|
| 377 |
# ===== Functions =====
|
| 378 |
+
def colorize(sketch, base_model, anime_model, prompt, negative_prompt, seed, steps, scale, cn_weight):
|
| 379 |
try:
|
| 380 |
# ตรวจสอบว่าเป็น SDXL model หรือไม่
|
| 381 |
if is_sdxl_model(base_model):
|
|
|
|
| 410 |
with torch.inference_mode():
|
| 411 |
out = pipe(
|
| 412 |
prompt,
|
| 413 |
+
negative_prompt=negative_prompt,
|
| 414 |
image=lineart,
|
| 415 |
num_inference_steps=int(steps),
|
| 416 |
guidance_scale=float(scale),
|
|
|
|
| 428 |
error_img = Image.new('RGB', (512, 512), color='red')
|
| 429 |
return error_img, Image.new('RGB', (512, 512), color='gray')
|
| 430 |
|
| 431 |
+
def t2i(prompt, negative_prompt, model, seed, steps, scale, w, h):
|
| 432 |
try:
|
| 433 |
load_t2i_model(model)
|
| 434 |
print(f"🖼️ Using T2I model: {model}")
|
|
|
|
| 443 |
height = max(int(h), 512)
|
| 444 |
result = CURRENT_T2I_PIPE(
|
| 445 |
prompt,
|
| 446 |
+
negative_prompt=negative_prompt,
|
| 447 |
width=width,
|
| 448 |
height=height,
|
| 449 |
num_inference_steps=int(steps),
|
|
|
|
| 453 |
else:
|
| 454 |
result = CURRENT_T2I_PIPE(
|
| 455 |
prompt,
|
| 456 |
+
negative_prompt=negative_prompt,
|
| 457 |
width=int(w),
|
| 458 |
height=int(h),
|
| 459 |
num_inference_steps=int(steps),
|
|
|
|
| 576 |
placeholder="e.g., 1girl, blonde hair, blue eyes, beautiful, masterpiece",
|
| 577 |
lines=2
|
| 578 |
)
|
| 579 |
+
negative_prompt = gr.Textbox(
|
| 580 |
+
label="Negative Prompt",
|
| 581 |
+
placeholder="e.g., ugly, deformed, bad anatomy, blurry",
|
| 582 |
+
lines=2
|
| 583 |
+
)
|
| 584 |
|
| 585 |
with gr.Row():
|
| 586 |
+
seed = gr.Number(value=42, label="Seed")
|
| 587 |
steps = gr.Slider(10, 50, 25, step=1, label="Steps")
|
| 588 |
scale = gr.Slider(1, 20, 8, step=0.5, label="CFG Scale")
|
| 589 |
cn_weight = gr.Slider(0.5, 1.5, 1.0, step=0.1, label="ControlNet Weight")
|
|
|
|
| 591 |
run = gr.Button("🎨 Colorize", variant="primary")
|
| 592 |
run.click(
|
| 593 |
colorize,
|
| 594 |
+
[inp, base_model, anime_chk, prompt, negative_prompt, seed, steps, scale, cn_weight],
|
| 595 |
[out, sketch_out]
|
| 596 |
)
|
| 597 |
|
|
|
|
| 611 |
lines=3,
|
| 612 |
placeholder="e.g., a beautiful landscape with mountains and a lake at sunset, highly detailed, 4k"
|
| 613 |
)
|
| 614 |
+
t2i_negative_prompt = gr.Textbox(
|
| 615 |
+
label="Negative Prompt",
|
| 616 |
+
lines=2,
|
| 617 |
+
placeholder="e.g., blurry, ugly, deformed, low quality"
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
with gr.Row():
|
| 621 |
t2i_model = gr.Dropdown(
|
| 622 |
choices=ALL_MODELS, # ใช้ทั้ง SD1.5 และ SDXL
|
| 623 |
value="digiplay/ChikMix_V3",
|
| 624 |
label="Model"
|
| 625 |
)
|
|
|
|
|
|
|
| 626 |
t2i_seed = gr.Number(value=42, label="Seed")
|
| 627 |
t2i_steps = gr.Slider(10, 50, 30, step=1, label="Steps")
|
| 628 |
t2i_scale = gr.Slider(1, 20, 7.5, step=0.5, label="CFG Scale")
|
|
|
|
| 635 |
gen_btn = gr.Button("🖼️ Generate", variant="primary")
|
| 636 |
gen_btn.click(
|
| 637 |
t2i,
|
| 638 |
+
[t2i_prompt, t2i_negative_prompt, t2i_model, t2i_seed, t2i_steps, t2i_scale, w, h],
|
| 639 |
t2i_out
|
| 640 |
)
|
| 641 |
|