Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -214,7 +214,7 @@ def load_and_prepare_model():
|
|
| 214 |
return pipe
|
| 215 |
|
| 216 |
# Preload and compile both models
|
| 217 |
-
|
| 218 |
|
| 219 |
MAX_SEED = np.iinfo(np.int32).max
|
| 220 |
|
|
@@ -238,11 +238,6 @@ def save_image(img):
|
|
| 238 |
img.save(unique_name,optimize=False,compress_level=0)
|
| 239 |
return unique_name
|
| 240 |
|
| 241 |
-
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 242 |
-
if randomize_seed:
|
| 243 |
-
seed = random.randint(0, MAX_SEED)
|
| 244 |
-
return seed
|
| 245 |
-
|
| 246 |
def uploadNote(prompt,num_inference_steps,guidance_scale,timestamp):
|
| 247 |
filename= f'tst_A_{timestamp}.txt'
|
| 248 |
with open(filename, "w") as f:
|
|
@@ -267,22 +262,16 @@ def generate_30(
|
|
| 267 |
negative_prompt: str = "",
|
| 268 |
use_negative_prompt: bool = False,
|
| 269 |
style_selection: str = "",
|
| 270 |
-
seed: int = 1,
|
| 271 |
width: int = 768,
|
| 272 |
height: int = 768,
|
| 273 |
guidance_scale: float = 4,
|
| 274 |
num_inference_steps: int = 125,
|
| 275 |
-
randomize_seed: bool = False,
|
| 276 |
latent_file = gr.File(), # Add latents file input
|
|
|
|
| 277 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 278 |
):
|
| 279 |
-
#torch.backends.cudnn.benchmark = False
|
| 280 |
-
#torch.cuda.empty_cache()
|
| 281 |
-
#gc.collect()
|
| 282 |
-
global models
|
| 283 |
-
pipe = models
|
| 284 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 285 |
-
seed =
|
| 286 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 287 |
if latent_file is not None: # Check if a latent file is provided
|
| 288 |
sd_image_a = Image.open(latent_file.name)
|
|
@@ -293,8 +282,9 @@ def generate_30(
|
|
| 293 |
#with torch.no_grad():
|
| 294 |
sd_image = ip_model.generate(
|
| 295 |
pil_image=sd_image_a,
|
|
|
|
| 296 |
prompt=prompt,
|
| 297 |
-
num_samples=
|
| 298 |
num_inference_steps=num_inference_steps,
|
| 299 |
guidance_scale=guidance_scale,
|
| 300 |
seed=seed
|
|
@@ -312,30 +302,24 @@ def generate_30(
|
|
| 312 |
image_paths = [save_image(downscale1)]
|
| 313 |
else:
|
| 314 |
print('-- IMAGE REQUIRED --')
|
| 315 |
-
return image_paths
|
| 316 |
|
| 317 |
@spaces.GPU(duration=60)
|
| 318 |
def generate_60(
|
| 319 |
-
prompt: str,
|
| 320 |
negative_prompt: str = "",
|
| 321 |
use_negative_prompt: bool = False,
|
| 322 |
style_selection: str = "",
|
| 323 |
-
seed: int = 1,
|
| 324 |
width: int = 768,
|
| 325 |
height: int = 768,
|
| 326 |
guidance_scale: float = 4,
|
| 327 |
-
num_inference_steps: int =
|
| 328 |
-
randomize_seed: bool = False,
|
| 329 |
latent_file = gr.File(), # Add latents file input
|
|
|
|
| 330 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 331 |
):
|
| 332 |
-
#torch.backends.cudnn.benchmark = True
|
| 333 |
-
#torch.cuda.empty_cache()
|
| 334 |
-
#gc.collect()
|
| 335 |
-
global models
|
| 336 |
-
pipe = models
|
| 337 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 338 |
-
seed =
|
| 339 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 340 |
if latent_file is not None: # Check if a latent file is provided
|
| 341 |
sd_image_a = Image.open(latent_file.name)
|
|
@@ -346,8 +330,9 @@ def generate_60(
|
|
| 346 |
#with torch.no_grad():
|
| 347 |
sd_image = ip_model.generate(
|
| 348 |
pil_image=sd_image_a,
|
|
|
|
| 349 |
prompt=prompt,
|
| 350 |
-
num_samples=
|
| 351 |
num_inference_steps=num_inference_steps,
|
| 352 |
guidance_scale=guidance_scale,
|
| 353 |
seed=seed
|
|
@@ -365,30 +350,24 @@ def generate_60(
|
|
| 365 |
image_paths = [save_image(downscale1)]
|
| 366 |
else:
|
| 367 |
print('-- IMAGE REQUIRED --')
|
| 368 |
-
return image_paths
|
| 369 |
|
| 370 |
@spaces.GPU(duration=90)
|
| 371 |
def generate_90(
|
| 372 |
-
prompt: str,
|
| 373 |
negative_prompt: str = "",
|
| 374 |
use_negative_prompt: bool = False,
|
| 375 |
style_selection: str = "",
|
| 376 |
-
seed: int = 1,
|
| 377 |
width: int = 768,
|
| 378 |
height: int = 768,
|
| 379 |
guidance_scale: float = 4,
|
| 380 |
-
num_inference_steps: int =
|
| 381 |
-
randomize_seed: bool = False,
|
| 382 |
latent_file = gr.File(), # Add latents file input
|
|
|
|
| 383 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 384 |
):
|
| 385 |
-
#torch.backends.cudnn.benchmark = True
|
| 386 |
-
#torch.cuda.empty_cache()
|
| 387 |
-
#gc.collect()
|
| 388 |
-
global models
|
| 389 |
-
pipe = models
|
| 390 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 391 |
-
seed =
|
| 392 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 393 |
if latent_file is not None: # Check if a latent file is provided
|
| 394 |
sd_image_a = Image.open(latent_file.name)
|
|
@@ -399,8 +378,9 @@ def generate_90(
|
|
| 399 |
#with torch.no_grad():
|
| 400 |
sd_image = ip_model.generate(
|
| 401 |
pil_image=sd_image_a,
|
|
|
|
| 402 |
prompt=prompt,
|
| 403 |
-
num_samples=
|
| 404 |
num_inference_steps=num_inference_steps,
|
| 405 |
guidance_scale=guidance_scale,
|
| 406 |
seed=seed
|
|
@@ -418,7 +398,7 @@ def generate_90(
|
|
| 418 |
image_paths = [save_image(downscale1)]
|
| 419 |
else:
|
| 420 |
print('-- IMAGE REQUIRED --')
|
| 421 |
-
return image_paths
|
| 422 |
|
| 423 |
def load_predefined_images1():
|
| 424 |
predefined_images1 = [
|
|
@@ -465,6 +445,7 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 465 |
|
| 466 |
with gr.Row():
|
| 467 |
latent_file = gr.File(label="Image Prompt (Required)")
|
|
|
|
| 468 |
style_selection = gr.Radio(
|
| 469 |
show_label=True,
|
| 470 |
container=True,
|
|
@@ -484,10 +465,10 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 484 |
value="('deformed', 'distorted', 'disfigured':1.3),'not photorealistic':1.5, 'poorly drawn', 'bad anatomy', 'wrong anatomy', 'extra limb', 'missing limb', 'floating limbs', 'poorly drawn hands', 'poorly drawn feet', 'poorly drawn face':1.3, 'out of frame', 'extra limbs', 'bad anatomy', 'bad art', 'beginner', 'distorted face','amateur'",
|
| 485 |
visible=True,
|
| 486 |
)
|
| 487 |
-
|
| 488 |
label="Seed",
|
| 489 |
minimum=0,
|
| 490 |
-
maximum=
|
| 491 |
step=1,
|
| 492 |
value=0,
|
| 493 |
)
|
|
@@ -547,15 +528,14 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 547 |
negative_prompt,
|
| 548 |
use_negative_prompt,
|
| 549 |
style_selection,
|
| 550 |
-
seed,
|
| 551 |
width,
|
| 552 |
height,
|
| 553 |
guidance_scale,
|
| 554 |
num_inference_steps,
|
| 555 |
-
randomize_seed,
|
| 556 |
latent_file,
|
|
|
|
| 557 |
],
|
| 558 |
-
outputs=[result
|
| 559 |
)
|
| 560 |
|
| 561 |
gr.on(
|
|
@@ -569,15 +549,14 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 569 |
negative_prompt,
|
| 570 |
use_negative_prompt,
|
| 571 |
style_selection,
|
| 572 |
-
seed,
|
| 573 |
width,
|
| 574 |
height,
|
| 575 |
guidance_scale,
|
| 576 |
num_inference_steps,
|
| 577 |
-
randomize_seed,
|
| 578 |
latent_file,
|
|
|
|
| 579 |
],
|
| 580 |
-
outputs=[result
|
| 581 |
)
|
| 582 |
|
| 583 |
gr.on(
|
|
@@ -591,15 +570,14 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
| 591 |
negative_prompt,
|
| 592 |
use_negative_prompt,
|
| 593 |
style_selection,
|
| 594 |
-
seed,
|
| 595 |
width,
|
| 596 |
height,
|
| 597 |
guidance_scale,
|
| 598 |
num_inference_steps,
|
| 599 |
-
randomize_seed,
|
| 600 |
latent_file,
|
|
|
|
| 601 |
],
|
| 602 |
-
outputs=[result
|
| 603 |
)
|
| 604 |
|
| 605 |
gr.Markdown("### REALVISXL V5.0")
|
|
|
|
| 214 |
return pipe
|
| 215 |
|
| 216 |
# Preload and compile both models
|
| 217 |
+
pipe = load_and_prepare_model()
|
| 218 |
|
| 219 |
MAX_SEED = np.iinfo(np.int32).max
|
| 220 |
|
|
|
|
| 238 |
img.save(unique_name,optimize=False,compress_level=0)
|
| 239 |
return unique_name
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
def uploadNote(prompt,num_inference_steps,guidance_scale,timestamp):
|
| 242 |
filename= f'tst_A_{timestamp}.txt'
|
| 243 |
with open(filename, "w") as f:
|
|
|
|
| 262 |
negative_prompt: str = "",
|
| 263 |
use_negative_prompt: bool = False,
|
| 264 |
style_selection: str = "",
|
|
|
|
| 265 |
width: int = 768,
|
| 266 |
height: int = 768,
|
| 267 |
guidance_scale: float = 4,
|
| 268 |
num_inference_steps: int = 125,
|
|
|
|
| 269 |
latent_file = gr.File(), # Add latents file input
|
| 270 |
+
latent_file_2 = gr.File(), # Add latents file input
|
| 271 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 272 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 274 |
+
seed = random.randint(0, MAX_SEED)
|
| 275 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 276 |
if latent_file is not None: # Check if a latent file is provided
|
| 277 |
sd_image_a = Image.open(latent_file.name)
|
|
|
|
| 282 |
#with torch.no_grad():
|
| 283 |
sd_image = ip_model.generate(
|
| 284 |
pil_image=sd_image_a,
|
| 285 |
+
pil_image_2=sd_image_b,
|
| 286 |
prompt=prompt,
|
| 287 |
+
num_samples=samples,
|
| 288 |
num_inference_steps=num_inference_steps,
|
| 289 |
guidance_scale=guidance_scale,
|
| 290 |
seed=seed
|
|
|
|
| 302 |
image_paths = [save_image(downscale1)]
|
| 303 |
else:
|
| 304 |
print('-- IMAGE REQUIRED --')
|
| 305 |
+
return image_paths
|
| 306 |
|
| 307 |
@spaces.GPU(duration=60)
|
| 308 |
def generate_60(
|
| 309 |
+
prompt: str = "",
|
| 310 |
negative_prompt: str = "",
|
| 311 |
use_negative_prompt: bool = False,
|
| 312 |
style_selection: str = "",
|
|
|
|
| 313 |
width: int = 768,
|
| 314 |
height: int = 768,
|
| 315 |
guidance_scale: float = 4,
|
| 316 |
+
num_inference_steps: int = 125,
|
|
|
|
| 317 |
latent_file = gr.File(), # Add latents file input
|
| 318 |
+
latent_file_2 = gr.File(), # Add latents file input
|
| 319 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 320 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 322 |
+
seed = random.randint(0, MAX_SEED)
|
| 323 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 324 |
if latent_file is not None: # Check if a latent file is provided
|
| 325 |
sd_image_a = Image.open(latent_file.name)
|
|
|
|
| 330 |
#with torch.no_grad():
|
| 331 |
sd_image = ip_model.generate(
|
| 332 |
pil_image=sd_image_a,
|
| 333 |
+
pil_image_2=sd_image_b,
|
| 334 |
prompt=prompt,
|
| 335 |
+
num_samples=samples,
|
| 336 |
num_inference_steps=num_inference_steps,
|
| 337 |
guidance_scale=guidance_scale,
|
| 338 |
seed=seed
|
|
|
|
| 350 |
image_paths = [save_image(downscale1)]
|
| 351 |
else:
|
| 352 |
print('-- IMAGE REQUIRED --')
|
| 353 |
+
return image_paths
|
| 354 |
|
| 355 |
@spaces.GPU(duration=90)
|
| 356 |
def generate_90(
|
| 357 |
+
prompt: str = "",
|
| 358 |
negative_prompt: str = "",
|
| 359 |
use_negative_prompt: bool = False,
|
| 360 |
style_selection: str = "",
|
|
|
|
| 361 |
width: int = 768,
|
| 362 |
height: int = 768,
|
| 363 |
guidance_scale: float = 4,
|
| 364 |
+
num_inference_steps: int = 125,
|
|
|
|
| 365 |
latent_file = gr.File(), # Add latents file input
|
| 366 |
+
latent_file_2 = gr.File(), # Add latents file input
|
| 367 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
| 368 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
ip_model = IPAdapterXL(pipe, local_folder, ip_ckpt, device)
|
| 370 |
+
seed = random.randint(0, MAX_SEED)
|
| 371 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
| 372 |
if latent_file is not None: # Check if a latent file is provided
|
| 373 |
sd_image_a = Image.open(latent_file.name)
|
|
|
|
| 378 |
#with torch.no_grad():
|
| 379 |
sd_image = ip_model.generate(
|
| 380 |
pil_image=sd_image_a,
|
| 381 |
+
pil_image_2=sd_image_b,
|
| 382 |
prompt=prompt,
|
| 383 |
+
num_samples=samples,
|
| 384 |
num_inference_steps=num_inference_steps,
|
| 385 |
guidance_scale=guidance_scale,
|
| 386 |
seed=seed
|
|
|
|
| 398 |
image_paths = [save_image(downscale1)]
|
| 399 |
else:
|
| 400 |
print('-- IMAGE REQUIRED --')
|
| 401 |
+
return image_paths
|
| 402 |
|
| 403 |
def load_predefined_images1():
|
| 404 |
predefined_images1 = [
|
|
|
|
| 445 |
|
| 446 |
with gr.Row():
|
| 447 |
latent_file = gr.File(label="Image Prompt (Required)")
|
| 448 |
+
latent_file_2 = gr.File(label="Image Prompt 2 (Optional)")
|
| 449 |
style_selection = gr.Radio(
|
| 450 |
show_label=True,
|
| 451 |
container=True,
|
|
|
|
| 465 |
value="('deformed', 'distorted', 'disfigured':1.3),'not photorealistic':1.5, 'poorly drawn', 'bad anatomy', 'wrong anatomy', 'extra limb', 'missing limb', 'floating limbs', 'poorly drawn hands', 'poorly drawn feet', 'poorly drawn face':1.3, 'out of frame', 'extra limbs', 'bad anatomy', 'bad art', 'beginner', 'distorted face','amateur'",
|
| 466 |
visible=True,
|
| 467 |
)
|
| 468 |
+
samples = gr.Slider(
|
| 469 |
label="Seed",
|
| 470 |
minimum=0,
|
| 471 |
+
maximum=20,
|
| 472 |
step=1,
|
| 473 |
value=0,
|
| 474 |
)
|
|
|
|
| 528 |
negative_prompt,
|
| 529 |
use_negative_prompt,
|
| 530 |
style_selection,
|
|
|
|
| 531 |
width,
|
| 532 |
height,
|
| 533 |
guidance_scale,
|
| 534 |
num_inference_steps,
|
|
|
|
| 535 |
latent_file,
|
| 536 |
+
latent_file_2,
|
| 537 |
],
|
| 538 |
+
outputs=[result],
|
| 539 |
)
|
| 540 |
|
| 541 |
gr.on(
|
|
|
|
| 549 |
negative_prompt,
|
| 550 |
use_negative_prompt,
|
| 551 |
style_selection,
|
|
|
|
| 552 |
width,
|
| 553 |
height,
|
| 554 |
guidance_scale,
|
| 555 |
num_inference_steps,
|
|
|
|
| 556 |
latent_file,
|
| 557 |
+
latent_file_2,
|
| 558 |
],
|
| 559 |
+
outputs=[result],
|
| 560 |
)
|
| 561 |
|
| 562 |
gr.on(
|
|
|
|
| 570 |
negative_prompt,
|
| 571 |
use_negative_prompt,
|
| 572 |
style_selection,
|
|
|
|
| 573 |
width,
|
| 574 |
height,
|
| 575 |
guidance_scale,
|
| 576 |
num_inference_steps,
|
|
|
|
| 577 |
latent_file,
|
| 578 |
+
latent_file_2,
|
| 579 |
],
|
| 580 |
+
outputs=[result],
|
| 581 |
)
|
| 582 |
|
| 583 |
gr.Markdown("### REALVISXL V5.0")
|