Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,9 +15,8 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
15 |
return seed
|
16 |
|
17 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
18 |
-
print(torch.cuda.is_available())
|
19 |
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to(device)
|
20 |
-
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
21 |
|
22 |
@spaces.GPU()
|
23 |
def create_image(image_pil,
|
@@ -30,9 +29,6 @@ def create_image(image_pil,
|
|
30 |
seed,
|
31 |
target="Load only style blocks",
|
32 |
):
|
33 |
-
print('start')
|
34 |
-
torch.cuda.set_device(device)
|
35 |
-
print('torch device set')
|
36 |
if target !="Load original IP-Adapter":
|
37 |
if target=="Load only style blocks":
|
38 |
scale = {
|
@@ -48,15 +44,9 @@ def create_image(image_pil,
|
|
48 |
"up": {"block_0": [0.0, control_scale, 0.0]},
|
49 |
}
|
50 |
pipeline.set_ip_adapter_scale(scale)
|
51 |
-
|
52 |
-
print('ipscale set')
|
53 |
-
|
54 |
-
style_image = load_image(image_pil)
|
55 |
|
56 |
-
|
57 |
-
generator = torch.Generator().manual_seed(randomize_seed_fn(seed, False))
|
58 |
-
print('generator loaded')
|
59 |
-
print(pipeline.model.device)
|
60 |
image = pipeline(
|
61 |
prompt=prompt,
|
62 |
ip_adapter_image=style_image,
|
@@ -64,6 +54,7 @@ def create_image(image_pil,
|
|
64 |
guidance_scale=guidance_scale,
|
65 |
num_inference_steps=num_inference_steps,
|
66 |
generator=generator,
|
|
|
67 |
)
|
68 |
return image
|
69 |
|
|
|
15 |
return seed
|
16 |
|
17 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
|
|
18 |
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to(device)
|
19 |
+
pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin", device=device)
|
20 |
|
21 |
@spaces.GPU()
|
22 |
def create_image(image_pil,
|
|
|
29 |
seed,
|
30 |
target="Load only style blocks",
|
31 |
):
|
|
|
|
|
|
|
32 |
if target !="Load original IP-Adapter":
|
33 |
if target=="Load only style blocks":
|
34 |
scale = {
|
|
|
44 |
"up": {"block_0": [0.0, control_scale, 0.0]},
|
45 |
}
|
46 |
pipeline.set_ip_adapter_scale(scale)
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
style_image = load_image(image_pil).to(device)
|
49 |
+
generator = torch.Generator(device=deive).manual_seed(randomize_seed_fn(seed, False))
|
|
|
|
|
50 |
image = pipeline(
|
51 |
prompt=prompt,
|
52 |
ip_adapter_image=style_image,
|
|
|
54 |
guidance_scale=guidance_scale,
|
55 |
num_inference_steps=num_inference_steps,
|
56 |
generator=generator,
|
57 |
+
device=device
|
58 |
)
|
59 |
return image
|
60 |
|