Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,11 @@ from torchvision import transforms
|
|
13 |
|
14 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
15 |
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
16 |
-
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float32).to(
|
17 |
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
18 |
|
|
|
|
|
19 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
20 |
if randomize_seed:
|
21 |
seed = random.randint(0, 2000)
|
@@ -32,6 +34,7 @@ def create_image(image_pil,
|
|
32 |
seed,
|
33 |
target="Load only style blocks",
|
34 |
):
|
|
|
35 |
if target !="Load original IP-Adapter":
|
36 |
if target=="Load only style blocks":
|
37 |
scale = {
|
@@ -49,8 +52,9 @@ def create_image(image_pil,
|
|
49 |
pipeline.set_ip_adapter_scale(scale)
|
50 |
|
51 |
style_image = load_image(image_pil)
|
52 |
-
generator = torch.Generator(device=
|
53 |
torch.cuda.set_device(device)
|
|
|
54 |
image = pipeline(
|
55 |
prompt=prompt,
|
56 |
ip_adapter_image=style_image,
|
@@ -58,7 +62,7 @@ def create_image(image_pil,
|
|
58 |
guidance_scale=guidance_scale,
|
59 |
num_inference_steps=num_inference_steps,
|
60 |
generator=generator,
|
61 |
-
device=
|
62 |
)
|
63 |
return image
|
64 |
|
|
|
13 |
|
14 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
15 |
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
16 |
+
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float32).to(device)
|
17 |
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
18 |
|
19 |
+
print(device)
|
20 |
+
|
21 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
22 |
if randomize_seed:
|
23 |
seed = random.randint(0, 2000)
|
|
|
34 |
seed,
|
35 |
target="Load only style blocks",
|
36 |
):
|
37 |
+
print(device)
|
38 |
if target !="Load original IP-Adapter":
|
39 |
if target=="Load only style blocks":
|
40 |
scale = {
|
|
|
52 |
pipeline.set_ip_adapter_scale(scale)
|
53 |
|
54 |
style_image = load_image(image_pil)
|
55 |
+
generator = torch.Generator(device=device).manual_seed(randomize_seed_fn(seed, True))
|
56 |
torch.cuda.set_device(device)
|
57 |
+
print(device)
|
58 |
image = pipeline(
|
59 |
prompt=prompt,
|
60 |
ip_adapter_image=style_image,
|
|
|
62 |
guidance_scale=guidance_scale,
|
63 |
num_inference_steps=num_inference_steps,
|
64 |
generator=generator,
|
65 |
+
device=device
|
66 |
)
|
67 |
return image
|
68 |
|