tori29umai commited on
Commit
7108a6a
·
verified ·
1 Parent(s): 6edd6df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import spaces
2
  import gradio as gr
3
  import torch
4
  from diffusers import ControlNetModel, StableDiffusionXLControlNetImg2ImgPipeline, AutoencoderKL
 
5
  from PIL import Image
6
  import os
7
  import time
@@ -41,14 +42,18 @@ def load_model(lora_model):
41
  pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
42
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=dtype
43
  )
 
 
44
  pipe.enable_model_cpu_offload()
45
 
46
  # LoRAモデルの設定
47
  if lora_model == "とりにく風":
48
- pipe.load_lora_weights(lora_dir, weight_name="tori29umai_line.safetensors", adapter_name="tori29umai_line")
49
- pipe.set_adapters(["tori29umai_line"], adapter_weights=[0.7])
 
50
  elif lora_model == "プレーン":
51
- pass # プレーンの場合はLoRAを読み込まない
 
52
 
53
  # 現在のLoRAモデルを保存
54
  current_lora_model = lora_model
@@ -85,8 +90,9 @@ def predict(lora_model, input_image_path, prompt, negative_prompt, controlnet_sc
85
  negative_prompt=negative_prompt,
86
  controlnet_conditioning_scale=float(controlnet_scale),
87
  generator=generator,
88
- num_inference_steps=30,
89
- eta=1.0,
 
90
  ).images[0]
91
  print(f"Time taken: {time.time() - last_time}")
92
  output_image = output_image.resize(input_image.size, Image.LANCZOS)
 
2
  import gradio as gr
3
  import torch
4
  from diffusers import ControlNetModel, StableDiffusionXLControlNetImg2ImgPipeline, AutoencoderKL
5
+ from scheduling_tcd import TCDScheduler
6
  from PIL import Image
7
  import os
8
  import time
 
42
  pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
43
  "cagliostrolab/animagine-xl-3.1", controlnet=controlnet, vae=vae, torch_dtype=dtype
44
  )
45
+ pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
46
+
47
  pipe.enable_model_cpu_offload()
48
 
49
  # LoRAモデルの設定
50
  if lora_model == "とりにく風":
51
+ pipe.load_lora_weights(lora_dir, weight_name="tcd-animaginexl-3_1.safetensors", adapter_name="tcd-animaginexl-3_1")
52
+ pipe.load_lora_weights(lora_dir, weight_name="tori29umai_line.safetensors", adapter_name="tori29umai_line")
53
+ pipe.set_adapters(["tcd-animaginexl-3_1", "tori29umai_line"], adapter_weights=[1.0, 1.0])
54
  elif lora_model == "プレーン":
55
+ pipe.load_lora_weights(lora_dir, weight_name="tcd-animaginexl-3_1.safetensors", adapter_name="tcd-animaginexl-3_1")
56
+ pipe.set_adapters(["tcd-animaginexl-3_1"], adapter_weights=[1.0])
57
 
58
  # 現在のLoRAモデルを保存
59
  current_lora_model = lora_model
 
90
  negative_prompt=negative_prompt,
91
  controlnet_conditioning_scale=float(controlnet_scale),
92
  generator=generator,
93
+ num_inference_steps=4,
94
+ guidance_scale=0,
95
+ eta=0.3,
96
  ).images[0]
97
  print(f"Time taken: {time.time() - last_time}")
98
  output_image = output_image.resize(input_image.size, Image.LANCZOS)