Spaces:
Sleeping
Sleeping
Commit
·
8c988dd
1
Parent(s):
01be129
optimize
Browse files- app.py +75 -76
- local_app.py +102 -79
app.py
CHANGED
|
@@ -55,71 +55,70 @@ class Preprocessor:
|
|
| 55 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 56 |
return self.model(image, **kwargs)
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
use_karras_sigmas=True,
|
| 75 |
-
final_sigmas_type="sigma_min",
|
| 76 |
-
algorithm_type="sde-dpmsolver++",
|
| 77 |
-
prediction_type="epsilon",
|
| 78 |
-
thresholding=False,
|
| 79 |
-
denoise_final=True,
|
| 80 |
-
device_map="cuda",
|
| 81 |
-
torch_dtype=torch.float16,
|
| 82 |
-
)
|
| 83 |
|
| 84 |
-
# Stable Diffusion Pipeline URL
|
| 85 |
-
# base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
|
| 86 |
-
base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
|
| 87 |
-
# vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
|
| 88 |
|
| 89 |
-
# print('loading vae')
|
| 90 |
-
# vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
|
| 91 |
-
# vae.to(memory_format=torch.channels_last)
|
| 92 |
|
| 93 |
-
print('loading pipe')
|
| 94 |
-
pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
).to("cuda")
|
| 102 |
|
| 103 |
-
print("loading preprocessor")
|
| 104 |
-
preprocessor = Preprocessor()
|
| 105 |
-
preprocessor.load("NormalBae")
|
| 106 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
|
| 107 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
|
| 108 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
|
| 109 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
|
| 110 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
|
| 111 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
|
| 112 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
|
| 113 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
|
| 114 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
|
| 115 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
|
| 116 |
-
pipe.to("cuda")
|
| 117 |
|
| 118 |
-
print("---------------Loaded controlnet pipeline---------------")
|
| 119 |
-
torch.cuda.empty_cache()
|
| 120 |
-
gc.collect()
|
| 121 |
-
print(f"CUDA memory allocated: {torch.cuda.max_memory_allocated(device='cuda') / 1e9:.2f} GB")
|
| 122 |
-
print("Model Compiled!")
|
| 123 |
|
| 124 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 125 |
if randomize_seed:
|
|
@@ -135,7 +134,7 @@ def get_additional_prompt():
|
|
| 135 |
# outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
|
| 136 |
|
| 137 |
def get_prompt(prompt, additional_prompt):
|
| 138 |
-
interior = "design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length
|
| 139 |
default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 140 |
default2 = f"professional 3d model {prompt},octane render,highly detailed,volumetric,dramatic lighting,hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 141 |
randomize = get_additional_prompt()
|
|
@@ -173,51 +172,51 @@ style_list = [
|
|
| 173 |
},
|
| 174 |
{
|
| 175 |
"name": "Minimalistic",
|
| 176 |
-
"prompt": "Minimalist interior design,
|
| 177 |
},
|
| 178 |
{
|
| 179 |
"name": "Boho",
|
| 180 |
-
"prompt": "Bohemian chic interior,
|
| 181 |
},
|
| 182 |
{
|
| 183 |
"name": "Farmhouse",
|
| 184 |
-
"prompt": "Modern farmhouse interior,
|
| 185 |
},
|
| 186 |
{
|
| 187 |
"name": "Saudi Prince",
|
| 188 |
-
"prompt": "Opulent gold interior,
|
| 189 |
},
|
| 190 |
{
|
| 191 |
"name": "Neoclassical",
|
| 192 |
-
"prompt": "Neoclassical interior design,
|
| 193 |
},
|
| 194 |
{
|
| 195 |
"name": "Eclectic",
|
| 196 |
-
"prompt": "Eclectic interior design,
|
| 197 |
},
|
| 198 |
{
|
| 199 |
"name": "Parisian",
|
| 200 |
-
"prompt": "Parisian apartment interior,
|
| 201 |
},
|
| 202 |
{
|
| 203 |
"name": "Hollywood",
|
| 204 |
-
"prompt": "Hollywood Regency interior,
|
| 205 |
},
|
| 206 |
{
|
| 207 |
"name": "Scandinavian",
|
| 208 |
-
"prompt": "Scandinavian interior design,
|
| 209 |
},
|
| 210 |
{
|
| 211 |
"name": "Beach",
|
| 212 |
-
"prompt": "Coastal beach house interior,
|
| 213 |
},
|
| 214 |
{
|
| 215 |
"name": "Japanese",
|
| 216 |
-
"prompt": "Traditional Japanese interior,
|
| 217 |
},
|
| 218 |
{
|
| 219 |
"name": "Midcentury Modern",
|
| 220 |
-
"prompt": "Mid-century modern interior,
|
| 221 |
},
|
| 222 |
{
|
| 223 |
"name": "Retro Futurism",
|
|
@@ -225,11 +224,11 @@ style_list = [
|
|
| 225 |
},
|
| 226 |
{
|
| 227 |
"name": "Texan",
|
| 228 |
-
"prompt": "Western cowboy interior,
|
| 229 |
},
|
| 230 |
{
|
| 231 |
"name": "Matrix",
|
| 232 |
-
"prompt": "Futuristic cyberpunk interior,
|
| 233 |
}
|
| 234 |
]
|
| 235 |
|
|
@@ -238,7 +237,7 @@ STYLE_NAMES = list(styles.keys())
|
|
| 238 |
|
| 239 |
def apply_style(style_name):
|
| 240 |
if style_name in styles:
|
| 241 |
-
p = styles.get(style_name, "
|
| 242 |
return p
|
| 243 |
|
| 244 |
|
|
@@ -416,7 +415,7 @@ def process_image(
|
|
| 416 |
)
|
| 417 |
preprocess_time = time.time() - preprocess_start
|
| 418 |
if style_selection is not None or style_selection != "None":
|
| 419 |
-
prompt = "Photo from Pinterest of " + apply_style(style_selection) + " " + prompt
|
| 420 |
else:
|
| 421 |
prompt=str(get_prompt(prompt, a_prompt))
|
| 422 |
negative_prompt=str(n_prompt)
|
|
|
|
| 55 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 56 |
return self.model(image, **kwargs)
|
| 57 |
|
| 58 |
+
if gr.NO_RELOAD:
|
| 59 |
+
# Controlnet Normal
|
| 60 |
+
model_id = "lllyasviel/control_v11p_sd15_normalbae"
|
| 61 |
+
print("initializing controlnet")
|
| 62 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 63 |
+
model_id,
|
| 64 |
+
torch_dtype=torch.float16,
|
| 65 |
+
attn_implementation="flash_attention_2",
|
| 66 |
+
).to("cuda")
|
| 67 |
|
| 68 |
+
# Scheduler
|
| 69 |
+
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
| 70 |
+
"runwayml/stable-diffusion-v1-5",
|
| 71 |
+
solver_order=2,
|
| 72 |
+
subfolder="scheduler",
|
| 73 |
+
use_karras_sigmas=True,
|
| 74 |
+
final_sigmas_type="sigma_min",
|
| 75 |
+
algorithm_type="sde-dpmsolver++",
|
| 76 |
+
prediction_type="epsilon",
|
| 77 |
+
thresholding=False,
|
| 78 |
+
denoise_final=True,
|
| 79 |
+
device_map="cuda",
|
| 80 |
+
torch_dtype=torch.float16,
|
| 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 |
+
controlnet=controlnet,
|
| 97 |
+
scheduler=scheduler,
|
| 98 |
+
# vae=vae,
|
| 99 |
+
torch_dtype=torch.float16,
|
| 100 |
+
).to("cuda")
|
| 101 |
|
| 102 |
+
print("loading preprocessor")
|
| 103 |
+
preprocessor = Preprocessor()
|
| 104 |
+
preprocessor.load("NormalBae")
|
| 105 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
|
| 106 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
|
| 107 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
|
| 108 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
|
| 109 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
|
| 110 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
|
| 111 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
|
| 112 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
|
| 113 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
|
| 114 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
|
| 115 |
+
pipe.to("cuda")
|
| 116 |
|
| 117 |
+
print("---------------Loaded controlnet pipeline---------------")
|
| 118 |
+
torch.cuda.empty_cache()
|
| 119 |
+
gc.collect()
|
| 120 |
+
print(f"CUDA memory allocated: {torch.cuda.max_memory_allocated(device='cuda') / 1e9:.2f} GB")
|
| 121 |
+
print("Model Compiled!")
|
| 122 |
|
| 123 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 124 |
if randomize_seed:
|
|
|
|
| 134 |
# outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
|
| 135 |
|
| 136 |
def get_prompt(prompt, additional_prompt):
|
| 137 |
+
interior = "design-style interior designed (interior space),tungsten white balance,captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length"
|
| 138 |
default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 139 |
default2 = f"professional 3d model {prompt},octane render,highly detailed,volumetric,dramatic lighting,hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 140 |
randomize = get_additional_prompt()
|
|
|
|
| 172 |
},
|
| 173 |
{
|
| 174 |
"name": "Minimalistic",
|
| 175 |
+
"prompt": "Minimalist interior design,clean lines,neutral colors,uncluttered space,functional furniture,lots of natural light"
|
| 176 |
},
|
| 177 |
{
|
| 178 |
"name": "Boho",
|
| 179 |
+
"prompt": "Bohemian chic interior,eclectic mix of patterns and textures,vintage furniture,plants,woven textiles,warm earthy colors"
|
| 180 |
},
|
| 181 |
{
|
| 182 |
"name": "Farmhouse",
|
| 183 |
+
"prompt": "Modern farmhouse interior,rustic wood elements,shiplap walls,neutral color palette,industrial accents,cozy textiles"
|
| 184 |
},
|
| 185 |
{
|
| 186 |
"name": "Saudi Prince",
|
| 187 |
+
"prompt": "Opulent gold interior,luxurious ornate furniture,crystal chandeliers,rich fabrics,marble floors,intricate Arabic patterns"
|
| 188 |
},
|
| 189 |
{
|
| 190 |
"name": "Neoclassical",
|
| 191 |
+
"prompt": "Neoclassical interior design,elegant columns,ornate moldings,symmetrical layout,refined furniture,muted color palette"
|
| 192 |
},
|
| 193 |
{
|
| 194 |
"name": "Eclectic",
|
| 195 |
+
"prompt": "Eclectic interior design,mix of styles and eras,bold color combinations,diverse furniture pieces,unique art objects"
|
| 196 |
},
|
| 197 |
{
|
| 198 |
"name": "Parisian",
|
| 199 |
+
"prompt": "Parisian apartment interior,all-white color scheme,ornate moldings,herringbone wood floors,elegant furniture,large windows"
|
| 200 |
},
|
| 201 |
{
|
| 202 |
"name": "Hollywood",
|
| 203 |
+
"prompt": "Hollywood Regency interior,glamorous and luxurious,bold colors,mirrored surfaces,velvet upholstery,gold accents"
|
| 204 |
},
|
| 205 |
{
|
| 206 |
"name": "Scandinavian",
|
| 207 |
+
"prompt": "Scandinavian interior design,light wood tones,white walls,minimalist furniture,cozy textiles,hygge atmosphere"
|
| 208 |
},
|
| 209 |
{
|
| 210 |
"name": "Beach",
|
| 211 |
+
"prompt": "Coastal beach house interior,light blue and white color scheme,weathered wood,nautical accents,sheer curtains,ocean view"
|
| 212 |
},
|
| 213 |
{
|
| 214 |
"name": "Japanese",
|
| 215 |
+
"prompt": "Traditional Japanese interior,tatami mats,shoji screens,low furniture,zen garden view,minimalist decor,natural materials"
|
| 216 |
},
|
| 217 |
{
|
| 218 |
"name": "Midcentury Modern",
|
| 219 |
+
"prompt": "Mid-century modern interior,1950s-60s style furniture,organic shapes,warm wood tones,bold accent colors,large windows"
|
| 220 |
},
|
| 221 |
{
|
| 222 |
"name": "Retro Futurism",
|
|
|
|
| 224 |
},
|
| 225 |
{
|
| 226 |
"name": "Texan",
|
| 227 |
+
"prompt": "Western cowboy interior,rustic wood beams,leather furniture,cowhide rugs,antler chandeliers,southwestern patterns"
|
| 228 |
},
|
| 229 |
{
|
| 230 |
"name": "Matrix",
|
| 231 |
+
"prompt": "Futuristic cyberpunk interior,neon accent lighting,holographic plants,sleek black surfaces,advanced gaming setup,transparent screens,Blade Runner inspired decor,high-tech minimalist furniture"
|
| 232 |
}
|
| 233 |
]
|
| 234 |
|
|
|
|
| 237 |
|
| 238 |
def apply_style(style_name):
|
| 239 |
if style_name in styles:
|
| 240 |
+
p = styles.get(style_name, "none")
|
| 241 |
return p
|
| 242 |
|
| 243 |
|
|
|
|
| 415 |
)
|
| 416 |
preprocess_time = time.time() - preprocess_start
|
| 417 |
if style_selection is not None or style_selection != "None":
|
| 418 |
+
prompt = "Photo from Pinterest of " + apply_style(style_selection) + " " + prompt
|
| 419 |
else:
|
| 420 |
prompt=str(get_prompt(prompt, a_prompt))
|
| 421 |
negative_prompt=str(n_prompt)
|
local_app.py
CHANGED
|
@@ -11,10 +11,11 @@ import time
|
|
| 11 |
import gradio as gr
|
| 12 |
import numpy as np
|
| 13 |
# import spaces
|
| 14 |
-
|
| 15 |
import gc
|
| 16 |
import torch
|
| 17 |
from PIL import Image
|
|
|
|
| 18 |
from diffusers import (
|
| 19 |
ControlNetModel,
|
| 20 |
DPMSolverMultistepScheduler,
|
|
@@ -25,6 +26,7 @@ from controlnet_aux_local import NormalBaeDetector
|
|
| 25 |
|
| 26 |
MAX_SEED = np.iinfo(np.int32).max
|
| 27 |
API_KEY = os.environ.get("API_KEY", None)
|
|
|
|
| 28 |
# os.environ['HF_HOME'] = '/data/.huggingface'
|
| 29 |
|
| 30 |
print("CUDA version:", torch.version.cuda)
|
|
@@ -53,71 +55,70 @@ class Preprocessor:
|
|
| 53 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 54 |
return self.model(image, **kwargs)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
use_karras_sigmas=True,
|
| 73 |
-
final_sigmas_type="sigma_min",
|
| 74 |
-
algorithm_type="sde-dpmsolver++",
|
| 75 |
-
prediction_type="epsilon",
|
| 76 |
-
thresholding=False,
|
| 77 |
-
denoise_final=True,
|
| 78 |
-
device_map="cuda",
|
| 79 |
-
torch_dtype=torch.float16,
|
| 80 |
-
)
|
| 81 |
|
| 82 |
-
# Stable Diffusion Pipeline URL
|
| 83 |
-
# base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
|
| 84 |
-
base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
|
| 85 |
-
# vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
|
| 86 |
|
| 87 |
-
# print('loading vae')
|
| 88 |
-
# vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
|
| 89 |
-
# vae.to(memory_format=torch.channels_last)
|
| 90 |
|
| 91 |
-
print('loading pipe')
|
| 92 |
-
pipe = StableDiffusionControlNetPipeline.from_single_file(
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
).to("cuda")
|
| 100 |
|
| 101 |
-
print("loading preprocessor")
|
| 102 |
-
preprocessor = Preprocessor()
|
| 103 |
-
preprocessor.load("NormalBae")
|
| 104 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
|
| 105 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
|
| 106 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
|
| 107 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
|
| 108 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
|
| 109 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
|
| 110 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
|
| 111 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
|
| 112 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
|
| 113 |
-
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
|
| 114 |
-
pipe.to("cuda")
|
| 115 |
|
| 116 |
-
print("---------------Loaded controlnet pipeline---------------")
|
| 117 |
-
torch.cuda.empty_cache()
|
| 118 |
-
gc.collect()
|
| 119 |
-
print(f"CUDA memory allocated: {torch.cuda.max_memory_allocated(device='cuda') / 1e9:.2f} GB")
|
| 120 |
-
print("Model Compiled!")
|
| 121 |
|
| 122 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 123 |
if randomize_seed:
|
|
@@ -133,7 +134,7 @@ def get_additional_prompt():
|
|
| 133 |
# outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
|
| 134 |
|
| 135 |
def get_prompt(prompt, additional_prompt):
|
| 136 |
-
interior = "design-style interior designed (interior space), captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length
|
| 137 |
default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 138 |
default2 = f"professional 3d model {prompt},octane render,highly detailed,volumetric,dramatic lighting,hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 139 |
randomize = get_additional_prompt()
|
|
@@ -160,7 +161,7 @@ def get_prompt(prompt, additional_prompt):
|
|
| 160 |
prompt = f"boho chic"
|
| 161 |
# print(f"-------------{preset}-------------")
|
| 162 |
else:
|
| 163 |
-
prompt = f"Photo from Pinterest of {prompt}
|
| 164 |
# prompt = default2
|
| 165 |
return f"{prompt} f{additional_prompt}"
|
| 166 |
|
|
@@ -171,51 +172,51 @@ style_list = [
|
|
| 171 |
},
|
| 172 |
{
|
| 173 |
"name": "Minimalistic",
|
| 174 |
-
"prompt": "Minimalist interior design,
|
| 175 |
},
|
| 176 |
{
|
| 177 |
"name": "Boho",
|
| 178 |
-
"prompt": "Bohemian chic interior,
|
| 179 |
},
|
| 180 |
{
|
| 181 |
"name": "Farmhouse",
|
| 182 |
-
"prompt": "Modern farmhouse interior,
|
| 183 |
},
|
| 184 |
{
|
| 185 |
"name": "Saudi Prince",
|
| 186 |
-
"prompt": "Opulent gold interior,
|
| 187 |
},
|
| 188 |
{
|
| 189 |
"name": "Neoclassical",
|
| 190 |
-
"prompt": "Neoclassical interior design,
|
| 191 |
},
|
| 192 |
{
|
| 193 |
"name": "Eclectic",
|
| 194 |
-
"prompt": "Eclectic interior design,
|
| 195 |
},
|
| 196 |
{
|
| 197 |
"name": "Parisian",
|
| 198 |
-
"prompt": "Parisian apartment interior,
|
| 199 |
},
|
| 200 |
{
|
| 201 |
"name": "Hollywood",
|
| 202 |
-
"prompt": "Hollywood Regency interior,
|
| 203 |
},
|
| 204 |
{
|
| 205 |
"name": "Scandinavian",
|
| 206 |
-
"prompt": "Scandinavian interior design,
|
| 207 |
},
|
| 208 |
{
|
| 209 |
"name": "Beach",
|
| 210 |
-
"prompt": "Coastal beach house interior,
|
| 211 |
},
|
| 212 |
{
|
| 213 |
"name": "Japanese",
|
| 214 |
-
"prompt": "Traditional Japanese interior,
|
| 215 |
},
|
| 216 |
{
|
| 217 |
"name": "Midcentury Modern",
|
| 218 |
-
"prompt": "Mid-century modern interior,
|
| 219 |
},
|
| 220 |
{
|
| 221 |
"name": "Retro Futurism",
|
|
@@ -223,11 +224,11 @@ style_list = [
|
|
| 223 |
},
|
| 224 |
{
|
| 225 |
"name": "Texan",
|
| 226 |
-
"prompt": "Western cowboy interior,
|
| 227 |
},
|
| 228 |
{
|
| 229 |
"name": "Matrix",
|
| 230 |
-
"prompt": "Futuristic cyberpunk interior,
|
| 231 |
}
|
| 232 |
]
|
| 233 |
|
|
@@ -236,7 +237,7 @@ STYLE_NAMES = list(styles.keys())
|
|
| 236 |
|
| 237 |
def apply_style(style_name):
|
| 238 |
if style_name in styles:
|
| 239 |
-
p = styles.get(style_name, "
|
| 240 |
return p
|
| 241 |
|
| 242 |
|
|
@@ -415,9 +416,9 @@ def process_image(
|
|
| 415 |
)
|
| 416 |
preprocess_time = time.time() - preprocess_start
|
| 417 |
if style_selection is not None or style_selection != "None":
|
| 418 |
-
prompt = "Photo from Pinterest of " + apply_style(style_selection) + " " + prompt
|
| 419 |
else:
|
| 420 |
-
prompt=str(get_prompt(prompt
|
| 421 |
negative_prompt=str(n_prompt)
|
| 422 |
print(prompt)
|
| 423 |
print(f"\n-------------------------Preprocess done in: {preprocess_time:.2f} seconds-------------------------")
|
|
@@ -434,6 +435,28 @@ def process_image(
|
|
| 434 |
print(f"\n-------------------------Inference done in: {time.time() - start:.2f} seconds-------------------------")
|
| 435 |
# torch.cuda.synchronize()
|
| 436 |
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
return results
|
| 438 |
|
| 439 |
if prod:
|
|
|
|
| 11 |
import gradio as gr
|
| 12 |
import numpy as np
|
| 13 |
# import spaces
|
| 14 |
+
import imageio
|
| 15 |
import gc
|
| 16 |
import torch
|
| 17 |
from PIL import Image
|
| 18 |
+
from huggingface_hub import HfApi
|
| 19 |
from diffusers import (
|
| 20 |
ControlNetModel,
|
| 21 |
DPMSolverMultistepScheduler,
|
|
|
|
| 26 |
|
| 27 |
MAX_SEED = np.iinfo(np.int32).max
|
| 28 |
API_KEY = os.environ.get("API_KEY", None)
|
| 29 |
+
api = HfApi()
|
| 30 |
# os.environ['HF_HOME'] = '/data/.huggingface'
|
| 31 |
|
| 32 |
print("CUDA version:", torch.version.cuda)
|
|
|
|
| 55 |
def __call__(self, image: Image.Image, **kwargs) -> Image.Image:
|
| 56 |
return self.model(image, **kwargs)
|
| 57 |
|
| 58 |
+
if gr.NO_RELOAD:
|
| 59 |
+
# Controlnet Normal
|
| 60 |
+
model_id = "lllyasviel/control_v11p_sd15_normalbae"
|
| 61 |
+
print("initializing controlnet")
|
| 62 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 63 |
+
model_id,
|
| 64 |
+
torch_dtype=torch.float16,
|
| 65 |
+
attn_implementation="flash_attention_2",
|
| 66 |
+
).to("cuda")
|
| 67 |
|
| 68 |
+
# Scheduler
|
| 69 |
+
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
| 70 |
+
"runwayml/stable-diffusion-v1-5",
|
| 71 |
+
solver_order=2,
|
| 72 |
+
subfolder="scheduler",
|
| 73 |
+
use_karras_sigmas=True,
|
| 74 |
+
final_sigmas_type="sigma_min",
|
| 75 |
+
algorithm_type="sde-dpmsolver++",
|
| 76 |
+
prediction_type="epsilon",
|
| 77 |
+
thresholding=False,
|
| 78 |
+
denoise_final=True,
|
| 79 |
+
device_map="cuda",
|
| 80 |
+
torch_dtype=torch.float16,
|
| 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 |
+
controlnet=controlnet,
|
| 97 |
+
scheduler=scheduler,
|
| 98 |
+
# vae=vae,
|
| 99 |
+
torch_dtype=torch.float16,
|
| 100 |
+
).to("cuda")
|
| 101 |
|
| 102 |
+
print("loading preprocessor")
|
| 103 |
+
preprocessor = Preprocessor()
|
| 104 |
+
preprocessor.load("NormalBae")
|
| 105 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
|
| 106 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
|
| 107 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
|
| 108 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
|
| 109 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
|
| 110 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
|
| 111 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
|
| 112 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
|
| 113 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
|
| 114 |
+
# pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
|
| 115 |
+
pipe.to("cuda")
|
| 116 |
|
| 117 |
+
print("---------------Loaded controlnet pipeline---------------")
|
| 118 |
+
torch.cuda.empty_cache()
|
| 119 |
+
gc.collect()
|
| 120 |
+
print(f"CUDA memory allocated: {torch.cuda.max_memory_allocated(device='cuda') / 1e9:.2f} GB")
|
| 121 |
+
print("Model Compiled!")
|
| 122 |
|
| 123 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 124 |
if randomize_seed:
|
|
|
|
| 134 |
# outfit = ["schoolgirl outfit", "playboy outfit", "red dress", "gala dress", "cheerleader outfit", "nurse outfit", "Kimono"]
|
| 135 |
|
| 136 |
def get_prompt(prompt, additional_prompt):
|
| 137 |
+
interior = "design-style interior designed (interior space),tungsten white balance,captured with a DSLR camera using f/10 aperture, 1/60 sec shutter speed, ISO 400, 20mm focal length"
|
| 138 |
default = "hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 139 |
default2 = f"professional 3d model {prompt},octane render,highly detailed,volumetric,dramatic lighting,hyperrealistic photography,extremely detailed,(intricate details),unity 8k wallpaper,ultra detailed"
|
| 140 |
randomize = get_additional_prompt()
|
|
|
|
| 161 |
prompt = f"boho chic"
|
| 162 |
# print(f"-------------{preset}-------------")
|
| 163 |
else:
|
| 164 |
+
prompt = f"Photo from Pinterest of {prompt}{interior}"
|
| 165 |
# prompt = default2
|
| 166 |
return f"{prompt} f{additional_prompt}"
|
| 167 |
|
|
|
|
| 172 |
},
|
| 173 |
{
|
| 174 |
"name": "Minimalistic",
|
| 175 |
+
"prompt": "Minimalist interior design,clean lines,neutral colors,uncluttered space,functional furniture,lots of natural light"
|
| 176 |
},
|
| 177 |
{
|
| 178 |
"name": "Boho",
|
| 179 |
+
"prompt": "Bohemian chic interior,eclectic mix of patterns and textures,vintage furniture,plants,woven textiles,warm earthy colors"
|
| 180 |
},
|
| 181 |
{
|
| 182 |
"name": "Farmhouse",
|
| 183 |
+
"prompt": "Modern farmhouse interior,rustic wood elements,shiplap walls,neutral color palette,industrial accents,cozy textiles"
|
| 184 |
},
|
| 185 |
{
|
| 186 |
"name": "Saudi Prince",
|
| 187 |
+
"prompt": "Opulent gold interior,luxurious ornate furniture,crystal chandeliers,rich fabrics,marble floors,intricate Arabic patterns"
|
| 188 |
},
|
| 189 |
{
|
| 190 |
"name": "Neoclassical",
|
| 191 |
+
"prompt": "Neoclassical interior design,elegant columns,ornate moldings,symmetrical layout,refined furniture,muted color palette"
|
| 192 |
},
|
| 193 |
{
|
| 194 |
"name": "Eclectic",
|
| 195 |
+
"prompt": "Eclectic interior design,mix of styles and eras,bold color combinations,diverse furniture pieces,unique art objects"
|
| 196 |
},
|
| 197 |
{
|
| 198 |
"name": "Parisian",
|
| 199 |
+
"prompt": "Parisian apartment interior,all-white color scheme,ornate moldings,herringbone wood floors,elegant furniture,large windows"
|
| 200 |
},
|
| 201 |
{
|
| 202 |
"name": "Hollywood",
|
| 203 |
+
"prompt": "Hollywood Regency interior,glamorous and luxurious,bold colors,mirrored surfaces,velvet upholstery,gold accents"
|
| 204 |
},
|
| 205 |
{
|
| 206 |
"name": "Scandinavian",
|
| 207 |
+
"prompt": "Scandinavian interior design,light wood tones,white walls,minimalist furniture,cozy textiles,hygge atmosphere"
|
| 208 |
},
|
| 209 |
{
|
| 210 |
"name": "Beach",
|
| 211 |
+
"prompt": "Coastal beach house interior,light blue and white color scheme,weathered wood,nautical accents,sheer curtains,ocean view"
|
| 212 |
},
|
| 213 |
{
|
| 214 |
"name": "Japanese",
|
| 215 |
+
"prompt": "Traditional Japanese interior,tatami mats,shoji screens,low furniture,zen garden view,minimalist decor,natural materials"
|
| 216 |
},
|
| 217 |
{
|
| 218 |
"name": "Midcentury Modern",
|
| 219 |
+
"prompt": "Mid-century modern interior,1950s-60s style furniture,organic shapes,warm wood tones,bold accent colors,large windows"
|
| 220 |
},
|
| 221 |
{
|
| 222 |
"name": "Retro Futurism",
|
|
|
|
| 224 |
},
|
| 225 |
{
|
| 226 |
"name": "Texan",
|
| 227 |
+
"prompt": "Western cowboy interior,rustic wood beams,leather furniture,cowhide rugs,antler chandeliers,southwestern patterns"
|
| 228 |
},
|
| 229 |
{
|
| 230 |
"name": "Matrix",
|
| 231 |
+
"prompt": "Futuristic cyberpunk interior,neon accent lighting,holographic plants,sleek black surfaces,advanced gaming setup,transparent screens,Blade Runner inspired decor,high-tech minimalist furniture"
|
| 232 |
}
|
| 233 |
]
|
| 234 |
|
|
|
|
| 237 |
|
| 238 |
def apply_style(style_name):
|
| 239 |
if style_name in styles:
|
| 240 |
+
p = styles.get(style_name, "none")
|
| 241 |
return p
|
| 242 |
|
| 243 |
|
|
|
|
| 416 |
)
|
| 417 |
preprocess_time = time.time() - preprocess_start
|
| 418 |
if style_selection is not None or style_selection != "None":
|
| 419 |
+
prompt = "Photo from Pinterest of " + apply_style(style_selection) + " " + prompt
|
| 420 |
else:
|
| 421 |
+
prompt=str(get_prompt(prompt))
|
| 422 |
negative_prompt=str(n_prompt)
|
| 423 |
print(prompt)
|
| 424 |
print(f"\n-------------------------Preprocess done in: {preprocess_time:.2f} seconds-------------------------")
|
|
|
|
| 435 |
print(f"\n-------------------------Inference done in: {time.time() - start:.2f} seconds-------------------------")
|
| 436 |
# torch.cuda.synchronize()
|
| 437 |
torch.cuda.empty_cache()
|
| 438 |
+
# # upload block
|
| 439 |
+
# timestamp = int(time.time())
|
| 440 |
+
# img_path = f"{timestamp}.jpg"
|
| 441 |
+
# results_path = f"{timestamp}_out.jpg"
|
| 442 |
+
# imageio.imsave(img_path, image)
|
| 443 |
+
# imageio.imsave(results_path, results)
|
| 444 |
+
# api.upload_file(
|
| 445 |
+
# path_or_fileobj=img_path,
|
| 446 |
+
# path_in_repo=img_path,
|
| 447 |
+
# repo_id="broyang/interior-ai-outputs",
|
| 448 |
+
# repo_type="dataset",
|
| 449 |
+
# token=API_KEY,
|
| 450 |
+
# run_as_future=True,
|
| 451 |
+
# )
|
| 452 |
+
# api.upload_file(
|
| 453 |
+
# path_or_fileobj=results_path,
|
| 454 |
+
# path_in_repo=results_path,
|
| 455 |
+
# repo_id="broyang/interior-ai-outputs",
|
| 456 |
+
# repo_type="dataset",
|
| 457 |
+
# token=API_KEY,
|
| 458 |
+
# run_as_future=True,
|
| 459 |
+
# )
|
| 460 |
return results
|
| 461 |
|
| 462 |
if prod:
|