Skip to content

Commit 4d4c863

Browse files
authored
Merge pull request #342 from mrhan1993:dev
Dev
2 parents d59fdc4 + 122f16c commit 4d4c863

39 files changed

+1113
-249
lines changed

fooocus_api_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = '0.4.0.7'
1+
version = '0.4.1.0'

fooocusapi/models/common/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class PerformanceSelection(str, Enum):
2121
quality = 'Quality'
2222
extreme_speed = 'Extreme Speed'
2323
lightning = 'Lightning'
24+
hyper_sd = 'Hyper-SD'
2425

2526

2627
class Lora(BaseModel):

fooocusapi/models/common/image_meta.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ImageMeta(BaseModel):
4242
guidance_scale: float
4343
sharpness: float
4444
steps: int
45+
vae_name: str
4546

4647
version: str = version
4748

@@ -101,6 +102,7 @@ def image_parse(
101102
guidance_scale=req_param.guidance_scale,
102103
sharpness=req_param.sharpness,
103104
steps=-1,
105+
vae_name=req_param.advanced_params.vae_name,
104106
version=version
105107
)
106108
if meta.metadata_scheme not in ["fooocus", "a111"]:

fooocusapi/models/common/requests.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
default_inpaint_engine_version,
2222
default_overwrite_switch,
2323
default_cfg_tsnr,
24-
default_sample_sharpness
24+
default_sample_sharpness,
25+
default_vae,
26+
default_clip_skip
2527
)
2628

29+
from modules.flags import clip_skip_max
30+
2731
from fooocusapi.models.common.base import (
2832
PerformanceSelection,
2933
Lora,
@@ -50,6 +54,7 @@ class AdvancedParams(BaseModel):
5054
adm_scaler_negative: float = Field(0.8, description="Negative ADM Guidance Scaler", ge=0.1, le=3.0)
5155
adm_scaler_end: float = Field(0.3, description="ADM Guidance End At Step", ge=0.0, le=1.0)
5256
adaptive_cfg: float = Field(default_cfg_tsnr, description="CFG Mimicking from TSNR", ge=1.0, le=30.0)
57+
clip_skip: int = Field(default_clip_skip, description="Clip Skip", ge=1, le=clip_skip_max)
5358
sampler_name: str = Field(default_sampler, description="Sampler")
5459
scheduler_name: str = Field(default_scheduler, description="Scheduler")
5560
overwrite_step: int = Field(default_overwrite_step, description="Forced Overwrite of Sampling Step", ge=-1, le=200)
@@ -79,6 +84,8 @@ class AdvancedParams(BaseModel):
7984
inpaint_mask_upload_checkbox: bool = Field(False, description="Upload Mask")
8085
invert_mask_checkbox: bool = Field(False, description="Invert Mask")
8186
inpaint_erode_or_dilate: int = Field(0, description="Mask Erode or Dilate", ge=-64, le=64)
87+
black_out_nsfw: bool = Field(False, description="Block out NSFW")
88+
vae_name: str = Field(default_vae, description="VAE name")
8289

8390

8491
class CommonRequest(BaseModel):

fooocusapi/worker.py

+84-30
Large diffs are not rendered by default.

repositories/Fooocus/args_manager.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
args_parser.parser.add_argument("--disable-preset-download", action='store_true',
3232
help="Disables downloading models for presets", default=False)
3333

34+
args_parser.parser.add_argument("--enable-describe-uov-image", action='store_true',
35+
help="Disables automatic description of uov images when prompt is empty", default=False)
36+
3437
args_parser.parser.add_argument("--always-download-new-model", action='store_true',
3538
help="Always download newer models ", default=False)
3639

repositories/Fooocus/extras/censor.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
3+
import numpy as np
4+
import torch
5+
from transformers import CLIPConfig, CLIPImageProcessor
6+
7+
import ldm_patched.modules.model_management as model_management
8+
import modules.config
9+
from extras.safety_checker.models.safety_checker import StableDiffusionSafetyChecker
10+
from ldm_patched.modules.model_patcher import ModelPatcher
11+
12+
safety_checker_repo_root = os.path.join(os.path.dirname(__file__), 'safety_checker')
13+
config_path = os.path.join(safety_checker_repo_root, "configs", "config.json")
14+
preprocessor_config_path = os.path.join(safety_checker_repo_root, "configs", "preprocessor_config.json")
15+
16+
17+
class Censor:
18+
def __init__(self):
19+
self.safety_checker_model: ModelPatcher | None = None
20+
self.clip_image_processor: CLIPImageProcessor | None = None
21+
self.load_device = torch.device('cpu')
22+
self.offload_device = torch.device('cpu')
23+
24+
def init(self):
25+
if self.safety_checker_model is None and self.clip_image_processor is None:
26+
safety_checker_model = modules.config.downloading_safety_checker_model()
27+
self.clip_image_processor = CLIPImageProcessor.from_json_file(preprocessor_config_path)
28+
clip_config = CLIPConfig.from_json_file(config_path)
29+
model = StableDiffusionSafetyChecker.from_pretrained(safety_checker_model, config=clip_config)
30+
model.eval()
31+
32+
self.load_device = model_management.text_encoder_device()
33+
self.offload_device = model_management.text_encoder_offload_device()
34+
35+
model.to(self.offload_device)
36+
37+
self.safety_checker_model = ModelPatcher(model, load_device=self.load_device, offload_device=self.offload_device)
38+
39+
def censor(self, images: list | np.ndarray) -> list | np.ndarray:
40+
self.init()
41+
model_management.load_model_gpu(self.safety_checker_model)
42+
43+
single = False
44+
if not isinstance(images, list) or isinstance(images, np.ndarray):
45+
images = [images]
46+
single = True
47+
48+
safety_checker_input = self.clip_image_processor(images, return_tensors="pt")
49+
safety_checker_input.to(device=self.load_device)
50+
checked_images, has_nsfw_concept = self.safety_checker_model.model(images=images,
51+
clip_input=safety_checker_input.pixel_values)
52+
checked_images = [image.astype(np.uint8) for image in checked_images]
53+
54+
if single:
55+
checked_images = checked_images[0]
56+
57+
return checked_images
58+
59+
60+
default_censor = Censor().censor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"_name_or_path": "clip-vit-large-patch14/",
3+
"architectures": [
4+
"SafetyChecker"
5+
],
6+
"initializer_factor": 1.0,
7+
"logit_scale_init_value": 2.6592,
8+
"model_type": "clip",
9+
"projection_dim": 768,
10+
"text_config": {
11+
"_name_or_path": "",
12+
"add_cross_attention": false,
13+
"architectures": null,
14+
"attention_dropout": 0.0,
15+
"bad_words_ids": null,
16+
"bos_token_id": 0,
17+
"chunk_size_feed_forward": 0,
18+
"cross_attention_hidden_size": null,
19+
"decoder_start_token_id": null,
20+
"diversity_penalty": 0.0,
21+
"do_sample": false,
22+
"dropout": 0.0,
23+
"early_stopping": false,
24+
"encoder_no_repeat_ngram_size": 0,
25+
"eos_token_id": 2,
26+
"exponential_decay_length_penalty": null,
27+
"finetuning_task": null,
28+
"forced_bos_token_id": null,
29+
"forced_eos_token_id": null,
30+
"hidden_act": "quick_gelu",
31+
"hidden_size": 768,
32+
"id2label": {
33+
"0": "LABEL_0",
34+
"1": "LABEL_1"
35+
},
36+
"initializer_factor": 1.0,
37+
"initializer_range": 0.02,
38+
"intermediate_size": 3072,
39+
"is_decoder": false,
40+
"is_encoder_decoder": false,
41+
"label2id": {
42+
"LABEL_0": 0,
43+
"LABEL_1": 1
44+
},
45+
"layer_norm_eps": 1e-05,
46+
"length_penalty": 1.0,
47+
"max_length": 20,
48+
"max_position_embeddings": 77,
49+
"min_length": 0,
50+
"model_type": "clip_text_model",
51+
"no_repeat_ngram_size": 0,
52+
"num_attention_heads": 12,
53+
"num_beam_groups": 1,
54+
"num_beams": 1,
55+
"num_hidden_layers": 12,
56+
"num_return_sequences": 1,
57+
"output_attentions": false,
58+
"output_hidden_states": false,
59+
"output_scores": false,
60+
"pad_token_id": 1,
61+
"prefix": null,
62+
"problem_type": null,
63+
"pruned_heads": {},
64+
"remove_invalid_values": false,
65+
"repetition_penalty": 1.0,
66+
"return_dict": true,
67+
"return_dict_in_generate": false,
68+
"sep_token_id": null,
69+
"task_specific_params": null,
70+
"temperature": 1.0,
71+
"tie_encoder_decoder": false,
72+
"tie_word_embeddings": true,
73+
"tokenizer_class": null,
74+
"top_k": 50,
75+
"top_p": 1.0,
76+
"torch_dtype": null,
77+
"torchscript": false,
78+
"transformers_version": "4.21.0.dev0",
79+
"typical_p": 1.0,
80+
"use_bfloat16": false,
81+
"vocab_size": 49408
82+
},
83+
"text_config_dict": {
84+
"hidden_size": 768,
85+
"intermediate_size": 3072,
86+
"num_attention_heads": 12,
87+
"num_hidden_layers": 12
88+
},
89+
"torch_dtype": "float32",
90+
"transformers_version": null,
91+
"vision_config": {
92+
"_name_or_path": "",
93+
"add_cross_attention": false,
94+
"architectures": null,
95+
"attention_dropout": 0.0,
96+
"bad_words_ids": null,
97+
"bos_token_id": null,
98+
"chunk_size_feed_forward": 0,
99+
"cross_attention_hidden_size": null,
100+
"decoder_start_token_id": null,
101+
"diversity_penalty": 0.0,
102+
"do_sample": false,
103+
"dropout": 0.0,
104+
"early_stopping": false,
105+
"encoder_no_repeat_ngram_size": 0,
106+
"eos_token_id": null,
107+
"exponential_decay_length_penalty": null,
108+
"finetuning_task": null,
109+
"forced_bos_token_id": null,
110+
"forced_eos_token_id": null,
111+
"hidden_act": "quick_gelu",
112+
"hidden_size": 1024,
113+
"id2label": {
114+
"0": "LABEL_0",
115+
"1": "LABEL_1"
116+
},
117+
"image_size": 224,
118+
"initializer_factor": 1.0,
119+
"initializer_range": 0.02,
120+
"intermediate_size": 4096,
121+
"is_decoder": false,
122+
"is_encoder_decoder": false,
123+
"label2id": {
124+
"LABEL_0": 0,
125+
"LABEL_1": 1
126+
},
127+
"layer_norm_eps": 1e-05,
128+
"length_penalty": 1.0,
129+
"max_length": 20,
130+
"min_length": 0,
131+
"model_type": "clip_vision_model",
132+
"no_repeat_ngram_size": 0,
133+
"num_attention_heads": 16,
134+
"num_beam_groups": 1,
135+
"num_beams": 1,
136+
"num_hidden_layers": 24,
137+
"num_return_sequences": 1,
138+
"output_attentions": false,
139+
"output_hidden_states": false,
140+
"output_scores": false,
141+
"pad_token_id": null,
142+
"patch_size": 14,
143+
"prefix": null,
144+
"problem_type": null,
145+
"pruned_heads": {},
146+
"remove_invalid_values": false,
147+
"repetition_penalty": 1.0,
148+
"return_dict": true,
149+
"return_dict_in_generate": false,
150+
"sep_token_id": null,
151+
"task_specific_params": null,
152+
"temperature": 1.0,
153+
"tie_encoder_decoder": false,
154+
"tie_word_embeddings": true,
155+
"tokenizer_class": null,
156+
"top_k": 50,
157+
"top_p": 1.0,
158+
"torch_dtype": null,
159+
"torchscript": false,
160+
"transformers_version": "4.21.0.dev0",
161+
"typical_p": 1.0,
162+
"use_bfloat16": false
163+
},
164+
"vision_config_dict": {
165+
"hidden_size": 1024,
166+
"intermediate_size": 4096,
167+
"num_attention_heads": 16,
168+
"num_hidden_layers": 24,
169+
"patch_size": 14
170+
}
171+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"crop_size": 224,
3+
"do_center_crop": true,
4+
"do_convert_rgb": true,
5+
"do_normalize": true,
6+
"do_resize": true,
7+
"feature_extractor_type": "CLIPFeatureExtractor",
8+
"image_mean": [
9+
0.48145466,
10+
0.4578275,
11+
0.40821073
12+
],
13+
"image_std": [
14+
0.26862954,
15+
0.26130258,
16+
0.27577711
17+
],
18+
"resample": 3,
19+
"size": 224
20+
}

0 commit comments

Comments
 (0)