Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ 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=
|
| 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:
|
|
@@ -49,7 +49,7 @@ 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,
|
|
@@ -58,7 +58,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('cpu')
|
| 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:
|
|
|
|
| 49 |
pipeline.set_ip_adapter_scale(scale)
|
| 50 |
|
| 51 |
style_image = load_image(image_pil)
|
| 52 |
+
generator = torch.Generator(device='cpu').manual_seed(randomize_seed_fn(seed, True))
|
| 53 |
torch.cuda.set_device(device)
|
| 54 |
image = pipeline(
|
| 55 |
prompt=prompt,
|
|
|
|
| 58 |
guidance_scale=guidance_scale,
|
| 59 |
num_inference_steps=num_inference_steps,
|
| 60 |
generator=generator,
|
| 61 |
+
device='cuda:0'
|
| 62 |
)
|
| 63 |
return image
|
| 64 |
|