Severian commited on
Commit
6ec9be2
·
verified ·
1 Parent(s): b2c7457

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -109,6 +109,7 @@ def scan_qr_code(image):
109
 
110
  return None
111
 
 
112
  @spaces.GPU()
113
  def inference(
114
  qr_code_content: str,
@@ -151,23 +152,34 @@ def inference(
151
  print("Using QR Code Image")
152
  qrcode_image = resize_for_condition_image(qrcode_image, 768)
153
 
154
- # hack due to gradio examples
155
- init_image = qrcode_image
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  out = pipe(
158
  prompt=prompt,
159
  negative_prompt=negative_prompt,
160
- image=qrcode_image,
161
- control_image=qrcode_image, # type: ignore
162
- width=768, # type: ignore
163
- height=768, # type: ignore
164
  guidance_scale=float(guidance_scale),
165
- controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
166
  generator=generator,
167
  strength=float(strength),
168
  num_inference_steps=50,
169
  )
170
- return out.images[0] # type: ignore
171
  except Exception as e:
172
  print(f"Error in inference: {str(e)}")
173
  # Return a blank image in case of an error
@@ -229,7 +241,7 @@ with gr.Blocks(theme='Hev832/Applio') as blocks:
229
  use_qr_code_as_init_image = gr.Checkbox(
230
  label="Use QR code as init image",
231
  value=True,
232
- interactive=False,
233
  info="Whether init image should be QR code. Unclick to pass init image or generate init image with Stable Diffusion 2.1"
234
  )
235
  with gr.Accordion(label="Init Images (Optional)", open=False, visible=True) as init_image_acc:
 
109
 
110
  return None
111
 
112
+
113
  @spaces.GPU()
114
  def inference(
115
  qr_code_content: str,
 
152
  print("Using QR Code Image")
153
  qrcode_image = resize_for_condition_image(qrcode_image, 768)
154
 
155
+ # Determine which image to use as init_image and control_image
156
+ if use_qr_code_as_init_image:
157
+ init_image = qrcode_image
158
+ control_image = qrcode_image
159
+ else:
160
+ control_image = qrcode_image
161
+ if init_image is None:
162
+ # If no init_image provided, set strength to 1.0 to generate a new image
163
+ strength = 1.0
164
+
165
+ # Adjust strength if using an init_image
166
+ if init_image is not None:
167
+ strength = min(strength, 0.8) # Cap strength at 0.8 when using init_image
168
 
169
  out = pipe(
170
  prompt=prompt,
171
  negative_prompt=negative_prompt,
172
+ image=init_image,
173
+ control_image=control_image,
174
+ width=768,
175
+ height=768,
176
  guidance_scale=float(guidance_scale),
177
+ controlnet_conditioning_scale=float(controlnet_conditioning_scale),
178
  generator=generator,
179
  strength=float(strength),
180
  num_inference_steps=50,
181
  )
182
+ return out.images[0]
183
  except Exception as e:
184
  print(f"Error in inference: {str(e)}")
185
  # Return a blank image in case of an error
 
241
  use_qr_code_as_init_image = gr.Checkbox(
242
  label="Use QR code as init image",
243
  value=True,
244
+ interactive=True,
245
  info="Whether init image should be QR code. Unclick to pass init image or generate init image with Stable Diffusion 2.1"
246
  )
247
  with gr.Accordion(label="Init Images (Optional)", open=False, visible=True) as init_image_acc: