amazonaws-sp commited on
Commit
fcf1f5f
1 Parent(s): 501134f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -63,7 +63,14 @@ def generate(
63
  if use_vae:
64
  vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
65
  pipe = DiffusionPipeline.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
 
 
 
66
 
 
 
 
 
67
  if use_lora:
68
  pipe.load_lora_weights(lora)
69
  pipe.fuse_lora(lora_scale)
@@ -86,6 +93,7 @@ def generate(
86
  if not use_negative_prompt_2:
87
  negative_prompt_2 = None # type: ignore
88
 
 
89
  return pipe(
90
  prompt=prompt,
91
  negative_prompt=negative_prompt,
@@ -98,7 +106,21 @@ def generate(
98
  generator=generator,
99
  output_type="pil",
100
  ).images[0]
101
- return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  examples = [
104
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
 
63
  if use_vae:
64
  vae = AutoencoderKL.from_pretrained(vaecall, torch_dtype=torch.float16)
65
  pipe = DiffusionPipeline.from_pretrained(model, vae=vae, torch_dtype=torch.float16)
66
+
67
+ if use_img2img:
68
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model, torch_dtype=torch.float16)
69
 
70
+ response = requests.get(url)
71
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
72
+ init_image = init_image.resize((1024, 1024))
73
+
74
  if use_lora:
75
  pipe.load_lora_weights(lora)
76
  pipe.fuse_lora(lora_scale)
 
93
  if not use_negative_prompt_2:
94
  negative_prompt_2 = None # type: ignore
95
 
96
+ if not use_img2img:
97
  return pipe(
98
  prompt=prompt,
99
  negative_prompt=negative_prompt,
 
106
  generator=generator,
107
  output_type="pil",
108
  ).images[0]
109
+ else:
110
+ images = pipe(
111
+ prompt=prompt,
112
+ image=init_image,
113
+ negative_prompt=negative_prompt,
114
+ prompt_2=prompt_2,
115
+ negative_prompt_2=negative_prompt_2,
116
+ width=width,
117
+ height=height,
118
+ guidance_scale=guidance_scale_base,
119
+ num_inference_steps=num_inference_steps_base,
120
+ generator=generator,
121
+ output_type="pil",
122
+ ).images[0]
123
+ return images
124
 
125
  examples = [
126
  "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",