Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
import random
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import spaces
|
| 5 |
import torch
|
| 6 |
from diffusers import AutoencoderKL
|
| 7 |
from mixture_tiling_sdxl import StableDiffusionXLTilingPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
MAX_SEED = np.iinfo(np.int32).max
|
| 10 |
SCHEDULERS = [
|
|
@@ -36,7 +41,15 @@ pipe.enable_model_cpu_offload() # VRAMμ΄ μ νλ κ²½μ° μ¬μ©
|
|
| 36 |
pipe.enable_vae_tiling()
|
| 37 |
pipe.enable_vae_slicing()
|
| 38 |
|
| 39 |
-
#region functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def select_scheduler(scheduler_name):
|
| 41 |
scheduler_parts = scheduler_name.split("-")
|
| 42 |
scheduler_class_name = scheduler_parts[0]
|
|
@@ -63,6 +76,11 @@ def predict(left_prompt, center_prompt, right_prompt, negative_prompt, left_gs,
|
|
| 63 |
pipe.scheduler = select_scheduler(scheduler)
|
| 64 |
generator = torch.Generator("cuda").manual_seed(generation_seed)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
target_height = int(target_height)
|
| 67 |
target_width = int(target_width)
|
| 68 |
tile_height = int(tile_height)
|
|
@@ -221,7 +239,9 @@ button:hover, .btn:hover {
|
|
| 221 |
|
| 222 |
title = """
|
| 223 |
<h1 align="center" style="margin-bottom: 0.2em;"> π€ Panorama X3 Image </h1>
|
| 224 |
-
|
|
|
|
|
|
|
| 225 |
"""
|
| 226 |
|
| 227 |
with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
|
|
@@ -234,21 +254,21 @@ with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
|
|
| 234 |
with gr.Row():
|
| 235 |
with gr.Column(variant="panel"):
|
| 236 |
gr.Markdown("### Left Region")
|
| 237 |
-
left_prompt = gr.Textbox(lines=4, placeholder="
|
| 238 |
left_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Left CFG Scale")
|
| 239 |
with gr.Column(variant="panel"):
|
| 240 |
gr.Markdown("### Center Region")
|
| 241 |
-
center_prompt = gr.Textbox(lines=4, placeholder="
|
| 242 |
center_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Center CFG Scale")
|
| 243 |
with gr.Column(variant="panel"):
|
| 244 |
gr.Markdown("### Right Region")
|
| 245 |
-
right_prompt = gr.Textbox(lines=4, placeholder="
|
| 246 |
right_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Right CFG Scale")
|
| 247 |
with gr.Row():
|
| 248 |
negative_prompt = gr.Textbox(
|
| 249 |
lines=2,
|
| 250 |
label="Negative Prompt",
|
| 251 |
-
placeholder="
|
| 252 |
value="blurry, low resolution, artifacts, poor details"
|
| 253 |
)
|
| 254 |
with gr.Row():
|
|
@@ -296,7 +316,6 @@ with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
|
|
| 296 |
1024, 1920,
|
| 297 |
1280
|
| 298 |
],
|
| 299 |
-
|
| 300 |
[
|
| 301 |
"Vibrant abstract strokes with fluid, swirling patterns in cool tones",
|
| 302 |
"Interlocking geometric shapes bursting with color and texture",
|
|
|
|
| 1 |
import random
|
| 2 |
+
import re
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
import spaces
|
| 6 |
import torch
|
| 7 |
from diffusers import AutoencoderKL
|
| 8 |
from mixture_tiling_sdxl import StableDiffusionXLTilingPipeline
|
| 9 |
+
from transformers import pipeline
|
| 10 |
+
|
| 11 |
+
# νκΈ μ
λ ₯ μ μμ΄λ‘ λ²μνκΈ° μν νμ΄νλΌμΈ (CPUμμ λμ)
|
| 12 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 13 |
|
| 14 |
MAX_SEED = np.iinfo(np.int32).max
|
| 15 |
SCHEDULERS = [
|
|
|
|
| 41 |
pipe.enable_vae_tiling()
|
| 42 |
pipe.enable_vae_slicing()
|
| 43 |
|
| 44 |
+
#region helper functions
|
| 45 |
+
def translate_if_needed(text: str) -> str:
|
| 46 |
+
"""ν
μ€νΈμ νκΈμ΄ ν¬ν¨λ κ²½μ° μμ΄λ‘ λ²μνμ¬ λ°ν."""
|
| 47 |
+
if re.search(r'[\uac00-\ud7a3]', text):
|
| 48 |
+
# λ²μ κ²°κ³Όλ 리μ€νΈμ 첫λ²μ§Έ μμμ "translation_text" ν€μ μμ
|
| 49 |
+
translated = translator(text)[0]["translation_text"]
|
| 50 |
+
return translated
|
| 51 |
+
return text
|
| 52 |
+
|
| 53 |
def select_scheduler(scheduler_name):
|
| 54 |
scheduler_parts = scheduler_name.split("-")
|
| 55 |
scheduler_class_name = scheduler_parts[0]
|
|
|
|
| 76 |
pipe.scheduler = select_scheduler(scheduler)
|
| 77 |
generator = torch.Generator("cuda").manual_seed(generation_seed)
|
| 78 |
|
| 79 |
+
# νκΈ ν둬ννΈκ° μ
λ ₯λ κ²½μ° μμ΄λ‘ λ²μ
|
| 80 |
+
left_prompt = translate_if_needed(left_prompt)
|
| 81 |
+
center_prompt = translate_if_needed(center_prompt)
|
| 82 |
+
right_prompt = translate_if_needed(right_prompt)
|
| 83 |
+
|
| 84 |
target_height = int(target_height)
|
| 85 |
target_width = int(target_width)
|
| 86 |
tile_height = int(tile_height)
|
|
|
|
| 239 |
|
| 240 |
title = """
|
| 241 |
<h1 align="center" style="margin-bottom: 0.2em;"> π€ Panorama X3 Image </h1>
|
| 242 |
+
<p align="center" style="font-size:1.1em; color:#555;">
|
| 243 |
+
Left/Center/Right prompts (English/Korean allowed)
|
| 244 |
+
</p>
|
| 245 |
"""
|
| 246 |
|
| 247 |
with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
|
|
|
|
| 254 |
with gr.Row():
|
| 255 |
with gr.Column(variant="panel"):
|
| 256 |
gr.Markdown("### Left Region")
|
| 257 |
+
left_prompt = gr.Textbox(lines=4, placeholder="e.g., μΈμ°½ν μ²κ³Ό νμ΄μ΄ λΉμΆλ λ무...", label="Left Prompt (English/Korean allowed)")
|
| 258 |
left_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Left CFG Scale")
|
| 259 |
with gr.Column(variant="panel"):
|
| 260 |
gr.Markdown("### Center Region")
|
| 261 |
+
center_prompt = gr.Textbox(lines=4, placeholder="e.g., μμν νΈμμ λ°μ§μ΄λ μλ©΄...", label="Center Prompt (English/Korean allowed)")
|
| 262 |
center_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Center CFG Scale")
|
| 263 |
with gr.Column(variant="panel"):
|
| 264 |
gr.Markdown("### Right Region")
|
| 265 |
+
right_prompt = gr.Textbox(lines=4, placeholder="e.g., μ
μ₯ν μ°λ§₯κ³Ό νλμ κ°λ₯΄λ ꡬλ¦...", label="Right Prompt (English/Korean allowed)")
|
| 266 |
right_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Right CFG Scale")
|
| 267 |
with gr.Row():
|
| 268 |
negative_prompt = gr.Textbox(
|
| 269 |
lines=2,
|
| 270 |
label="Negative Prompt",
|
| 271 |
+
placeholder="e.g., blurry, low resolution, artifacts, poor details",
|
| 272 |
value="blurry, low resolution, artifacts, poor details"
|
| 273 |
)
|
| 274 |
with gr.Row():
|
|
|
|
| 316 |
1024, 1920,
|
| 317 |
1280
|
| 318 |
],
|
|
|
|
| 319 |
[
|
| 320 |
"Vibrant abstract strokes with fluid, swirling patterns in cool tones",
|
| 321 |
"Interlocking geometric shapes bursting with color and texture",
|