Compare commits

...

16 Commits
main ... main

Author SHA1 Message Date
Hitmare 6ce183544f Update TRT-Patch/Readme.md 2024-01-29 23:05:39 +00:00
Hitmare f8ea16349e Update Readme.md 2024-01-29 23:04:16 +00:00
Hitmare 26b4cf297a Update Readme.md 2024-01-29 23:03:50 +00:00
Hitmare dfa90b9f70 Update Readme.md 2024-01-29 23:03:40 +00:00
Hitmare b21fe64411 Update Readme.md 2024-01-29 23:03:17 +00:00
Hitmare cd70de52e8 Update Readme.md 2024-01-29 23:02:51 +00:00
Hitmare 9fcd7d5067 Update Readme.md 2024-01-29 23:02:19 +00:00
Hitmare 54f45d2390 Update Readme.md 2024-01-29 22:55:03 +00:00
Hitmare 9187dfdad1 Update Readme.md 2024-01-29 22:54:01 +00:00
Hitmare e93a2de8bc Update Readme.md 2024-01-29 22:53:11 +00:00
Hitmare 4a9bf0f823 Update Readme.md 2024-01-29 22:52:28 +00:00
Hitmare 8f3d7ca9fd Merge pull request 'Add anti child porn patch' (#3) from cofob/Eris_api_tensor_patch:anti-child-porn into main
Reviewed-on: Hitmare/Eris_api_tensor_patch#3
Reviewed-by: Hitmare <hitmare@noreply@foxo.me>
2024-01-06 09:42:53 +00:00
cofob a40b8228ba
Lower prompt 2024-01-06 09:45:05 +07:00
cofob 23a9b8a8e3
Add kid tag 2024-01-06 09:43:54 +07:00
cofob 0505146563
Add README 2024-01-06 09:38:07 +07:00
cofob 16b3903d80
Add anti child porn patch 2024-01-06 09:33:34 +07:00
3 changed files with 90 additions and 22 deletions

View File

@ -2,10 +2,9 @@ This `api.py` file has some additional modifications that can be activated withi
This file replaces `modules/api/api.py` .
::: error
Don't overwrite your original `api.py` file. Rename it to something different like `api_original.py` and then copy the modified `api.py` into your `modules/api` folder.
> **Note** \
> Don't overwrite your original `api.py` file. Rename it to something different like `api_original.py` and then copy the modified `api.py` into your `modules/api` folder.
:::
A clean, original[ ](http://api.py)`api.py` file can be found in the `#Original API File` folder
@ -25,6 +24,8 @@ The modified API.py file can do the following:
5. Eris Imagelimit:
- Will resize and limit every request down to 1024px max on height and width, keeping the aspect ratio. Also reduces Steps down to 35 if the set Steps exceeds 35
- Compatible with TRTpatch. Please read the Readme in the `TRT-Patch` folder for the additional instructions
6. Eris AntiChildPorn:
- Will prevent the generation of child porn images.
# Enabling the Modifications
@ -38,11 +39,12 @@ eris_imagelog = False
eris_consolelog = False
eris_TRTpatch = False
eris_imagelimit = False
eris_antichildporn = False
```
Change the `False` to `True` to enable any of the modifications.
For example to enable the Promptlog and Imagelog:
For example to enable the Promptlog, Imagelog and AntiChildPorn:
```python
eris_promtlog = True
@ -50,11 +52,11 @@ eris_imagelog = True
eris_consolelog = False
eris_TRTpatch = False
eris_imagelimit = False
eris_antichildporn = True
```
Don't forget to save the `api.py` file again and (re)start your A1111 Stable-difussion
::: warn
Additional and !!**__necessary__**!! Instructions for the TRT-Patch are in the `TRT-Patch` Folder
> **Warning** \
> Additional and !!**__necessary__**!! Instructions for the TRT-Patch are in the `TRT-Patch` Folder
:::

View File

@ -7,17 +7,15 @@ Original files for restoring can be found in the `#Original` folder
Copy `api.py` from the previous folder into `modules/api` and enable `eris_TRTpatch` or `eris_imagelimit`
::: warn
If you use the TRTpatch with the Imagelimit you will need to create a **__Dynamic Tensor Profile__** with the following settings:
`min/opt/max batch size: 1, 2, 4`
`min/opt/max width: 256/576/1024`
`min/opt/max height: 256/704/1024`
`min/opt/max tokens: 75/75/500`\`
Those settings are **__very critical__** to have the TRT Plugin working correctly
:::
> **Warning**\
>If you use the TRTpatch with the Imagelimit you will need to create a **__Dynamic Tensor Profile__** with the following settings:\
>\
>`min/opt/max batch size: 1, 2, 4`\
>\
>`min/opt/max width: 256/576/1024`\
>\
>`min/opt/max height: 256/704/1024`\
>\
>`min/opt/max tokens: 75/75/500`\
>\
>Those settings are **__very critical__** to have the TRT Plugin working correctly \

70
api.py
View File

@ -27,7 +27,7 @@ from PIL import PngImagePlugin, Image
from modules.sd_models_config import find_checkpoint_config_near_filename
from modules.realesrgan_model import get_realesrgan_models
from modules import devices
from typing import Any
from typing import Any, Tuple
import piexif
import piexif.helper
from contextlib import closing
@ -63,6 +63,7 @@ eris_imagelog = False
eris_consolelog = False
eris_TRTpatch = False
eris_imagelimit = False
eris_antichildporn = False
# Limits for text2image. needs eris_imagelimit = True
txt_max_width_height = 1024
txt_min_width_height = 320
@ -75,6 +76,64 @@ img_min_width_height = 320
img_max_pixel_count = 589824
img_max_steps = 35
img_max_characters = 2000
# Anti child porn tags. Needs eris_antichildporn = True
# If a tag is found in the prompt, anti child porn will be triggered,
# and the tag will be removed from the prompt and added to the neg_prompt.
child_porn_tags = [
"loli",
"baby",
"newborn",
"kid",
]
# Soft tags will be removed if they are found and added to the neg_prompt, but they
# cannot trigger the anti child porn check.
soft_child_porn_tags = [
"small",
"little",
"1 year",
"2 years",
"3 years",
"4 years",
"5 years",
"6 years",
"7 years",
"8 years",
"9 years",
"10 years",
"11 years",
"12 years",
"13 years",
"14 years",
"15 years",
]
def anti_child_porn(prompt: str, neg_prompt: str) -> Tuple[str, str]:
"""Detect child porn and remove it from the prompt.
This can be easily bypassed, but we assume that pedophiles are not smart
enough to understand how to do it.
Args:
prompt (str): Positive prompt.
neg_prompt (str): Negative promth.
Returns:
Tuple[str, str]: Updated positive prompt and negative prompt.
"""
tags = prompt.replace(",", " ").lower().split(" ")
detected = False
for tag in child_porn_tags:
if tag in tags:
if not detected:
print("[Anti-Child-Porn] Detected child porn, original prompt:", (prompt, neg_prompt))
prompt = prompt.replace(tag, "")
detected = True
if detected:
for tag in soft_child_porn_tags:
prompt = prompt.replace(tag, "")
neg_prompt += " , " + ", ".join(child_porn_tags + soft_child_porn_tags)
print("[Anti-Child-Porn] Patched:", (prompt, neg_prompt))
return (prompt, neg_prompt)
def script_name_to_index(name, scripts):
try:
@ -461,6 +520,10 @@ class Api:
if eris_consolelog:
print('[t2i]', txt2imgreq.width, 'x', txt2imgreq.height, '|', txt2imgreq.prompt)
# Eris ______
# Eris AntiChildPorn
if eris_antichildporn:
txt2imgreq.prompt, txt2imgreq.negative_prompt = anti_child_porn(txt2imgreq.prompt, txt2imgreq.negative_prompt)
@ -600,6 +663,11 @@ class Api:
# Eris console prompt log -> writes promts into the console/terminal window
if eris_consolelog:
print('[i2i]', img2imgreq.width, 'x', img2imgreq.height, '|', img2imgreq.prompt)
# Eris AntiChildPorn
if eris_antichildporn:
img2imgreq.prompt, img2imgreq.negative_prompt = anti_child_porn(img2imgreq.prompt, img2imgreq.negative_prompt)
# Eris ______
init_images = img2imgreq.init_images
if init_images is None: