Spaces:
Sleeping
Sleeping
Bobby
commited on
Commit
·
53a2cd6
1
Parent(s):
f40aafb
revert
Browse files
app.py
CHANGED
|
@@ -19,9 +19,8 @@ from diffusers import (
|
|
| 19 |
ControlNetModel,
|
| 20 |
DPMSolverMultistepScheduler,
|
| 21 |
StableDiffusionControlNetPipeline,
|
| 22 |
-
|
| 23 |
)
|
| 24 |
-
from huggingface_hub import hf_hub_download, hf_hub_url
|
| 25 |
from controlnet_aux_local import NormalBaeDetector
|
| 26 |
|
| 27 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -39,31 +38,18 @@ class Preprocessor:
|
|
| 39 |
self.model = None
|
| 40 |
self.name = ""
|
| 41 |
|
| 42 |
-
# def load(self, name: str) -> None:
|
| 43 |
-
# if name == self.name:
|
| 44 |
-
# return
|
| 45 |
-
# elif name == "NormalBae":
|
| 46 |
-
# print("Loading NormalBae")
|
| 47 |
-
# self.model = NormalBaeDetector.from_pretrained(self.MODEL_ID).to("cuda")
|
| 48 |
-
# torch.cuda.empty_cache()
|
| 49 |
-
# self.name = name
|
| 50 |
-
# else:
|
| 51 |
-
# raise ValueError
|
| 52 |
-
# return
|
| 53 |
-
|
| 54 |
def load(self, name: str) -> None:
|
| 55 |
if name == self.name:
|
| 56 |
return
|
| 57 |
elif name == "NormalBae":
|
| 58 |
print("Loading NormalBae")
|
| 59 |
-
|
| 60 |
-
self.model = NormalBaeDetector.from_pretrained(model_file).to("cuda")
|
| 61 |
torch.cuda.empty_cache()
|
| 62 |
self.name = name
|
| 63 |
else:
|
| 64 |
raise ValueError
|
| 65 |
return
|
| 66 |
-
|
| 67 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 68 |
return self.model(image, **kwargs)
|
| 69 |
|
|
@@ -78,26 +64,9 @@ controlnet = ControlNetModel.from_pretrained(
|
|
| 78 |
attn_implementation="flash_attention_2",
|
| 79 |
).to("cuda")
|
| 80 |
|
| 81 |
-
# # Scheduler
|
| 82 |
-
# scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
| 83 |
-
# "runwayml/stable-diffusion-v1-5",
|
| 84 |
-
# solver_order=2,
|
| 85 |
-
# subfolder="scheduler",
|
| 86 |
-
# use_karras_sigmas=True,
|
| 87 |
-
# final_sigmas_type="sigma_min",
|
| 88 |
-
# algorithm_type="sde-dpmsolver++",
|
| 89 |
-
# prediction_type="epsilon",
|
| 90 |
-
# thresholding=False,
|
| 91 |
-
# denoise_final=True,
|
| 92 |
-
# device_map="cuda",
|
| 93 |
-
# torch_dtype=torch.float16,
|
| 94 |
-
# )
|
| 95 |
-
|
| 96 |
# Scheduler
|
| 97 |
-
scheduler_repo = "runwayml/stable-diffusion-v1-5"
|
| 98 |
-
scheduler_file = hf_hub_download(scheduler_repo, filename="scheduler/scheduler_config.json", subfolder="scheduler")
|
| 99 |
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
| 100 |
-
|
| 101 |
solver_order=2,
|
| 102 |
subfolder="scheduler",
|
| 103 |
use_karras_sigmas=True,
|
|
@@ -110,52 +79,50 @@ scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
|
| 110 |
torch_dtype=torch.float16,
|
| 111 |
)
|
| 112 |
|
|
|
|
| 113 |
# Stable Diffusion Pipeline URL
|
| 114 |
# base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
|
| 115 |
base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
|
| 116 |
vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
|
| 117 |
|
| 118 |
# print('loading vae')
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
# print('loading pipe')
|
| 123 |
-
# pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 124 |
-
# base_model_url,
|
| 125 |
-
# safety_checker=None,
|
| 126 |
-
# # load_safety_checker=True,
|
| 127 |
-
# controlnet=controlnet,
|
| 128 |
-
# scheduler=scheduler,
|
| 129 |
-
# # vae=vae,
|
| 130 |
-
# torch_dtype=torch.float16,
|
| 131 |
-
# )
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
print('loading pipe')
|
| 138 |
pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 139 |
-
|
| 140 |
safety_checker=None,
|
| 141 |
controlnet=controlnet,
|
| 142 |
scheduler=scheduler,
|
|
|
|
| 143 |
torch_dtype=torch.float16,
|
| 144 |
)
|
| 145 |
|
| 146 |
print("loading preprocessor")
|
| 147 |
preprocessor = Preprocessor()
|
| 148 |
preprocessor.load("NormalBae")
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
pipe.to("cuda")
|
| 160 |
|
| 161 |
|
|
|
|
| 19 |
ControlNetModel,
|
| 20 |
DPMSolverMultistepScheduler,
|
| 21 |
StableDiffusionControlNetPipeline,
|
| 22 |
+
AutoencoderKL,
|
| 23 |
)
|
|
|
|
| 24 |
from controlnet_aux_local import NormalBaeDetector
|
| 25 |
|
| 26 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 38 |
self.model = None
|
| 39 |
self.name = ""
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def load(self, name: str) -> None:
|
| 42 |
if name == self.name:
|
| 43 |
return
|
| 44 |
elif name == "NormalBae":
|
| 45 |
print("Loading NormalBae")
|
| 46 |
+
self.model = NormalBaeDetector.from_pretrained(self.MODEL_ID).to("cuda")
|
|
|
|
| 47 |
torch.cuda.empty_cache()
|
| 48 |
self.name = name
|
| 49 |
else:
|
| 50 |
raise ValueError
|
| 51 |
return
|
| 52 |
+
|
| 53 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 54 |
return self.model(image, **kwargs)
|
| 55 |
|
|
|
|
| 64 |
attn_implementation="flash_attention_2",
|
| 65 |
).to("cuda")
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# Scheduler
|
|
|
|
|
|
|
| 68 |
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
| 69 |
+
"runwayml/stable-diffusion-v1-5",
|
| 70 |
solver_order=2,
|
| 71 |
subfolder="scheduler",
|
| 72 |
use_karras_sigmas=True,
|
|
|
|
| 79 |
torch_dtype=torch.float16,
|
| 80 |
)
|
| 81 |
|
| 82 |
+
|
| 83 |
# Stable Diffusion Pipeline URL
|
| 84 |
# base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
|
| 85 |
base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
|
| 86 |
vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
|
| 87 |
|
| 88 |
# print('loading vae')
|
| 89 |
+
vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
|
| 90 |
+
vae.to(memory_format=torch.channels_last)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
print('loading pipe')
|
| 93 |
+
pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 94 |
+
base_model_url,
|
| 95 |
+
safety_checker=None,
|
| 96 |
+
# load_safety_checker=True,
|
| 97 |
+
controlnet=controlnet,
|
| 98 |
+
scheduler=scheduler,
|
| 99 |
+
# vae=vae,
|
| 100 |
+
torch_dtype=torch.float16,
|
| 101 |
+
)
|
| 102 |
|
| 103 |
print('loading pipe')
|
| 104 |
pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 105 |
+
base_model_url,
|
| 106 |
safety_checker=None,
|
| 107 |
controlnet=controlnet,
|
| 108 |
scheduler=scheduler,
|
| 109 |
+
vae=vae,
|
| 110 |
torch_dtype=torch.float16,
|
| 111 |
)
|
| 112 |
|
| 113 |
print("loading preprocessor")
|
| 114 |
preprocessor = Preprocessor()
|
| 115 |
preprocessor.load("NormalBae")
|
| 116 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
|
| 117 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
|
| 118 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
|
| 119 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
|
| 120 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
|
| 121 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
|
| 122 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
|
| 123 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
|
| 124 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
|
| 125 |
+
pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
|
| 126 |
pipe.to("cuda")
|
| 127 |
|
| 128 |
|