Lifeinhockey commited on
Commit
50761b6
·
verified ·
1 Parent(s): 4162f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -329,6 +329,37 @@ def infer(
329
  controlnet_conditioning_scale=controlnet_conditioning_scale,
330
  generator=generator,
331
  ).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  else:
333
  # Генерация изображений с ControlNet ----------------------------------------------------------------------------------------------------------------
334
 
@@ -512,11 +543,13 @@ examples = [
512
  "The smiling man. His face and hands are visible. Anime style. The best quality.",
513
  "The smiling girl. Anime style. Best quality, high quality.",
514
  "lego batman and robin. Rich and vibrant colors.",
 
515
  ]
516
 
517
  examples_negative = [
518
  "Blurred details, low resolution, bad anatomy, no face visible, poor image of a man's face, poor quality, artifacts, black and white image.",
519
  "Monochrome, lowres, bad anatomy, worst quality, low quality",
 
520
  ]
521
 
522
  css = """
@@ -701,6 +734,7 @@ with gr.Blocks(css=css) as demo:
701
  "pose_estimation",
702
  "edge_detection",
703
  "depth_map",
 
704
  ],
705
  value="pose_estimation",
706
  interactive=True,
 
329
  controlnet_conditioning_scale=controlnet_conditioning_scale,
330
  generator=generator,
331
  ).images[0]
332
+ else
333
+
334
+ if ip_adapter_mode == "face_model":
335
+
336
+ print('ip_adapter_mode = ', ip_adapter_mode)
337
+
338
+ # Преобразование изображений для IP-Adapter (размер 224x224)
339
+ ip_source_image = preprocess_image(ip_source_image, width, height, resize_to_224=True)
340
+ ip_adapter_image = preprocess_image(ip_adapter_image, width, height, resize_to_224=True)
341
+
342
+ pipe_ip_adapter = StableDiffusionPipeline.from_pretrained(
343
+ model_default,
344
+ torch_dtype=torch_dtype,
345
+ ).to(device)
346
+
347
+ pipe_ip_adapter.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
348
+ pipe_ip_adapter.load_ip_adapter(IP_ADAPTER, subfolder="models", weight_name=WEIGHT_NAME_face)
349
+
350
+ generator = torch.Generator(device).manual_seed(seed)
351
+
352
+ pipe_ip_adapter.set_ip_adapter_scale(ip_adapter_strength)
353
+ image = pipe_ip_adapter(
354
+ prompt=prompt,
355
+ negative_prompt=negative_prompt,
356
+ ip_adapter_image=ip_adapter_image,
357
+ width=width,
358
+ height=height,
359
+ guidance_scale=guidance_scale,
360
+ num_inference_steps=num_inference_steps,
361
+ generator=generator,
362
+ ).images[0]
363
  else:
364
  # Генерация изображений с ControlNet ----------------------------------------------------------------------------------------------------------------
365
 
 
543
  "The smiling man. His face and hands are visible. Anime style. The best quality.",
544
  "The smiling girl. Anime style. Best quality, high quality.",
545
  "lego batman and robin. Rich and vibrant colors.",
546
+ "Photo of Pushkin as a hockey player in uniform with a stick, playing hockey on the ice arena in the NHL.",
547
  ]
548
 
549
  examples_negative = [
550
  "Blurred details, low resolution, bad anatomy, no face visible, poor image of a man's face, poor quality, artifacts, black and white image.",
551
  "Monochrome, lowres, bad anatomy, worst quality, low quality",
552
+ "lowres, bad anatomy, worst quality, low quality, black and white image.",
553
  ]
554
 
555
  css = """
 
734
  "pose_estimation",
735
  "edge_detection",
736
  "depth_map",
737
+ "face_model"
738
  ],
739
  value="pose_estimation",
740
  interactive=True,