Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,22 @@ Demo for the WaifuDiffusion tagger models
|
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 17 |
|
| 18 |
# Dataset v3 series of models:
|
|
|
|
|
|
|
| 19 |
VIT_MODEL_DSV3_REPO = "ura23/wd-vit-tagger-v3"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Files to download from the repos
|
| 22 |
MODEL_FILENAME = "model.onnx"
|
|
@@ -108,64 +123,214 @@ def main():
|
|
| 108 |
predictor = Predictor()
|
| 109 |
|
| 110 |
model_repos = [
|
|
|
|
|
|
|
| 111 |
VIT_MODEL_DSV3_REPO,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
]
|
| 113 |
|
| 114 |
-
predefined_tags = ["
|
|
|
|
| 115 |
"2024",
|
| 116 |
-
"2020",
|
| 117 |
"2023",
|
| 118 |
-
"2025"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
with gr.Blocks(title=TITLE) as demo:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
with gr.Blocks(title=TITLE) as demo:
|
| 125 |
-
gr.Markdown(f"<h1 style='text-align: center;'>{TITLE}</h1>")
|
| 126 |
-
gr.Markdown(DESCRIPTION)
|
| 127 |
-
|
| 128 |
-
with gr.Row():
|
| 129 |
-
with gr.Column():
|
| 130 |
-
submit = gr.Button(
|
| 131 |
-
value="Process Images", variant="primary"
|
| 132 |
-
)
|
| 133 |
-
|
| 134 |
-
image_files = gr.File(
|
| 135 |
-
file_types=["image"], label="Upload Images", file_count="multiple",
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
# Wrap the model selection and sliders in an Accordion
|
| 139 |
-
with gr.Accordion("Advanced Settings", open=False): # Collapsible by default
|
| 140 |
-
model_repo = gr.Dropdown(
|
| 141 |
-
model_repos,
|
| 142 |
-
value=VIT_MODEL_DSV3_REPO,
|
| 143 |
-
label="Select Model",
|
| 144 |
-
)
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
general_val = 0.25 if isinstance(args.score_general_threshold, bool) else float(args.score_general_threshold)
|
| 149 |
-
char_val = 1.0 if isinstance(args.score_character_threshold, bool) else float(args.score_character_threshold)
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
)
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
)
|
| 158 |
-
|
| 159 |
-
filter_tags = gr.Textbox(
|
| 160 |
-
value=", ".join(predefined_tags),
|
| 161 |
-
label="Filter Tags (comma-separated)",
|
| 162 |
-
placeholder="Add tags to filter out (e.g., winter, red, from above)",
|
| 163 |
-
lines=9
|
| 164 |
)
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
def process_images(files, model_repo, general_thresh, character_thresh, filter_tags):
|
| 171 |
images = [Image.open(file.name) for file in files]
|
|
|
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 17 |
|
| 18 |
# Dataset v3 series of models:
|
| 19 |
+
SWINV2_MODEL_DSV3_REPO = "SmilingWolf/wd-swinv2-tagger-v3"
|
| 20 |
+
CONV_MODEL_DSV3_REPO = "SmilingWolf/wd-convnext-tagger-v3"
|
| 21 |
VIT_MODEL_DSV3_REPO = "ura23/wd-vit-tagger-v3"
|
| 22 |
+
VIT_LARGE_MODEL_DSV3_REPO = "SmilingWolf/wd-vit-large-tagger-v3"
|
| 23 |
+
EVA02_LARGE_MODEL_DSV3_REPO = "SmilingWolf/wd-eva02-large-tagger-v3"
|
| 24 |
+
|
| 25 |
+
# Dataset v2 series of models:
|
| 26 |
+
MOAT_MODEL_DSV2_REPO = "SmilingWolf/wd-v1-4-moat-tagger-v2"
|
| 27 |
+
SWIN_MODEL_DSV2_REPO = "SmilingWolf/wd-v1-4-swinv2-tagger-v2"
|
| 28 |
+
CONV_MODEL_DSV2_REPO = "SmilingWolf/wd-v1-4-convnext-tagger-v2"
|
| 29 |
+
CONV2_MODEL_DSV2_REPO = "SmilingWolf/wd-v1-4-convnextv2-tagger-v2"
|
| 30 |
+
VIT_MODEL_DSV2_REPO = "SmilingWolf/wd-v1-4-vit-tagger-v2"
|
| 31 |
+
|
| 32 |
+
# IdolSankaku series of models:
|
| 33 |
+
EVA02_LARGE_MODEL_IS_DSV1_REPO = "deepghs/idolsankaku-eva02-large-tagger-v1"
|
| 34 |
+
SWINV2_MODEL_IS_DSV1_REPO = "deepghs/idolsankaku-swinv2-tagger-v1"
|
| 35 |
|
| 36 |
# Files to download from the repos
|
| 37 |
MODEL_FILENAME = "model.onnx"
|
|
|
|
| 123 |
predictor = Predictor()
|
| 124 |
|
| 125 |
model_repos = [
|
| 126 |
+
SWINV2_MODEL_DSV3_REPO,
|
| 127 |
+
CONV_MODEL_DSV3_REPO,
|
| 128 |
VIT_MODEL_DSV3_REPO,
|
| 129 |
+
VIT_LARGE_MODEL_DSV3_REPO,
|
| 130 |
+
EVA02_LARGE_MODEL_DSV3_REPO,
|
| 131 |
+
# ---
|
| 132 |
+
MOAT_MODEL_DSV2_REPO,
|
| 133 |
+
SWIN_MODEL_DSV2_REPO,
|
| 134 |
+
CONV_MODEL_DSV2_REPO,
|
| 135 |
+
CONV2_MODEL_DSV2_REPO,
|
| 136 |
+
VIT_MODEL_DSV2_REPO,
|
| 137 |
+
# ---
|
| 138 |
+
SWINV2_MODEL_IS_DSV1_REPO,
|
| 139 |
+
EVA02_LARGE_MODEL_IS_DSV1_REPO,
|
| 140 |
]
|
| 141 |
|
| 142 |
+
predefined_tags = ["loli",
|
| 143 |
+
"oppai_loli",
|
| 144 |
"2024",
|
|
|
|
| 145 |
"2023",
|
| 146 |
+
"2025",
|
| 147 |
+
"genderswap",
|
| 148 |
+
"genderswap_(otm)",
|
| 149 |
+
"genderswap_(otf)",
|
| 150 |
+
"genderswap_(mtf)",
|
| 151 |
+
"genderswap_(ftm)",
|
| 152 |
+
"respirator",
|
| 153 |
+
"head-mounted_display",
|
| 154 |
+
"2022",
|
| 155 |
+
"muscular_female",
|
| 156 |
+
"muscular",
|
| 157 |
+
"abs",
|
| 158 |
+
"2021",
|
| 159 |
+
"peeing",
|
| 160 |
+
"pee",
|
| 161 |
+
"round_eyewear",
|
| 162 |
+
"yellow-framed_eyewear",
|
| 163 |
+
"hetero",
|
| 164 |
+
"vaginal",
|
| 165 |
+
"straddling",
|
| 166 |
+
"girl_on_top",
|
| 167 |
+
"male_pubic_hair",
|
| 168 |
+
"cowgirl_position",
|
| 169 |
+
"happy_sex",
|
| 170 |
+
"vibrator_under_panties",
|
| 171 |
+
"vibrator_in_thighhighs",
|
| 172 |
+
"anal_beads",
|
| 173 |
+
"butt_plug",
|
| 174 |
+
"sex_toy",
|
| 175 |
+
"anal",
|
| 176 |
+
"object_insertion",
|
| 177 |
+
"dildo",
|
| 178 |
+
"anal_object_insertion",
|
| 179 |
+
"vaginal_object_insertion",
|
| 180 |
+
"semi-rimless_eyewear",
|
| 181 |
+
"red-framed_eyewear",
|
| 182 |
+
"under-rim_eyewear",
|
| 183 |
+
"3d_background",
|
| 184 |
+
"sample_watermark",
|
| 185 |
+
"onee-shota",
|
| 186 |
+
"incest",
|
| 187 |
+
"furry",
|
| 188 |
+
"can",
|
| 189 |
+
"drinking_can",
|
| 190 |
+
"holding_can",
|
| 191 |
+
"twitter_strip_game_(meme)",
|
| 192 |
+
"like_and_retweet",
|
| 193 |
+
"furry_female",
|
| 194 |
+
"realistic",
|
| 195 |
+
"egg_vibrator",
|
| 196 |
+
"tongue_piercing",
|
| 197 |
+
"handheld_game_console",
|
| 198 |
+
"game_controller",
|
| 199 |
+
"nintendo_switch",
|
| 200 |
+
"talking",
|
| 201 |
+
"swastika",
|
| 202 |
+
"character_name",
|
| 203 |
+
"vibrator",
|
| 204 |
+
"black-framed_eyewear",
|
| 205 |
+
"heterochromia",
|
| 206 |
+
"chibi",
|
| 207 |
+
"mini_person",
|
| 208 |
+
"controller",
|
| 209 |
+
"remote_control_vibrator",
|
| 210 |
+
"vibrator_under_clothes",
|
| 211 |
+
"thank_you",
|
| 212 |
+
"vibrator_cord",
|
| 213 |
+
"shota",
|
| 214 |
+
"cropped_legs",
|
| 215 |
+
"cropped_torso",
|
| 216 |
+
"traditional_media",
|
| 217 |
+
"color_guide",
|
| 218 |
+
"photorealistic",
|
| 219 |
+
"male_focus",
|
| 220 |
+
"black_babydoll",
|
| 221 |
+
"signature",
|
| 222 |
+
"web_address",
|
| 223 |
+
"censored_nipples",
|
| 224 |
+
"rhodes_island_logo_(arknights)",
|
| 225 |
+
"gothic_lolita",
|
| 226 |
+
"glasses",
|
| 227 |
+
"reference_inset",
|
| 228 |
+
"twitter_logo",
|
| 229 |
+
"mother_and_daughter",
|
| 230 |
+
"holding_controller",
|
| 231 |
+
"holding_game_controller",
|
| 232 |
+
"baby",
|
| 233 |
+
"heart_censor",
|
| 234 |
+
"pixiv_username",
|
| 235 |
+
"korean_text",
|
| 236 |
+
"pixiv_logo",
|
| 237 |
+
"greyscale_with_colored_background",
|
| 238 |
+
"water_bottle",
|
| 239 |
+
"body_writing",
|
| 240 |
+
"used_condom",
|
| 241 |
+
"multiple_condoms",
|
| 242 |
+
"condom_belt",
|
| 243 |
+
"holding_phone",
|
| 244 |
+
"multiple_views",
|
| 245 |
+
"phone",
|
| 246 |
+
"cellphone",
|
| 247 |
+
"zoom_layer",
|
| 248 |
+
"smartphone",
|
| 249 |
+
"lolita_hairband",
|
| 250 |
+
"lactation",
|
| 251 |
+
"otoko_no_ko",
|
| 252 |
+
"minigirl",
|
| 253 |
+
"babydoll",
|
| 254 |
+
"domino_mask",
|
| 255 |
+
"pixiv_id",
|
| 256 |
+
"qr_code",
|
| 257 |
+
"monochrome",
|
| 258 |
+
"trick_or_treat",
|
| 259 |
+
"happy_birthday",
|
| 260 |
+
"lolita_fashion",
|
| 261 |
+
"arrow_(symbol)",
|
| 262 |
+
"happy_new_year",
|
| 263 |
+
"dated",
|
| 264 |
+
"thought_bubble",
|
| 265 |
+
"greyscale",
|
| 266 |
+
"speech_bubble",
|
| 267 |
+
"mask",
|
| 268 |
+
"comic",
|
| 269 |
+
"bottle",
|
| 270 |
+
"holding_bottle",
|
| 271 |
+
"milk",
|
| 272 |
+
"milk_bottle",
|
| 273 |
+
"english_text",
|
| 274 |
+
"copyright_name",
|
| 275 |
+
"twitter_username",
|
| 276 |
+
"fanbox_username",
|
| 277 |
+
"patreon_username",
|
| 278 |
+
"patreon_logo",
|
| 279 |
+
"cover",
|
| 280 |
+
"weibo_logo",
|
| 281 |
+
"weibo_username",
|
| 282 |
+
"signature",
|
| 283 |
+
"content_rating",
|
| 284 |
+
"cover_page",
|
| 285 |
+
"doujin_cover",
|
| 286 |
+
"sex",
|
| 287 |
+
"artist_name",
|
| 288 |
+
"watermark",
|
| 289 |
+
"censored",
|
| 290 |
+
"bar_censor",
|
| 291 |
+
"blank_censor",
|
| 292 |
+
"blur_censor",
|
| 293 |
+
"light_censor",
|
| 294 |
+
"mosaic_censoring"]
|
| 295 |
|
| 296 |
with gr.Blocks(title=TITLE) as demo:
|
| 297 |
+
gr.Markdown(f"<h1 style='text-align: center;'>{TITLE}</h1>")
|
| 298 |
+
gr.Markdown(DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
+
with gr.Row():
|
| 301 |
+
with gr.Column():
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
submit = gr.Button(
|
| 304 |
+
value="Process Images", variant="primary"
|
| 305 |
)
|
| 306 |
+
|
| 307 |
+
image_files = gr.File(
|
| 308 |
+
file_types=["image"], label="Upload Images", file_count="multiple",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
)
|
| 310 |
+
|
| 311 |
+
# Wrap the model selection and sliders in an Accordion
|
| 312 |
+
with gr.Accordion("Advanced Settings", open=False): # Collapsible by default
|
| 313 |
+
model_repo = gr.Dropdown(
|
| 314 |
+
model_repos,
|
| 315 |
+
value=VIT_MODEL_DSV3_REPO,
|
| 316 |
+
label="Select Model",
|
| 317 |
+
)
|
| 318 |
+
general_thresh = gr.Slider(
|
| 319 |
+
0, 1, step=args.score_slider_step, value=args.score_general_threshold, label="General Tags Threshold"
|
| 320 |
+
)
|
| 321 |
+
character_thresh = gr.Slider(
|
| 322 |
+
0, 1, step=args.score_slider_step, value=args.score_character_threshold, label="Character Tags Threshold"
|
| 323 |
+
)
|
| 324 |
+
filter_tags = gr.Textbox(
|
| 325 |
+
value=", ".join(predefined_tags),
|
| 326 |
+
label="Filter Tags (comma-separated)",
|
| 327 |
+
placeholder="Add tags to filter out (e.g., winter, red, from above)",
|
| 328 |
+
lines=9
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
with gr.Column():
|
| 333 |
+
output = gr.Textbox(label="Output", lines=10)
|
| 334 |
|
| 335 |
def process_images(files, model_repo, general_thresh, character_thresh, filter_tags):
|
| 336 |
images = [Image.open(file.name) for file in files]
|