appsnprojectsstpl-tech commited on
Commit
c5491ef
·
1 Parent(s): 0cba1d4

Fix ZeroGPU crash by deferring .to(cuda)

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -10,19 +10,21 @@ pipe_t2i = StableDiffusionPipeline.from_pretrained(
10
  "runwayml/stable-diffusion-v1-5",
11
  torch_dtype=torch.float16,
12
  safety_checker=None
13
- ).to("cuda")
14
 
15
  # 2. Instruct-Pix2Pix Model (Instruction-Based Editing)
16
  pipe_edit = StableDiffusionInstructPix2PixPipeline.from_pretrained(
17
  "timbrooks/instruct-pix2pix",
18
  torch_dtype=torch.float16,
19
  safety_checker=None
20
- ).to("cuda")
21
 
22
  print("Models loaded successfully!")
23
 
24
  @spaces.GPU
25
  def generate_or_edit(prompt, input_image, image_guidance_scale, guidance_scale, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
 
 
26
  if randomize_seed:
27
  seed = torch.randint(0, 2**32 - 1, (1,)).item()
28
  generator = torch.Generator("cuda").manual_seed(int(seed))
 
10
  "runwayml/stable-diffusion-v1-5",
11
  torch_dtype=torch.float16,
12
  safety_checker=None
13
+ )
14
 
15
  # 2. Instruct-Pix2Pix Model (Instruction-Based Editing)
16
  pipe_edit = StableDiffusionInstructPix2PixPipeline.from_pretrained(
17
  "timbrooks/instruct-pix2pix",
18
  torch_dtype=torch.float16,
19
  safety_checker=None
20
+ )
21
 
22
  print("Models loaded successfully!")
23
 
24
  @spaces.GPU
25
  def generate_or_edit(prompt, input_image, image_guidance_scale, guidance_scale, num_inference_steps, seed, randomize_seed, progress=gr.Progress(track_tqdm=True)):
26
+ pipe_t2i.to("cuda")
27
+ pipe_edit.to("cuda")
28
  if randomize_seed:
29
  seed = torch.randint(0, 2**32 - 1, (1,)).item()
30
  generator = torch.Generator("cuda").manual_seed(int(seed))