Severian commited on
Commit
1b8ab0f
·
verified ·
1 Parent(s): 90f8b0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -201,7 +201,6 @@ def inference(
201
  pipe = load_models(controlnet_model, diffusion_model)
202
  progress(0.5, desc="Models downloaded, preparing for inference...")
203
 
204
-
205
  if prompt is None or prompt == "":
206
  raise gr.Error("Prompt is required")
207
 
@@ -211,7 +210,7 @@ def inference(
211
  pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
212
 
213
  if seed == -1:
214
- seed = torch.randint(0, 2**32 - 1, (1,)).item()
215
  generator = torch.manual_seed(seed)
216
 
217
  if qr_code_content != "" or qrcode_image.size == (1, 1):
@@ -226,10 +225,10 @@ def inference(
226
  qr.make(fit=True)
227
 
228
  qrcode_image = qr.make_image(fill_color=qr_color, back_color=bg_color)
229
- qrcode_image = resize_for_condition_image(qrcode_image, 768)
230
  else:
231
  print("Using QR Code Image")
232
- qrcode_image = resize_for_condition_image(qrcode_image, 768)
233
 
234
  # Determine which image to use as init_image and control_image
235
  if use_qr_code_as_init_image:
@@ -269,8 +268,11 @@ def inference(
269
  final_image = invert_image(final_image)
270
 
271
  return final_image, seed
 
 
 
272
  except Exception as e:
273
- print(f"Error in inference: {str(e)}")
274
  return Image.new('RGB', (1024, 1024), color='white'), -1
275
 
276
  def invert_init_image_display(image):
 
201
  pipe = load_models(controlnet_model, diffusion_model)
202
  progress(0.5, desc="Models downloaded, preparing for inference...")
203
 
 
204
  if prompt is None or prompt == "":
205
  raise gr.Error("Prompt is required")
206
 
 
210
  pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
211
 
212
  if seed == -1:
213
+ seed = torch.seed() # Generate a truly random seed
214
  generator = torch.manual_seed(seed)
215
 
216
  if qr_code_content != "" or qrcode_image.size == (1, 1):
 
225
  qr.make(fit=True)
226
 
227
  qrcode_image = qr.make_image(fill_color=qr_color, back_color=bg_color)
228
+ qrcode_image = resize_for_condition_image(qrcode_image, 1024)
229
  else:
230
  print("Using QR Code Image")
231
+ qrcode_image = resize_for_condition_image(qrcode_image, 1024)
232
 
233
  # Determine which image to use as init_image and control_image
234
  if use_qr_code_as_init_image:
 
268
  final_image = invert_image(final_image)
269
 
270
  return final_image, seed
271
+ except gr.Error as e:
272
+ print(f"Gradio error in inference: {str(e)}")
273
+ return Image.new('RGB', (1024, 1024), color='white'), -1
274
  except Exception as e:
275
+ print(f"Unexpected error in inference: {str(e)}")
276
  return Image.new('RGB', (1024, 1024), color='white'), -1
277
 
278
  def invert_init_image_display(image):