Spaces:
Running on Zero
Running on Zero
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,610 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gc
|
| 3 |
-
import gradio as gr
|
| 4 |
-
import numpy as np
|
| 5 |
-
import spaces
|
| 6 |
-
import torch
|
| 7 |
-
import random
|
| 8 |
-
from PIL import Image
|
| 9 |
-
from typing import Iterable
|
| 10 |
-
from gradio.themes import Base
|
| 11 |
-
from gradio.themes.utils import colors, fonts, sizes
|
| 12 |
-
|
| 13 |
-
# ββ Windows 98 Color Palettes βββββββββββββββββββββββββββββββββββββββββββ
|
| 14 |
-
|
| 15 |
-
colors.win98_blue = colors.Color(
|
| 16 |
-
name="win98_blue",
|
| 17 |
-
c50="#E6E6F5",
|
| 18 |
-
c100="#CCCCEB",
|
| 19 |
-
c200="#9999D6",
|
| 20 |
-
c300="#6666C2",
|
| 21 |
-
c400="#3333AD",
|
| 22 |
-
c500="#000080",
|
| 23 |
-
c600="#000073",
|
| 24 |
-
c700="#000066",
|
| 25 |
-
c800="#000059",
|
| 26 |
-
c900="#00004D",
|
| 27 |
-
c950="#000040",
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
colors.win98_gray = colors.Color(
|
| 31 |
-
name="win98_gray",
|
| 32 |
-
c50="#F5F5F5",
|
| 33 |
-
c100="#EBEBEB",
|
| 34 |
-
c200="#D6D6D6",
|
| 35 |
-
c300="#C0C0C0",
|
| 36 |
-
c400="#A8A8A8",
|
| 37 |
-
c500="#808080",
|
| 38 |
-
c600="#696969",
|
| 39 |
-
c700="#555555",
|
| 40 |
-
c800="#404040",
|
| 41 |
-
c900="#2D2D2D",
|
| 42 |
-
c950="#1A1A1A",
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# ββ Windows 98 Theme ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 47 |
-
|
| 48 |
-
class Windows98Theme(Base):
|
| 49 |
-
def __init__(
|
| 50 |
-
self,
|
| 51 |
-
*,
|
| 52 |
-
primary_hue: colors.Color | str = colors.win98_gray,
|
| 53 |
-
secondary_hue: colors.Color | str = colors.win98_blue,
|
| 54 |
-
neutral_hue: colors.Color | str = colors.win98_gray,
|
| 55 |
-
text_size: sizes.Size | str = sizes.text_md,
|
| 56 |
-
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 57 |
-
fonts.Font("Tahoma"),
|
| 58 |
-
fonts.Font("MS Sans Serif"),
|
| 59 |
-
fonts.Font("Arial"),
|
| 60 |
-
fonts.Font("sans-serif"),
|
| 61 |
-
),
|
| 62 |
-
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 63 |
-
fonts.Font("Courier New"),
|
| 64 |
-
fonts.Font("Fixedsys"),
|
| 65 |
-
fonts.Font("monospace"),
|
| 66 |
-
),
|
| 67 |
-
):
|
| 68 |
-
super().__init__(
|
| 69 |
-
primary_hue=primary_hue,
|
| 70 |
-
secondary_hue=secondary_hue,
|
| 71 |
-
neutral_hue=neutral_hue,
|
| 72 |
-
text_size=text_size,
|
| 73 |
-
font=font,
|
| 74 |
-
font_mono=font_mono,
|
| 75 |
-
)
|
| 76 |
-
super().set(
|
| 77 |
-
# ββ Body ββ
|
| 78 |
-
body_background_fill="#c0c0c0",
|
| 79 |
-
body_background_fill_dark="#c0c0c0",
|
| 80 |
-
background_fill_primary="#c0c0c0",
|
| 81 |
-
background_fill_primary_dark="#c0c0c0",
|
| 82 |
-
background_fill_secondary="#d4d0c8",
|
| 83 |
-
background_fill_secondary_dark="#d4d0c8",
|
| 84 |
-
|
| 85 |
-
# ββ Blocks ββ
|
| 86 |
-
block_background_fill="#c0c0c0",
|
| 87 |
-
block_border_width="2px",
|
| 88 |
-
block_shadow="none",
|
| 89 |
-
block_title_text_weight="bold",
|
| 90 |
-
block_label_background_fill="#c0c0c0",
|
| 91 |
-
|
| 92 |
-
# ββ Primary Button (Navy Blue) ββ
|
| 93 |
-
button_primary_background_fill="#000080",
|
| 94 |
-
button_primary_background_fill_hover="#0000a0",
|
| 95 |
-
button_primary_background_fill_dark="#000080",
|
| 96 |
-
button_primary_background_fill_hover_dark="#0000a0",
|
| 97 |
-
button_primary_text_color="white",
|
| 98 |
-
button_primary_text_color_hover="white",
|
| 99 |
-
button_primary_shadow="none",
|
| 100 |
-
|
| 101 |
-
# ββ Secondary Button (Gray) ββ
|
| 102 |
-
button_secondary_background_fill="#c0c0c0",
|
| 103 |
-
button_secondary_background_fill_hover="#d4d0c8",
|
| 104 |
-
button_secondary_background_fill_dark="#c0c0c0",
|
| 105 |
-
button_secondary_background_fill_hover_dark="#d4d0c8",
|
| 106 |
-
button_secondary_text_color="#000000",
|
| 107 |
-
button_secondary_text_color_hover="#000000",
|
| 108 |
-
|
| 109 |
-
button_large_padding="6px 16px",
|
| 110 |
-
|
| 111 |
-
# ββ Slider ββ
|
| 112 |
-
slider_color="#000080",
|
| 113 |
-
slider_color_dark="#000080",
|
| 114 |
-
|
| 115 |
-
# ββ Accent ββ
|
| 116 |
-
color_accent_soft="#d4d0c8",
|
| 117 |
-
|
| 118 |
-
# ββ Input ββ
|
| 119 |
-
input_background_fill="#ffffff",
|
| 120 |
-
input_background_fill_dark="#ffffff",
|
| 121 |
-
|
| 122 |
-
# ββ Text ββ
|
| 123 |
-
body_text_color="#000000",
|
| 124 |
-
body_text_color_dark="#000000",
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
windows_98_theme = Windows98Theme()
|
| 129 |
-
|
| 130 |
-
# ββ Device & Model Setup ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 131 |
-
|
| 132 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 133 |
-
|
| 134 |
-
print("CUDA_VISIBLE_DEVICES=", os.environ.get("CUDA_VISIBLE_DEVICES"))
|
| 135 |
-
print("torch.__version__ =", torch.__version__)
|
| 136 |
-
print("Using device:", device)
|
| 137 |
-
|
| 138 |
-
from diffusers import FlowMatchEulerDiscreteScheduler
|
| 139 |
-
from qwenimage.pipeline_qwenimage_edit_plus import QwenImageEditPlusPipeline
|
| 140 |
-
from qwenimage.transformer_qwenimage import QwenImageTransformer2DModel
|
| 141 |
-
from qwenimage.qwen_fa3_processor import QwenDoubleStreamAttnProcessorFA3
|
| 142 |
-
|
| 143 |
-
dtype = torch.bfloat16
|
| 144 |
-
|
| 145 |
-
pipe = QwenImageEditPlusPipeline.from_pretrained(
|
| 146 |
-
"FireRedTeam/FireRed-Image-Edit-1.0",
|
| 147 |
-
transformer=QwenImageTransformer2DModel.from_pretrained(
|
| 148 |
-
"prithivMLmods/Qwen-Image-Edit-Rapid-AIO-V19",
|
| 149 |
-
torch_dtype=dtype,
|
| 150 |
-
device_map='cuda'
|
| 151 |
-
),
|
| 152 |
-
torch_dtype=dtype
|
| 153 |
-
).to(device)
|
| 154 |
-
|
| 155 |
-
try:
|
| 156 |
-
pipe.transformer.set_attn_processor(QwenDoubleStreamAttnProcessorFA3())
|
| 157 |
-
print("Flash Attention 3 Processor set successfully.")
|
| 158 |
-
except Exception as e:
|
| 159 |
-
print(f"Warning: Could not set FA3 processor: {e}")
|
| 160 |
-
|
| 161 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
# ββ Helper Functions ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 165 |
-
|
| 166 |
-
def update_dimensions_on_upload(image):
|
| 167 |
-
if image is None:
|
| 168 |
-
return 1024, 1024
|
| 169 |
-
|
| 170 |
-
original_width, original_height = image.size
|
| 171 |
-
|
| 172 |
-
if original_width > original_height:
|
| 173 |
-
new_width = 1024
|
| 174 |
-
aspect_ratio = original_height / original_width
|
| 175 |
-
new_height = int(new_width * aspect_ratio)
|
| 176 |
-
else:
|
| 177 |
-
new_height = 1024
|
| 178 |
-
aspect_ratio = original_width / original_height
|
| 179 |
-
new_width = int(new_height * aspect_ratio)
|
| 180 |
-
|
| 181 |
-
new_width = (new_width // 8) * 8
|
| 182 |
-
new_height = (new_height // 8) * 8
|
| 183 |
-
|
| 184 |
-
return new_width, new_height
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
@spaces.GPU
|
| 188 |
-
def infer(
|
| 189 |
-
images,
|
| 190 |
-
prompt,
|
| 191 |
-
seed,
|
| 192 |
-
randomize_seed,
|
| 193 |
-
guidance_scale,
|
| 194 |
-
steps,
|
| 195 |
-
progress=gr.Progress(track_tqdm=True)
|
| 196 |
-
):
|
| 197 |
-
gc.collect()
|
| 198 |
-
torch.cuda.empty_cache()
|
| 199 |
-
|
| 200 |
-
if not images:
|
| 201 |
-
raise gr.Error("Please upload at least one image to edit.")
|
| 202 |
-
|
| 203 |
-
pil_images = []
|
| 204 |
-
if images is not None:
|
| 205 |
-
for item in images:
|
| 206 |
-
try:
|
| 207 |
-
if isinstance(item, tuple) or isinstance(item, list):
|
| 208 |
-
path_or_img = item[0]
|
| 209 |
-
else:
|
| 210 |
-
path_or_img = item
|
| 211 |
-
|
| 212 |
-
if isinstance(path_or_img, str):
|
| 213 |
-
pil_images.append(Image.open(path_or_img).convert("RGB"))
|
| 214 |
-
elif isinstance(path_or_img, Image.Image):
|
| 215 |
-
pil_images.append(path_or_img.convert("RGB"))
|
| 216 |
-
else:
|
| 217 |
-
pil_images.append(Image.open(path_or_img.name).convert("RGB"))
|
| 218 |
-
except Exception as e:
|
| 219 |
-
print(f"Skipping invalid image item: {e}")
|
| 220 |
-
continue
|
| 221 |
-
|
| 222 |
-
if not pil_images:
|
| 223 |
-
raise gr.Error("Could not process uploaded images.")
|
| 224 |
-
|
| 225 |
-
if randomize_seed:
|
| 226 |
-
seed = random.randint(0, MAX_SEED)
|
| 227 |
-
|
| 228 |
-
generator = torch.Generator(device=device).manual_seed(seed)
|
| 229 |
-
negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
|
| 230 |
-
|
| 231 |
-
width, height = update_dimensions_on_upload(pil_images[0])
|
| 232 |
-
|
| 233 |
-
try:
|
| 234 |
-
result_image = pipe(
|
| 235 |
-
image=pil_images,
|
| 236 |
-
prompt=prompt,
|
| 237 |
-
negative_prompt=negative_prompt,
|
| 238 |
-
height=height,
|
| 239 |
-
width=width,
|
| 240 |
-
num_inference_steps=steps,
|
| 241 |
-
generator=generator,
|
| 242 |
-
true_cfg_scale=guidance_scale,
|
| 243 |
-
).images[0]
|
| 244 |
-
|
| 245 |
-
return result_image, seed
|
| 246 |
-
|
| 247 |
-
except Exception as e:
|
| 248 |
-
raise e
|
| 249 |
-
finally:
|
| 250 |
-
gc.collect()
|
| 251 |
-
torch.cuda.empty_cache()
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
@spaces.GPU
|
| 255 |
-
def infer_example(images, prompt):
|
| 256 |
-
if not images:
|
| 257 |
-
return None, 0
|
| 258 |
-
|
| 259 |
-
if isinstance(images, str):
|
| 260 |
-
images_list = [images]
|
| 261 |
-
else:
|
| 262 |
-
images_list = images
|
| 263 |
-
|
| 264 |
-
result, seed = infer(
|
| 265 |
-
images=images_list,
|
| 266 |
-
prompt=prompt,
|
| 267 |
-
seed=0,
|
| 268 |
-
randomize_seed=True,
|
| 269 |
-
guidance_scale=1.0,
|
| 270 |
-
steps=4
|
| 271 |
-
)
|
| 272 |
-
return result, seed
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
# ββ CSS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 276 |
-
|
| 277 |
-
css = """
|
| 278 |
-
/* βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 279 |
-
WINDOWS 98 RETRO THEME
|
| 280 |
-
βββββββββββββββββββββββββββββββββββββββββββββββ */
|
| 281 |
-
|
| 282 |
-
/* ββ Global Reset ββ */
|
| 283 |
-
*, *::before, *::after {
|
| 284 |
-
border-radius: 0px !important;
|
| 285 |
-
}
|
| 286 |
-
|
| 287 |
-
.gradio-container {
|
| 288 |
-
background: #c0c0c0 !important;
|
| 289 |
-
}
|
| 290 |
-
|
| 291 |
-
/* ββ Window Frame ββ */
|
| 292 |
-
#col-container {
|
| 293 |
-
margin: 0 auto;
|
| 294 |
-
max-width: 1000px;
|
| 295 |
-
background: #c0c0c0;
|
| 296 |
-
border-top: 2px solid #ffffff;
|
| 297 |
-
border-left: 2px solid #ffffff;
|
| 298 |
-
border-right: 2px solid #404040;
|
| 299 |
-
border-bottom: 2px solid #404040;
|
| 300 |
-
box-shadow: 1px 1px 0 0 #000000;
|
| 301 |
-
padding: 2px;
|
| 302 |
-
}
|
| 303 |
-
|
| 304 |
-
/* ββ Title Bar ββ */
|
| 305 |
-
#main-title {
|
| 306 |
-
background: linear-gradient(90deg, #000080, #1084d0) !important;
|
| 307 |
-
padding: 3px 8px !important;
|
| 308 |
-
margin: 0 !important;
|
| 309 |
-
border: none !important;
|
| 310 |
-
box-shadow: none !important;
|
| 311 |
-
position: relative;
|
| 312 |
-
}
|
| 313 |
-
|
| 314 |
-
#main-title h1 {
|
| 315 |
-
font-size: 13px !important;
|
| 316 |
-
color: white !important;
|
| 317 |
-
font-weight: bold !important;
|
| 318 |
-
margin: 0 !important;
|
| 319 |
-
padding: 1px 0 !important;
|
| 320 |
-
text-shadow: 1px 1px 0px rgba(0,0,0,0.5);
|
| 321 |
-
font-family: "Tahoma", "MS Sans Serif", sans-serif !important;
|
| 322 |
-
}
|
| 323 |
-
|
| 324 |
-
/* Faux Window Controls */
|
| 325 |
-
#main-title::after {
|
| 326 |
-
content: "β β‘ β";
|
| 327 |
-
position: absolute;
|
| 328 |
-
right: 4px;
|
| 329 |
-
top: 3px;
|
| 330 |
-
color: #000000;
|
| 331 |
-
font-size: 9px;
|
| 332 |
-
letter-spacing: 2px;
|
| 333 |
-
background: #c0c0c0;
|
| 334 |
-
border-top: 2px solid #ffffff;
|
| 335 |
-
border-left: 2px solid #ffffff;
|
| 336 |
-
border-right: 2px solid #808080;
|
| 337 |
-
border-bottom: 2px solid #808080;
|
| 338 |
-
padding: 0 5px;
|
| 339 |
-
font-family: "Tahoma", sans-serif;
|
| 340 |
-
line-height: 15px;
|
| 341 |
-
}
|
| 342 |
-
|
| 343 |
-
/* ββ Description / Menu Bar ββ */
|
| 344 |
-
#desc-text {
|
| 345 |
-
background: #c0c0c0 !important;
|
| 346 |
-
border: none !important;
|
| 347 |
-
border-bottom: 1px solid #808080 !important;
|
| 348 |
-
padding: 4px 6px !important;
|
| 349 |
-
margin: 0 0 4px 0 !important;
|
| 350 |
-
box-shadow: none !important;
|
| 351 |
-
}
|
| 352 |
-
|
| 353 |
-
#desc-text p {
|
| 354 |
-
font-size: 11px !important;
|
| 355 |
-
margin: 2px 0 !important;
|
| 356 |
-
color: #000000 !important;
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
#desc-text a {
|
| 360 |
-
color: #000080 !important;
|
| 361 |
-
text-decoration: underline !important;
|
| 362 |
-
}
|
| 363 |
-
|
| 364 |
-
/* ββ Raised Panels / Blocks ββ */
|
| 365 |
-
.block, .form {
|
| 366 |
-
border-top: 2px solid #ffffff !important;
|
| 367 |
-
border-left: 2px solid #ffffff !important;
|
| 368 |
-
border-right: 2px solid #808080 !important;
|
| 369 |
-
border-bottom: 2px solid #808080 !important;
|
| 370 |
-
background: #c0c0c0 !important;
|
| 371 |
-
box-shadow: none !important;
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
/* ββ Sunken Text Inputs ββ */
|
| 375 |
-
textarea,
|
| 376 |
-
input[type="text"],
|
| 377 |
-
input[type="number"],
|
| 378 |
-
input[type="search"] {
|
| 379 |
-
border-top: 2px solid #808080 !important;
|
| 380 |
-
border-left: 2px solid #808080 !important;
|
| 381 |
-
border-right: 2px solid #ffffff !important;
|
| 382 |
-
border-bottom: 2px solid #ffffff !important;
|
| 383 |
-
background: #ffffff !important;
|
| 384 |
-
box-shadow: none !important;
|
| 385 |
-
font-family: "Tahoma", "MS Sans Serif", sans-serif !important;
|
| 386 |
-
outline: none !important;
|
| 387 |
-
}
|
| 388 |
-
|
| 389 |
-
textarea:focus,
|
| 390 |
-
input[type="text"]:focus,
|
| 391 |
-
input[type="number"]:focus {
|
| 392 |
-
border-top: 2px solid #808080 !important;
|
| 393 |
-
border-left: 2px solid #808080 !important;
|
| 394 |
-
border-right: 2px solid #ffffff !important;
|
| 395 |
-
border-bottom: 2px solid #ffffff !important;
|
| 396 |
-
box-shadow: none !important;
|
| 397 |
-
outline: none !important;
|
| 398 |
-
}
|
| 399 |
-
|
| 400 |
-
/* ββ Sunken Image / Gallery Frames ββ */
|
| 401 |
-
.image-frame {
|
| 402 |
-
border-top: 2px solid #808080 !important;
|
| 403 |
-
border-left: 2px solid #808080 !important;
|
| 404 |
-
border-right: 2px solid #ffffff !important;
|
| 405 |
-
border-bottom: 2px solid #ffffff !important;
|
| 406 |
-
background: #ffffff !important;
|
| 407 |
-
}
|
| 408 |
-
|
| 409 |
-
/* ββ Upload Area ββ */
|
| 410 |
-
.upload-area {
|
| 411 |
-
border-top: 2px solid #808080 !important;
|
| 412 |
-
border-left: 2px solid #808080 !important;
|
| 413 |
-
border-right: 2px solid #ffffff !important;
|
| 414 |
-
border-bottom: 2px solid #ffffff !important;
|
| 415 |
-
background: #ffffff !important;
|
| 416 |
-
}
|
| 417 |
-
|
| 418 |
-
/* ββ Buttons (Raised) ββ */
|
| 419 |
-
button {
|
| 420 |
-
border-top: 2px solid #ffffff !important;
|
| 421 |
-
border-left: 2px solid #ffffff !important;
|
| 422 |
-
border-right: 2px solid #808080 !important;
|
| 423 |
-
border-bottom: 2px solid #808080 !important;
|
| 424 |
-
box-shadow: none !important;
|
| 425 |
-
font-family: "Tahoma", "MS Sans Serif", sans-serif !important;
|
| 426 |
-
}
|
| 427 |
-
|
| 428 |
-
button:active {
|
| 429 |
-
border-top: 2px solid #808080 !important;
|
| 430 |
-
border-left: 2px solid #808080 !important;
|
| 431 |
-
border-right: 2px solid #ffffff !important;
|
| 432 |
-
border-bottom: 2px solid #ffffff !important;
|
| 433 |
-
}
|
| 434 |
-
|
| 435 |
-
/* ββ Checkbox (Sunken) ββ */
|
| 436 |
-
input[type="checkbox"] {
|
| 437 |
-
border-top: 2px solid #808080 !important;
|
| 438 |
-
border-left: 2px solid #808080 !important;
|
| 439 |
-
border-right: 2px solid #ffffff !important;
|
| 440 |
-
border-bottom: 2px solid #ffffff !important;
|
| 441 |
-
background: #ffffff !important;
|
| 442 |
-
}
|
| 443 |
-
|
| 444 |
-
/* ββ Slider ββ */
|
| 445 |
-
input[type="range"] {
|
| 446 |
-
border: none !important;
|
| 447 |
-
background: transparent !important;
|
| 448 |
-
}
|
| 449 |
-
|
| 450 |
-
/* ββ Select / Dropdown (Sunken) ββ */
|
| 451 |
-
select {
|
| 452 |
-
border-top: 2px solid #808080 !important;
|
| 453 |
-
border-left: 2px solid #808080 !important;
|
| 454 |
-
border-right: 2px solid #ffffff !important;
|
| 455 |
-
border-bottom: 2px solid #ffffff !important;
|
| 456 |
-
background: #ffffff !important;
|
| 457 |
-
}
|
| 458 |
-
|
| 459 |
-
/* ββ Accordion (Group Box) ββ */
|
| 460 |
-
.accordion {
|
| 461 |
-
border: 2px groove #c0c0c0 !important;
|
| 462 |
-
box-shadow: none !important;
|
| 463 |
-
}
|
| 464 |
-
|
| 465 |
-
/* ββ Labels ββ */
|
| 466 |
-
.block-label, .label-wrap {
|
| 467 |
-
background: #c0c0c0 !important;
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
/* ββ Tab Nav (if present) ββ */
|
| 471 |
-
.tab-nav button {
|
| 472 |
-
border-top: 2px solid #ffffff !important;
|
| 473 |
-
border-left: 2px solid #ffffff !important;
|
| 474 |
-
border-right: 2px solid #808080 !important;
|
| 475 |
-
border-bottom: none !important;
|
| 476 |
-
background: #c0c0c0 !important;
|
| 477 |
-
margin-right: 1px !important;
|
| 478 |
-
}
|
| 479 |
-
|
| 480 |
-
.tab-nav button.selected {
|
| 481 |
-
border-bottom: 2px solid #c0c0c0 !important;
|
| 482 |
-
position: relative;
|
| 483 |
-
z-index: 2;
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
/* ββ Scrollbars (Classic Win98) ββ */
|
| 487 |
-
::-webkit-scrollbar {
|
| 488 |
-
width: 16px;
|
| 489 |
-
height: 16px;
|
| 490 |
-
}
|
| 491 |
-
|
| 492 |
-
::-webkit-scrollbar-track {
|
| 493 |
-
background: #c0c0c0;
|
| 494 |
-
}
|
| 495 |
-
|
| 496 |
-
::-webkit-scrollbar-thumb {
|
| 497 |
-
background: #c0c0c0;
|
| 498 |
-
border-top: 2px solid #ffffff;
|
| 499 |
-
border-left: 2px solid #ffffff;
|
| 500 |
-
border-right: 2px solid #808080;
|
| 501 |
-
border-bottom: 2px solid #808080;
|
| 502 |
-
}
|
| 503 |
-
|
| 504 |
-
::-webkit-scrollbar-button {
|
| 505 |
-
display: block;
|
| 506 |
-
height: 16px;
|
| 507 |
-
width: 16px;
|
| 508 |
-
background: #c0c0c0;
|
| 509 |
-
border-top: 2px solid #ffffff;
|
| 510 |
-
border-left: 2px solid #ffffff;
|
| 511 |
-
border-right: 2px solid #808080;
|
| 512 |
-
border-bottom: 2px solid #808080;
|
| 513 |
-
}
|
| 514 |
-
|
| 515 |
-
::-webkit-scrollbar-corner {
|
| 516 |
-
background: #c0c0c0;
|
| 517 |
-
}
|
| 518 |
-
|
| 519 |
-
/* ββ Progress Bar ββ */
|
| 520 |
-
.progress-bar {
|
| 521 |
-
background: #000080 !important;
|
| 522 |
-
}
|
| 523 |
-
|
| 524 |
-
/* ββ Toast / Error Dialogs ββ */
|
| 525 |
-
.toast-wrap, .toast-body {
|
| 526 |
-
border-top: 2px solid #ffffff !important;
|
| 527 |
-
border-left: 2px solid #ffffff !important;
|
| 528 |
-
border-right: 2px solid #808080 !important;
|
| 529 |
-
border-bottom: 2px solid #808080 !important;
|
| 530 |
-
background: #c0c0c0 !important;
|
| 531 |
-
color: #000000 !important;
|
| 532 |
-
}
|
| 533 |
-
|
| 534 |
-
/* ββ Footer ββ */
|
| 535 |
-
footer {
|
| 536 |
-
border-top: 1px solid #808080 !important;
|
| 537 |
-
background: #c0c0c0 !important;
|
| 538 |
-
}
|
| 539 |
-
"""
|
| 540 |
-
|
| 541 |
-
# ββ Gradio Interface βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 542 |
-
|
| 543 |
-
with gr.Blocks() as demo:
|
| 544 |
-
with gr.Column(elem_id="col-container"):
|
| 545 |
-
gr.Markdown("# **FireRed-Image-Edit-1.0-Fast**", elem_id="main-title")
|
| 546 |
-
gr.Markdown(
|
| 547 |
-
"Perform image edits using "
|
| 548 |
-
"[FireRed-Image-Edit-1.0](https://huggingface.co/FireRedTeam/FireRed-Image-Edit-1.0) "
|
| 549 |
-
"with 4-step fast inference.",
|
| 550 |
-
elem_id="desc-text"
|
| 551 |
-
)
|
| 552 |
-
|
| 553 |
-
with gr.Row(equal_height=True):
|
| 554 |
-
with gr.Column():
|
| 555 |
-
images = gr.Gallery(
|
| 556 |
-
label="Upload Images",
|
| 557 |
-
type="filepath",
|
| 558 |
-
columns=2,
|
| 559 |
-
rows=1,
|
| 560 |
-
height=300,
|
| 561 |
-
allow_preview=True
|
| 562 |
-
)
|
| 563 |
-
|
| 564 |
-
prompt = gr.Text(
|
| 565 |
-
label="Edit Prompt",
|
| 566 |
-
show_label=True,
|
| 567 |
-
placeholder="e.g., transform into anime, upscale, change lighting...",
|
| 568 |
-
)
|
| 569 |
-
|
| 570 |
-
run_button = gr.Button("Edit Image", variant="primary")
|
| 571 |
-
|
| 572 |
-
with gr.Column():
|
| 573 |
-
output_image = gr.Image(
|
| 574 |
-
label="Output Image",
|
| 575 |
-
interactive=False,
|
| 576 |
-
format="png",
|
| 577 |
-
height=395
|
| 578 |
-
)
|
| 579 |
-
|
| 580 |
-
with gr.Accordion("Advanced Settings", open=False, visible=False):
|
| 581 |
-
seed = gr.Slider(
|
| 582 |
-
label="Seed", minimum=0,
|
| 583 |
-
maximum=MAX_SEED, step=1, value=0
|
| 584 |
-
)
|
| 585 |
-
randomize_seed = gr.Checkbox(
|
| 586 |
-
label="Randomize Seed", value=True
|
| 587 |
-
)
|
| 588 |
-
guidance_scale = gr.Slider(
|
| 589 |
-
label="Guidance Scale", minimum=1.0,
|
| 590 |
-
maximum=10.0, step=0.1, value=1.0
|
| 591 |
-
)
|
| 592 |
-
steps = gr.Slider(
|
| 593 |
-
label="Inference Steps", minimum=1,
|
| 594 |
-
maximum=50, step=1, value=4
|
| 595 |
-
)
|
| 596 |
-
|
| 597 |
-
run_button.click(
|
| 598 |
-
fn=infer,
|
| 599 |
-
inputs=[images, prompt, seed, randomize_seed, guidance_scale, steps],
|
| 600 |
-
outputs=[output_image, seed]
|
| 601 |
-
)
|
| 602 |
-
|
| 603 |
-
if __name__ == "__main__":
|
| 604 |
-
demo.queue(max_size=30).launch(
|
| 605 |
-
css=css,
|
| 606 |
-
theme=windows_98_theme,
|
| 607 |
-
mcp_server=True,
|
| 608 |
-
ssr_mode=False,
|
| 609 |
-
show_error=True
|
| 610 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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