amazonaws-la commited on
Commit
4c85b9a
·
verified ·
1 Parent(s): 0cd874b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -9,8 +9,10 @@ import gradio as gr
9
  import numpy as np
10
  import PIL.Image
11
  import spaces
 
12
  import torch
13
- from diffusers import AutoencoderKL, DiffusionPipeline
 
14
 
15
  DESCRIPTION = "# SDXL"
16
  if not torch.cuda.is_available():
@@ -55,12 +57,13 @@ def generate(
55
  model = 'SG161222/Realistic_Vision_V6.0_B1_noVAE',
56
  vaecall = 'stabilityai/sd-vae-ft-mse',
57
  lora = 'amazonaws-la/juliette',
 
58
  lora_scale: float = 0.7,
59
  ) -> PIL.Image.Image:
60
  if torch.cuda.is_available():
61
 
62
  if not use_vae:
63
- pipe = DiffusionPipeline.from_pretrained(model, torch_dtype=torch.float16)
64
 
65
  if use_vae:
66
  vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
@@ -69,7 +72,11 @@ def generate(
69
  if use_lora:
70
  pipe.load_lora_weights(lora)
71
  pipe.fuse_lora(lora_scale=0.7)
72
-
 
 
 
 
73
  if ENABLE_CPU_OFFLOAD:
74
  pipe.enable_model_cpu_offload()
75
 
@@ -99,6 +106,7 @@ def generate(
99
  guidance_scale=guidance_scale_base,
100
  num_inference_steps=num_inference_steps_base,
101
  generator=generator,
 
102
  output_type="pil",
103
  ).images[0]
104
  else:
 
9
  import numpy as np
10
  import PIL.Image
11
  import spaces
12
+ import requests
13
  import torch
14
+ from io import BytesIO
15
+ from diffusers import StableDiffusionImg2ImgPipeline, AutoencoderKL, DiffusionPipeline
16
 
17
  DESCRIPTION = "# SDXL"
18
  if not torch.cuda.is_available():
 
57
  model = 'SG161222/Realistic_Vision_V6.0_B1_noVAE',
58
  vaecall = 'stabilityai/sd-vae-ft-mse',
59
  lora = 'amazonaws-la/juliette',
60
+ url = 'https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg'
61
  lora_scale: float = 0.7,
62
  ) -> PIL.Image.Image:
63
  if torch.cuda.is_available():
64
 
65
  if not use_vae:
66
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model, torch_dtype=torch.float16)
67
 
68
  if use_vae:
69
  vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
 
72
  if use_lora:
73
  pipe.load_lora_weights(lora)
74
  pipe.fuse_lora(lora_scale=0.7)
75
+
76
+ response = requests.get(url)
77
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
78
+ init_image = init_image.resize((1024, 1024))
79
+
80
  if ENABLE_CPU_OFFLOAD:
81
  pipe.enable_model_cpu_offload()
82
 
 
106
  guidance_scale=guidance_scale_base,
107
  num_inference_steps=num_inference_steps_base,
108
  generator=generator,
109
+ image=init_image
110
  output_type="pil",
111
  ).images[0]
112
  else: