Compare commits
No commits in common. "main" and "main" have entirely different histories.
16
Readme.md
16
Readme.md
|
@ -2,9 +2,10 @@ This `api.py` file has some additional modifications that can be activated withi
|
|||
|
||||
This file replaces `modules/api/api.py` .
|
||||
|
||||
> **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.
|
||||
::: 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.
|
||||
|
||||
:::
|
||||
|
||||
A clean, original[ ](http://api.py)`api.py` file can be found in the `#Original API File` folder
|
||||
|
||||
|
@ -24,8 +25,6 @@ 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
|
||||
|
||||
|
@ -39,12 +38,11 @@ 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, Imagelog and AntiChildPorn:
|
||||
For example to enable the Promptlog and Imagelog:
|
||||
|
||||
```python
|
||||
eris_promtlog = True
|
||||
|
@ -52,11 +50,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
|
||||
|
||||
> **Warning** \
|
||||
> Additional and !!**__necessary__**!! Instructions for the TRT-Patch are in the `TRT-Patch` Folder
|
||||
::: warn
|
||||
Additional and !!**__necessary__**!! Instructions for the TRT-Patch are in the `TRT-Patch` Folder
|
||||
|
||||
:::
|
|
@ -7,15 +7,17 @@ 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`
|
||||
|
||||
> **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 \
|
||||
::: 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
|
||||
|
||||
:::
|
70
api.py
70
api.py
|
@ -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, Tuple
|
||||
from typing import Any
|
||||
import piexif
|
||||
import piexif.helper
|
||||
from contextlib import closing
|
||||
|
@ -63,7 +63,6 @@ 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
|
||||
|
@ -76,64 +75,6 @@ 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:
|
||||
|
@ -520,10 +461,6 @@ 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)
|
||||
|
||||
|
||||
|
||||
|
@ -663,11 +600,6 @@ 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:
|
||||
|
|
Loading…
Reference in New Issue