Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import yaml
|
| 3 |
import torch
|
| 4 |
import sys
|
|
@@ -53,20 +58,27 @@ def load_message(height, width, seed, prompt, args, stage_a_tiled):
|
|
| 53 |
def is_korean(text):
|
| 54 |
return any('\uac00' <= char <= '\ud7a3' for char in text)
|
| 55 |
|
| 56 |
-
def translate_if_korean(text):
|
| 57 |
if is_korean(text):
|
| 58 |
translated = translator(text, max_length=512)[0]['translation_text']
|
| 59 |
print(f"Translated from Korean: {text} -> {translated}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return translated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
return text
|
| 62 |
|
| 63 |
@spaces.GPU(duration=120)
|
| 64 |
def get_image(height, width, seed, prompt, cfg, timesteps, stage_a_tiled):
|
| 65 |
global args
|
| 66 |
|
| 67 |
-
# Translate the prompt if it's in Korean
|
| 68 |
-
prompt = translate_if_korean(prompt)
|
| 69 |
-
|
| 70 |
args = load_message(height, width, seed, prompt, args, stage_a_tiled)
|
| 71 |
torch.manual_seed(args.seed)
|
| 72 |
random.seed(args.seed)
|
|
@@ -119,93 +131,311 @@ def get_image(height, width, seed, prompt, cfg, timesteps, stage_a_tiled):
|
|
| 119 |
torch.cuda.empty_cache()
|
| 120 |
imgs = show_images(sampled)
|
| 121 |
|
| 122 |
-
return imgs[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
css = """
|
| 125 |
footer {
|
| 126 |
visibility: hidden;
|
| 127 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
"""
|
| 129 |
|
| 130 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 131 |
with gr.Column(elem_id="col-container"):
|
| 132 |
-
gr.Markdown("<h1
|
| 133 |
|
| 134 |
-
with gr.
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
)
|
| 142 |
-
polish_button = gr.Button("Submit", scale=0)
|
| 143 |
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
with gr.Accordion("Advanced Settings", open=False):
|
| 147 |
-
seed = gr.Number(
|
| 148 |
-
label="Random Seed",
|
| 149 |
-
value=123,
|
| 150 |
-
step=1,
|
| 151 |
-
minimum=0,
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
with gr.Row():
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
step=0.1,
|
| 177 |
-
value=4
|
| 178 |
-
)
|
| 179 |
-
|
| 180 |
-
timesteps = gr.Slider(
|
| 181 |
-
label="Timesteps",
|
| 182 |
-
minimum=10,
|
| 183 |
-
maximum=50,
|
| 184 |
-
step=1,
|
| 185 |
-
value=20
|
| 186 |
-
)
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
)
|
| 206 |
|
| 207 |
-
|
| 208 |
-
polish_button.click(clear_image, inputs=[], outputs=output_img)
|
| 209 |
|
| 210 |
def download_with_wget(url, save_path):
|
| 211 |
try:
|
|
|
|
| 1 |
import os
|
| 2 |
+
|
| 3 |
+
# Set this environment variable to disable torch.compiler features
|
| 4 |
+
os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1"
|
| 5 |
+
os.environ["TRANSFORMERS_COMPILER_DISABLED"] = "1"
|
| 6 |
+
|
| 7 |
import yaml
|
| 8 |
import torch
|
| 9 |
import sys
|
|
|
|
| 58 |
def is_korean(text):
|
| 59 |
return any('\uac00' <= char <= '\ud7a3' for char in text)
|
| 60 |
|
| 61 |
+
def translate_if_korean(text, translation_display=None):
|
| 62 |
if is_korean(text):
|
| 63 |
translated = translator(text, max_length=512)[0]['translation_text']
|
| 64 |
print(f"Translated from Korean: {text} -> {translated}")
|
| 65 |
+
|
| 66 |
+
# If translation_display is provided, update it to show the translation
|
| 67 |
+
if translation_display is not None:
|
| 68 |
+
translation_display.update(value=f"Original (Korean): {text}\nTranslation (English): {translated}", visible=True)
|
| 69 |
+
|
| 70 |
return translated
|
| 71 |
+
|
| 72 |
+
# If not Korean, hide the translation display if it exists
|
| 73 |
+
if translation_display is not None:
|
| 74 |
+
translation_display.update(visible=False)
|
| 75 |
+
|
| 76 |
return text
|
| 77 |
|
| 78 |
@spaces.GPU(duration=120)
|
| 79 |
def get_image(height, width, seed, prompt, cfg, timesteps, stage_a_tiled):
|
| 80 |
global args
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
args = load_message(height, width, seed, prompt, args, stage_a_tiled)
|
| 83 |
torch.manual_seed(args.seed)
|
| 84 |
random.seed(args.seed)
|
|
|
|
| 131 |
torch.cuda.empty_cache()
|
| 132 |
imgs = show_images(sampled)
|
| 133 |
|
| 134 |
+
return imgs[0]
|
| 135 |
+
|
| 136 |
+
def process_and_generate(height, width, seed, prompt, cfg, timesteps, stage_a_tiled, translation_display):
|
| 137 |
+
# First translate if needed and show the translation
|
| 138 |
+
translated_prompt = translate_if_korean(prompt, translation_display)
|
| 139 |
+
|
| 140 |
+
# Then generate the image
|
| 141 |
+
return get_image(height, width, seed, translated_prompt, cfg, timesteps, stage_a_tiled)
|
| 142 |
|
| 143 |
css = """
|
| 144 |
footer {
|
| 145 |
visibility: hidden;
|
| 146 |
}
|
| 147 |
+
|
| 148 |
+
/* Main container styling */
|
| 149 |
+
#col-container {
|
| 150 |
+
max-width: 1200px;
|
| 151 |
+
margin: 0 auto;
|
| 152 |
+
padding: 20px;
|
| 153 |
+
background-color: #f8f9fa;
|
| 154 |
+
border-radius: 15px;
|
| 155 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/* Header styling */
|
| 159 |
+
h1 {
|
| 160 |
+
text-align: center;
|
| 161 |
+
color: #ff6b00;
|
| 162 |
+
font-size: 2.5rem;
|
| 163 |
+
margin-bottom: 20px;
|
| 164 |
+
font-weight: 700;
|
| 165 |
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
/* Button styling */
|
| 169 |
+
button.primary {
|
| 170 |
+
background-color: #ff6b00 !important;
|
| 171 |
+
color: white !important;
|
| 172 |
+
border: none !important;
|
| 173 |
+
border-radius: 8px !important;
|
| 174 |
+
padding: 10px 20px !important;
|
| 175 |
+
font-weight: 600 !important;
|
| 176 |
+
transition: all 0.3s ease !important;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
button.primary:hover {
|
| 180 |
+
background-color: #e55f00 !important;
|
| 181 |
+
transform: translateY(-2px);
|
| 182 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
/* Input field styling */
|
| 186 |
+
input[type="text"] {
|
| 187 |
+
border-radius: 8px !important;
|
| 188 |
+
border: 2px solid #ddd !important;
|
| 189 |
+
padding: 12px !important;
|
| 190 |
+
font-size: 1rem !important;
|
| 191 |
+
transition: all 0.3s ease !important;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
input[type="text"]:focus {
|
| 195 |
+
border-color: #ff6b00 !important;
|
| 196 |
+
box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.2) !important;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
/* Output image container */
|
| 200 |
+
.output-image {
|
| 201 |
+
border-radius: 12px;
|
| 202 |
+
overflow: hidden;
|
| 203 |
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
|
| 204 |
+
margin: 20px 0;
|
| 205 |
+
transition: all 0.3s ease;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.output-image:hover {
|
| 209 |
+
transform: scale(1.02);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/* Accordion styling */
|
| 213 |
+
.accordion {
|
| 214 |
+
border-radius: 10px !important;
|
| 215 |
+
overflow: hidden !important;
|
| 216 |
+
margin: 15px 0 !important;
|
| 217 |
+
border: 1px solid #eaeaea !important;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
/* Example gallery */
|
| 221 |
+
.examples-gallery {
|
| 222 |
+
display: grid;
|
| 223 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 224 |
+
gap: 15px;
|
| 225 |
+
margin-top: 20px;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.example-item {
|
| 229 |
+
background-color: white;
|
| 230 |
+
border-radius: 10px;
|
| 231 |
+
padding: 10px;
|
| 232 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
| 233 |
+
transition: all 0.3s ease;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
.example-item:hover {
|
| 237 |
+
transform: translateY(-5px);
|
| 238 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
/* Language indicator */
|
| 242 |
+
.language-indicator {
|
| 243 |
+
background-color: #e6f7ff;
|
| 244 |
+
color: #0072b5;
|
| 245 |
+
border-radius: 20px;
|
| 246 |
+
padding: 2px 10px;
|
| 247 |
+
font-size: 0.8rem;
|
| 248 |
+
margin-left: 10px;
|
| 249 |
+
display: inline-block;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
/* Loading animation */
|
| 253 |
+
@keyframes pulse {
|
| 254 |
+
0% { opacity: 0.6; }
|
| 255 |
+
50% { opacity: 1; }
|
| 256 |
+
100% { opacity: 0.6; }
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.loading {
|
| 260 |
+
animation: pulse 1.5s infinite;
|
| 261 |
+
text-align: center;
|
| 262 |
+
padding: 20px;
|
| 263 |
+
color: #ff6b00;
|
| 264 |
+
font-weight: bold;
|
| 265 |
+
}
|
| 266 |
"""
|
| 267 |
|
| 268 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 269 |
with gr.Column(elem_id="col-container"):
|
| 270 |
+
gr.Markdown("<h1>UHD Image Generator (5120ร4096)</h1>")
|
| 271 |
|
| 272 |
+
with gr.Group():
|
| 273 |
+
with gr.Row():
|
| 274 |
+
with gr.Column(scale=5):
|
| 275 |
+
prompt = gr.Textbox(
|
| 276 |
+
label="Text Prompt",
|
| 277 |
+
max_lines=2,
|
| 278 |
+
placeholder="Enter your prompt in Korean or English (ํ๊ตญ์ด๋ ์์ด๋ก ํ๋กฌํํธ๋ฅผ ์
๋ ฅํ์ธ์)",
|
| 279 |
+
elem_id="prompt-input"
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
with gr.Column(scale=1):
|
| 283 |
+
generate_button = gr.Button("Generate Image", variant="primary", elem_id="generate-btn")
|
| 284 |
+
clear_button = gr.Button("Clear", elem_id="clear-btn")
|
| 285 |
+
|
| 286 |
+
# Language detection indicator
|
| 287 |
+
with gr.Row(visible=False) as language_indicator:
|
| 288 |
+
gr.Markdown('<div class="language-indicator">Korean detected - will translate to English</div>')
|
| 289 |
+
|
| 290 |
+
# Translation display component
|
| 291 |
+
with gr.Row(visible=False) as translation_display:
|
| 292 |
+
translation_text = gr.Textbox(
|
| 293 |
+
label="Translation Information",
|
| 294 |
+
interactive=False
|
| 295 |
)
|
|
|
|
| 296 |
|
| 297 |
+
# Loading indicator
|
| 298 |
+
with gr.Row(visible=False) as loading_indicator:
|
| 299 |
+
gr.Markdown('<div class="loading">Generating your ultra high resolution image... This may take a minute...</div>')
|
| 300 |
+
|
| 301 |
+
# Output image with nicer styling
|
| 302 |
+
output_img = gr.Image(label="Generated Image", elem_classes="output-image")
|
| 303 |
|
| 304 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
with gr.Row():
|
| 306 |
+
with gr.Column():
|
| 307 |
+
seed = gr.Number(
|
| 308 |
+
label="Random Seed",
|
| 309 |
+
value=123,
|
| 310 |
+
step=1,
|
| 311 |
+
minimum=0,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
cfg = gr.Slider(
|
| 315 |
+
label="CFG Scale (Creativity vs. Prompt Adherence)",
|
| 316 |
+
minimum=3,
|
| 317 |
+
maximum=10,
|
| 318 |
+
step=0.1,
|
| 319 |
+
value=4
|
| 320 |
+
)
|
| 321 |
|
| 322 |
+
with gr.Column():
|
| 323 |
+
with gr.Row():
|
| 324 |
+
width = gr.Slider(
|
| 325 |
+
label="Width",
|
| 326 |
+
minimum=1536,
|
| 327 |
+
maximum=5120,
|
| 328 |
+
step=32,
|
| 329 |
+
value=4096
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
height = gr.Slider(
|
| 333 |
+
label="Height",
|
| 334 |
+
minimum=1536,
|
| 335 |
+
maximum=4096,
|
| 336 |
+
step=32,
|
| 337 |
+
value=2304
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
timesteps = gr.Slider(
|
| 341 |
+
label="Timesteps (Quality vs. Speed)",
|
| 342 |
+
minimum=10,
|
| 343 |
+
maximum=50,
|
| 344 |
+
step=1,
|
| 345 |
+
value=20
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
stage_a_tiled = gr.Checkbox(
|
| 349 |
+
label="Use Tiled Decoding (Lower Memory Usage)",
|
| 350 |
+
value=False
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
# Aspect ratio presets
|
| 354 |
+
with gr.Row():
|
| 355 |
+
gr.Markdown("### Quick Aspect Ratio Presets")
|
| 356 |
|
| 357 |
+
with gr.Row():
|
| 358 |
+
preset_landscape = gr.Button("Landscape (16:9)", size="sm")
|
| 359 |
+
preset_portrait = gr.Button("Portrait (9:16)", size="sm")
|
| 360 |
+
preset_square = gr.Button("Square (1:1)", size="sm")
|
| 361 |
+
preset_ultrawide = gr.Button("Ultrawide (21:9)", size="sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
+
# Examples with better organization
|
| 364 |
+
gr.Markdown("### Example Prompts")
|
| 365 |
+
with gr.Row():
|
| 366 |
+
example_tabs = gr.Tabs([
|
| 367 |
+
gr.TabItem("Nature", gr.Examples(
|
| 368 |
+
examples=[
|
| 369 |
+
"A detailed view of a blooming magnolia tree, with large, white flowers and dark green leaves, set against a clear blue sky.",
|
| 370 |
+
"๋ ๋ฎ์ธ ์ฐ๋งฅ์ ์ฅ์ํ ์ ๊ฒฝ, ํธ๋ฅธ ํ๋์ ๋ฐฐ๊ฒฝ์ผ๋ก ํ ๊ณ ์ํ ํธ์๊ฐ ์๋ ๋ชจ์ต",
|
| 371 |
+
],
|
| 372 |
+
inputs=[prompt],
|
| 373 |
+
outputs=[output_img],
|
| 374 |
+
)),
|
| 375 |
+
gr.TabItem("Animals", gr.Examples(
|
| 376 |
+
examples=[
|
| 377 |
+
"์ค์จํฐ๋ฅผ ์
์ ์
์ด",
|
| 378 |
+
"๊ณจ๋ ๋ฆฌํธ๋ฆฌ๋ฒ ๊ฐ์์ง๊ฐ ํธ๋ฅธ ์๋๋ฐญ์์ ๋นจ๊ฐ ๊ณต์ ์ซ๋ ๊ท์ฌ์ด ๋ชจ์ต",
|
| 379 |
+
],
|
| 380 |
+
inputs=[prompt],
|
| 381 |
+
outputs=[output_img],
|
| 382 |
+
)),
|
| 383 |
+
gr.TabItem("Anime", gr.Examples(
|
| 384 |
+
examples=[
|
| 385 |
+
"A vibrant anime scene of a young girl with long, flowing pink hair, big sparkling blue eyes, and a school uniform, standing under a cherry blossom tree with petals falling around her.",
|
| 386 |
+
],
|
| 387 |
+
inputs=[prompt],
|
| 388 |
+
outputs=[output_img],
|
| 389 |
+
)),
|
| 390 |
+
gr.TabItem("Architecture", gr.Examples(
|
| 391 |
+
examples=[
|
| 392 |
+
"A cozy, rustic log cabin nestled in a snow-covered forest, with smoke rising from the stone chimney, warm lights glowing from the windows, and a path of footprints leading to the front door.",
|
| 393 |
+
],
|
| 394 |
+
inputs=[prompt],
|
| 395 |
+
outputs=[output_img],
|
| 396 |
+
)),
|
| 397 |
+
])
|
| 398 |
+
|
| 399 |
+
# Function to set aspect ratio presets
|
| 400 |
+
def set_landscape():
|
| 401 |
+
return 5120, 2880
|
| 402 |
+
|
| 403 |
+
def set_portrait():
|
| 404 |
+
return 2880, 4096
|
| 405 |
+
|
| 406 |
+
def set_square():
|
| 407 |
+
return 3584, 3584
|
| 408 |
+
|
| 409 |
+
def set_ultrawide():
|
| 410 |
+
return 5120, 2160
|
| 411 |
+
|
| 412 |
+
# Connect buttons to functions
|
| 413 |
+
preset_landscape.click(set_landscape, outputs=[width, height])
|
| 414 |
+
preset_portrait.click(set_portrait, outputs=[width, height])
|
| 415 |
+
preset_square.click(set_square, outputs=[width, height])
|
| 416 |
+
preset_ultrawide.click(set_ultrawide, outputs=[width, height])
|
| 417 |
|
| 418 |
+
# Function to show Korean detection indicator
|
| 419 |
+
def check_korean(text):
|
| 420 |
+
if any('\uac00' <= char <= '\ud7a3' for char in text):
|
| 421 |
+
return gr.update(visible=True)
|
| 422 |
+
return gr.update(visible=False)
|
| 423 |
+
|
| 424 |
+
# Connect events
|
| 425 |
+
prompt.change(check_korean, inputs=[prompt], outputs=[language_indicator])
|
| 426 |
+
generate_button.click(
|
| 427 |
+
lambda: gr.update(visible=True),
|
| 428 |
+
outputs=[loading_indicator]
|
| 429 |
+
).then(
|
| 430 |
+
process_and_generate,
|
| 431 |
+
inputs=[height, width, seed, prompt, cfg, timesteps, stage_a_tiled, translation_display],
|
| 432 |
+
outputs=[output_img]
|
| 433 |
+
).then(
|
| 434 |
+
lambda: gr.update(visible=False),
|
| 435 |
+
outputs=[loading_indicator]
|
| 436 |
)
|
| 437 |
|
| 438 |
+
clear_button.click(clear_image, inputs=[], outputs=[output_img])
|
|
|
|
| 439 |
|
| 440 |
def download_with_wget(url, save_path):
|
| 441 |
try:
|