File size: 4,698 Bytes
65d64be
1e250ff
d179c4c
23f4f95
d179c4c
23f4f95
9edebae
 
 
 
 
 
 
c70346f
9edebae
d179c4c
 
9edebae
98afd85
 
 
 
 
 
1e250ff
7a7cda5
d179c4c
 
7a7cda5
d179c4c
 
 
 
 
 
 
 
 
7a7cda5
 
d179c4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e250ff
7a7cda5
23f4f95
65d64be
1e250ff
7a7cda5
f70898c
d179c4c
98afd85
d179c4c
 
98afd85
7a7cda5
4719a50
d179c4c
4719a50
d179c4c
2f072bf
65d64be
23f4f95
 
 
 
 
 
 
 
9edebae
1e250ff
 
98afd85
 
9edebae
5e223b0
23f4f95
9edebae
23f4f95
 
4719a50
9edebae
4719a50
9edebae
2f072bf
23f4f95
7a7cda5
9edebae
7a7cda5
9edebae
 
4719a50
9edebae
 
2f072bf
9edebae
6c1122d
9edebae
 
 
 
 
 
 
c70346f
9edebae
7a7cda5
98afd85
 
 
f70898c
 
23f4f95
 
ca2f5d2
6c1122d
ca2f5d2
232c234
23f4f95
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import os
from importlib import import_module
from importlib.util import find_spec
from types import SimpleNamespace
from warnings import filterwarnings

from diffusers import (
    DDIMScheduler,
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    PNDMScheduler,
    UniPCMultistepScheduler,
)
from diffusers.utils import logging as diffusers_logging
from transformers import logging as transformers_logging

from .pipelines import (
    CustomStableDiffusionControlNetImg2ImgPipeline,
    CustomStableDiffusionControlNetPipeline,
    CustomStableDiffusionImg2ImgPipeline,
    CustomStableDiffusionPipeline,
)

# Improved GPU handling and progress bars; set before importing spaces
os.environ["ZEROGPU_V2"] = "1"

# Errors if enabled and not installed
if find_spec("hf_transfer"):
    os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"

filterwarnings("ignore", category=FutureWarning, module="diffusers")
filterwarnings("ignore", category=FutureWarning, module="transformers")

diffusers_logging.set_verbosity_error()
transformers_logging.set_verbosity_error()

# Standard Stable Diffusion 1.5 file structure
sd_files = [
    "feature_extractor/preprocessor_config.json",
    "safety_checker/config.json",
    "scheduler/scheduler_config.json",
    "text_encoder/config.json",
    "text_encoder/model.fp16.safetensors",
    "tokenizer/merges.txt",
    "tokenizer/special_tokens_map.json",
    "tokenizer/tokenizer_config.json",
    "tokenizer/vocab.json",
    "unet/config.json",
    "unet/diffusion_pytorch_model.fp16.safetensors",
    "vae/config.json",
    "vae/diffusion_pytorch_model.fp16.safetensors",
    "model_index.json",
]

# Using namespace instead of dataclass for simplicity
Config = SimpleNamespace(
    HF_TOKEN=os.environ.get("HF_TOKEN", None),
    ZERO_GPU=import_module("spaces").config.Config.zero_gpu,
    # TODO: fix model config redundancy
    HF_MODELS={
        # downloaded on startup
        "ai-forever/Real-ESRGAN": ["RealESRGAN_x2.pth", "RealESRGAN_x4.pth"],
        "cyberdelia/CyberRealistic": ["CyberRealistic_V5_FP16.safetensors"],
        "fluently/Fluently-v4": ["Fluently-v4.safetensors"],
        "lllyasviel/control_v11p_sd15_canny": ["diffusion_pytorch_model.fp16.safetensors"],
        "Lykon/dreamshaper-8": [*sd_files],
        "s6yx/ReV_Animated": ["rev_1.2.2/rev_1.2.2-fp16.safetensors"],
        "SG161222/Realistic_Vision_V5.1_noVAE": ["Realistic_Vision_V5.1_fp16-no-ema.safetensors"],
        "stable-diffusion-v1-5/stable-diffusion-v1-5": [*sd_files],
        "XpucT/Deliberate": ["Deliberate_v6.safetensors"],
        "XpucT/Reliberate": ["Reliberate_v3.safetensors"],
    },
    MONO_FONTS=["monospace"],
    SANS_FONTS=[
        "sans-serif",
        "Apple Color Emoji",
        "Segoe UI Emoji",
        "Segoe UI Symbol",
        "Noto Color Emoji",
    ],
    PIPELINES={
        "txt2img": CustomStableDiffusionPipeline,
        "img2img": CustomStableDiffusionImg2ImgPipeline,
        "controlnet_txt2img": CustomStableDiffusionControlNetPipeline,
        "controlnet_img2img": CustomStableDiffusionControlNetImg2ImgPipeline,
    },
    MODEL="XpucT/Reliberate",
    MODELS=[
        "cyberdelia/CyberRealistic",
        "fluently/Fluently-v4",
        "Lykon/dreamshaper-8",
        "s6yx/ReV_Animated",
        "SG161222/Realistic_Vision_V5.1_noVAE",
        "stable-diffusion-v1-5/stable-diffusion-v1-5",
        "XpucT/Deliberate",
        "XpucT/Reliberate",
    ],
    # Single-file model weights
    MODEL_CHECKPOINTS={
        # keep keys lowercase for case-insensitive matching in the loader
        "cyberdelia/cyberrealistic": "CyberRealistic_V5_FP16.safetensors",
        "fluently/fluently-v4": "Fluently-v4.safetensors",
        "s6yx/rev_animated": "rev_1.2.2/rev_1.2.2-fp16.safetensors",
        "sg161222/realistic_vision_v5.1_novae": "Realistic_Vision_V5.1_fp16-no-ema.safetensors",
        "xpuct/deliberate": "Deliberate_v6.safetensors",
        "xpuct/reliberate": "Reliberate_v3.safetensors",
    },
    SCHEDULER="UniPC 2M",
    SCHEDULERS={
        "DDIM": DDIMScheduler,
        "DEIS 2M": DEISMultistepScheduler,
        "DPM++ 2M": DPMSolverMultistepScheduler,
        "Euler": EulerDiscreteScheduler,
        "Euler a": EulerAncestralDiscreteScheduler,
        "PNDM": PNDMScheduler,
        "UniPC 2M": UniPCMultistepScheduler,
    },
    ANNOTATOR="canny",
    ANNOTATORS={
        "canny": "lllyasviel/control_v11p_sd15_canny",
    },
    WIDTH=512,
    HEIGHT=512,
    NUM_IMAGES=1,
    SEED=-1,
    GUIDANCE_SCALE=6,
    INFERENCE_STEPS=40,
    DENOISING_STRENGTH=0.8,
    DEEPCACHE_INTERVAL=1,
    SCALE=1,
    SCALES=[1, 2, 4],
)