Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ import gradio as gr
|
|
| 33 |
from lxml.html import fromstring
|
| 34 |
from huggingface_hub import hf_hub_download
|
| 35 |
from safetensors.torch import load_file, save_file
|
| 36 |
-
from diffusers import
|
| 37 |
from PIL import Image, ImageDraw, ImageFont
|
| 38 |
from transformers import pipeline, T5ForConditionalGeneration, T5Tokenizer
|
| 39 |
from refiners.fluxion.utils import manual_seed
|
|
@@ -418,7 +418,7 @@ CHECKPOINTS = ESRGANUpscalerCheckpoints(
|
|
| 418 |
)
|
| 419 |
|
| 420 |
device = DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 421 |
-
DTYPE = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
|
| 422 |
enhancer = ESRGANUpscaler(checkpoints=CHECKPOINTS, device=DEVICE, dtype=DTYPE)
|
| 423 |
|
| 424 |
# logging
|
|
@@ -434,15 +434,15 @@ root.addHandler(handler)
|
|
| 434 |
|
| 435 |
# constant data
|
| 436 |
|
| 437 |
-
|
| 438 |
|
| 439 |
# precision data
|
| 440 |
|
| 441 |
-
seq=
|
| 442 |
width=1536
|
| 443 |
height=1536
|
| 444 |
-
image_steps=
|
| 445 |
-
img_accu=0
|
| 446 |
|
| 447 |
# ui data
|
| 448 |
|
|
@@ -502,7 +502,9 @@ function custom(){
|
|
| 502 |
|
| 503 |
# torch pipes
|
| 504 |
|
| 505 |
-
|
|
|
|
|
|
|
| 506 |
image_pipe.enable_model_cpu_offload()
|
| 507 |
image_pipe.enable_vae_slicing()
|
| 508 |
image_pipe.enable_vae_tiling()
|
|
@@ -511,7 +513,7 @@ image_pipe.enable_vae_tiling()
|
|
| 511 |
|
| 512 |
def upscaler(
|
| 513 |
input_image: Image.Image,
|
| 514 |
-
prompt: str = "
|
| 515 |
negative_prompt: str = "Distorted, Discontinuous, Blurry, Doll-Like, Overly-Plastic, Low-Quality, Painted, Smoothed, Artificial, Phony, Gaudy, Digital Effects.",
|
| 516 |
seed: int = int(str(random.random()).split(".")[1]),
|
| 517 |
upscale_factor: int = 2,
|
|
@@ -613,13 +615,16 @@ def pipe_generate_image(p1,p2):
|
|
| 613 |
imgs = image_pipe(
|
| 614 |
prompt=p1,
|
| 615 |
negative_prompt=p2,
|
|
|
|
| 616 |
height=height,
|
| 617 |
width=width,
|
|
|
|
| 618 |
guidance_scale=img_accu,
|
| 619 |
num_images_per_prompt=1,
|
| 620 |
num_inference_steps=image_steps,
|
| 621 |
max_sequence_length=seq,
|
| 622 |
-
|
|
|
|
| 623 |
).images
|
| 624 |
log(f'RET pipe_generate')
|
| 625 |
return imgs
|
|
|
|
| 33 |
from lxml.html import fromstring
|
| 34 |
from huggingface_hub import hf_hub_download
|
| 35 |
from safetensors.torch import load_file, save_file
|
| 36 |
+
from diffusers import DiffusionPipeline
|
| 37 |
from PIL import Image, ImageDraw, ImageFont
|
| 38 |
from transformers import pipeline, T5ForConditionalGeneration, T5Tokenizer
|
| 39 |
from refiners.fluxion.utils import manual_seed
|
|
|
|
| 418 |
)
|
| 419 |
|
| 420 |
device = DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 421 |
+
DTYPE = dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
|
| 422 |
enhancer = ESRGANUpscaler(checkpoints=CHECKPOINTS, device=DEVICE, dtype=DTYPE)
|
| 423 |
|
| 424 |
# logging
|
|
|
|
| 434 |
|
| 435 |
# constant data
|
| 436 |
|
| 437 |
+
MAX_SEED = np.iinfo(np.int32).max
|
| 438 |
|
| 439 |
# precision data
|
| 440 |
|
| 441 |
+
seq=512
|
| 442 |
width=1536
|
| 443 |
height=1536
|
| 444 |
+
image_steps=50
|
| 445 |
+
img_accu=9.0
|
| 446 |
|
| 447 |
# ui data
|
| 448 |
|
|
|
|
| 502 |
|
| 503 |
# torch pipes
|
| 504 |
|
| 505 |
+
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
| 506 |
+
good_vae = AutoencoderKL.from_pretrained("ostris/Flex.1-alpha", subfolder="vae", torch_dtype=dtype).to(device)
|
| 507 |
+
image_pipe = DiffusionPipeline.from_pretrained("ostris/Flex.1-alpha", torch_dtype=dtype, vae=taef1).to(device)
|
| 508 |
image_pipe.enable_model_cpu_offload()
|
| 509 |
image_pipe.enable_vae_slicing()
|
| 510 |
image_pipe.enable_vae_tiling()
|
|
|
|
| 513 |
|
| 514 |
def upscaler(
|
| 515 |
input_image: Image.Image,
|
| 516 |
+
prompt: str = "Hyper realistic photography, Natural visual content.",
|
| 517 |
negative_prompt: str = "Distorted, Discontinuous, Blurry, Doll-Like, Overly-Plastic, Low-Quality, Painted, Smoothed, Artificial, Phony, Gaudy, Digital Effects.",
|
| 518 |
seed: int = int(str(random.random()).split(".")[1]),
|
| 519 |
upscale_factor: int = 2,
|
|
|
|
| 615 |
imgs = image_pipe(
|
| 616 |
prompt=p1,
|
| 617 |
negative_prompt=p2,
|
| 618 |
+
progress=gr.Progress(track_tqdm=True),
|
| 619 |
height=height,
|
| 620 |
width=width,
|
| 621 |
+
safety_checker=None,
|
| 622 |
guidance_scale=img_accu,
|
| 623 |
num_images_per_prompt=1,
|
| 624 |
num_inference_steps=image_steps,
|
| 625 |
max_sequence_length=seq,
|
| 626 |
+
good_vae=good_vae,
|
| 627 |
+
generator=torch.Generator(device).manual_seed(random.randint(0, MAX_SEED))
|
| 628 |
).images
|
| 629 |
log(f'RET pipe_generate')
|
| 630 |
return imgs
|