Hatman commited on
Commit
6d7c4d0
·
verified ·
1 Parent(s): 2804b75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -9,16 +9,14 @@ import gradio as gr
9
  from diffusers import AutoPipelineForText2Image
10
  from diffusers.utils import load_image
11
 
12
- # global variable
13
- device = "cuda" if torch.cuda.is_available() else "cpu"
14
- dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
15
-
16
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
17
  if randomize_seed:
18
  seed = random.randint(0, 2000)
19
  return seed
20
 
21
- pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=dtype).to(device)
 
 
22
  pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
23
 
24
  @spaces.GPU()
@@ -54,7 +52,7 @@ def create_image(image_pil,
54
 
55
  style_image = load_image(image_pil)
56
 
57
- generator = torch.Generator(device=device).manual_seed(randomize_seed_fn(seed, False))
58
  image = pipeline(
59
  prompt=prompt,
60
  ip_adapter_image=style_image,
 
9
  from diffusers import AutoPipelineForText2Image
10
  from diffusers.utils import load_image
11
 
 
 
 
 
12
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
13
  if randomize_seed:
14
  seed = random.randint(0, 2000)
15
  return seed
16
 
17
+ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
18
+ torch.cuda.set_device(device)
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()
 
52
 
53
  style_image = load_image(image_pil)
54
 
55
+ generator = torch.Generator().manual_seed(randomize_seed_fn(seed, False))
56
  image = pipeline(
57
  prompt=prompt,
58
  ip_adapter_image=style_image,