zhiweili
commited on
Commit
·
fd9040f
1
Parent(s):
2a2d3ad
add seed
Browse files- app_base.py +2 -0
- upscale.py +7 -0
app_base.py
CHANGED
@@ -48,6 +48,7 @@ def create_demo() -> gr.Blocks:
|
|
48 |
upscale_prompt,
|
49 |
start_size=pre_upscale_start_size,
|
50 |
upscale_steps=pre_upscale_steps,
|
|
|
51 |
)
|
52 |
input_image = input_image.resize((generate_size, generate_size))
|
53 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
@@ -70,6 +71,7 @@ def create_demo() -> gr.Blocks:
|
|
70 |
upscale_prompt,
|
71 |
start_size=upscale_start_size,
|
72 |
upscale_steps=upscale_steps,
|
|
|
73 |
)
|
74 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
75 |
|
|
|
48 |
upscale_prompt,
|
49 |
start_size=pre_upscale_start_size,
|
50 |
upscale_steps=pre_upscale_steps,
|
51 |
+
seed=seed,
|
52 |
)
|
53 |
input_image = input_image.resize((generate_size, generate_size))
|
54 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
|
|
71 |
upscale_prompt,
|
72 |
start_size=upscale_start_size,
|
73 |
upscale_steps=upscale_steps,
|
74 |
+
seed=seed,
|
75 |
)
|
76 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
77 |
|
upscale.py
CHANGED
@@ -3,23 +3,30 @@ import torch
|
|
3 |
from PIL import Image
|
4 |
from diffusers import StableDiffusionUpscalePipeline
|
5 |
|
|
|
|
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
9 |
upscale_pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
10 |
upscale_pipe = upscale_pipe.to(device)
|
11 |
|
|
|
|
|
12 |
def upscale_image(
|
13 |
input_image: Image,
|
14 |
prompt: str,
|
15 |
start_size: int = 128,
|
16 |
upscale_steps: int = 30,
|
|
|
17 |
):
|
|
|
18 |
input_image = input_image.resize((start_size, start_size))
|
19 |
upscaled_image = upscale_pipe(
|
20 |
prompt=prompt,
|
21 |
image=input_image,
|
22 |
num_inference_steps=upscale_steps,
|
|
|
23 |
).images[0]
|
24 |
|
25 |
return upscaled_image
|
|
|
3 |
from PIL import Image
|
4 |
from diffusers import StableDiffusionUpscalePipeline
|
5 |
|
6 |
+
from hidiffusion import apply_hidiffusion
|
7 |
+
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
11 |
upscale_pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
12 |
upscale_pipe = upscale_pipe.to(device)
|
13 |
|
14 |
+
apply_hidiffusion(upscale_pipe)
|
15 |
+
|
16 |
def upscale_image(
|
17 |
input_image: Image,
|
18 |
prompt: str,
|
19 |
start_size: int = 128,
|
20 |
upscale_steps: int = 30,
|
21 |
+
seed: int = 42,
|
22 |
):
|
23 |
+
generator = torch.Generator().manual_seed(seed)
|
24 |
input_image = input_image.resize((start_size, start_size))
|
25 |
upscaled_image = upscale_pipe(
|
26 |
prompt=prompt,
|
27 |
image=input_image,
|
28 |
num_inference_steps=upscale_steps,
|
29 |
+
generator=generator,
|
30 |
).images[0]
|
31 |
|
32 |
return upscaled_image
|