PeterL1n commited on
Commit
cbd20c7
1 Parent(s): 0c6962b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -9,8 +9,6 @@ from huggingface_hub import hf_hub_download
9
  from safetensors.torch import load_file
10
  from PIL import Image
11
 
12
- assert torch.cuda.is_available()
13
-
14
  device = "cuda"
15
  dtype = torch.float16
16
 
@@ -27,11 +25,11 @@ opts = {
27
  step_loaded = 4
28
  unet = UNet2DConditionModel.from_config(base, subfolder="unet")
29
  unet.load_state_dict(load_file(hf_hub_download(repo, opts["4 Steps"][0])))
30
- pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=dtype, variant="fp16").to(device, dtype)
31
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
32
 
33
  # Safety checker.
34
- safety_checker=StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker").to(device, dtype)
35
  feature_extractor=CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch32")
36
  image_processor = VaeImageProcessor(vae_scale_factor=8)
37
 
@@ -42,6 +40,10 @@ def generate(prompt, option, progress=gr.Progress()):
42
  print(prompt, option)
43
  ckpt, step = opts[option]
44
  progress((0, step))
 
 
 
 
45
  if step != step_loaded:
46
  print(f"Switching checkpoint from {step_loaded} to {step}")
47
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample" if step == 1 else "epsilon")
 
9
  from safetensors.torch import load_file
10
  from PIL import Image
11
 
 
 
12
  device = "cuda"
13
  dtype = torch.float16
14
 
 
25
  step_loaded = 4
26
  unet = UNet2DConditionModel.from_config(base, subfolder="unet")
27
  unet.load_state_dict(load_file(hf_hub_download(repo, opts["4 Steps"][0])))
28
+ pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=dtype, variant="fp16")
29
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
30
 
31
  # Safety checker.
32
+ safety_checker=StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker")
33
  feature_extractor=CLIPImageProcessor.from_pretrained("openai/clip-vit-base-patch32")
34
  image_processor = VaeImageProcessor(vae_scale_factor=8)
35
 
 
40
  print(prompt, option)
41
  ckpt, step = opts[option]
42
  progress((0, step))
43
+
44
+ pipe.to(device, dtype)
45
+ safety_checker.to(device, dtype)
46
+
47
  if step != step_loaded:
48
  print(f"Switching checkpoint from {step_loaded} to {step}")
49
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample" if step == 1 else "epsilon")