diff --git a/CHANGES.md b/CHANGES.md index 1209960c..d54a1d84 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ - **Major rewrite of the code** - We've switched to using diffusers under-the-hood, which allows us to release new features faster, and focus on making the UI and installer even easier to use. ### Detailed changelog +* 3.0.2 - 30 Aug 2023 - Allow blocking NSFW images using a server-side config. This prevents the browser from generating NSFW images or changing the config. Open `config.yaml` in a text editor (e.g. Notepad), and add `block_nsfw: true` at the end, and save the file. * 3.0.2 - 29 Aug 2023 - Fixed incorrect matching of embeddings from prompts. * 3.0.2 - 24 Aug 2023 - Fix broken seamless tiling. * 3.0.2 - 23 Aug 2023 - Fix styling on mobile devices. diff --git a/ui/easydiffusion/server.py b/ui/easydiffusion/server.py index e3f80f42..5af198fe 100644 --- a/ui/easydiffusion/server.py +++ b/ui/easydiffusion/server.py @@ -36,6 +36,7 @@ NOCACHE_HEADERS = { "Pragma": "no-cache", "Expires": "0", } +PROTECTED_CONFIG_KEYS = ("block_nsfw",) # can't change these via the HTTP API class NoCacheStaticFiles(StaticFiles): @@ -175,7 +176,7 @@ def set_app_config_internal(req: SetAppConfigRequest): config["test_diffusers"] = req.test_diffusers for property, property_value in req.dict().items(): - if property_value is not None and property not in req.__fields__: + if property_value is not None and property not in req.__fields__ and property not in PROTECTED_CONFIG_KEYS: config[property] = property_value try: @@ -456,6 +457,7 @@ def modify_package_internal(package_name: str, req: dict): log.error(traceback.format_exc()) return HTTPException(status_code=500, detail=str(e)) + def get_sha256_internal(obj_path): import hashlib from easydiffusion.utils import sha256sum @@ -477,4 +479,3 @@ def get_sha256_internal(obj_path): log.error(str(e)) log.error(traceback.format_exc()) return HTTPException(status_code=500, detail=str(e)) - diff --git a/ui/easydiffusion/tasks/render_images.py b/ui/easydiffusion/tasks/render_images.py index f0d25d37..b512e707 100644 --- a/ui/easydiffusion/tasks/render_images.py +++ b/ui/easydiffusion/tasks/render_images.py @@ -42,9 +42,16 @@ class RenderTask(Task): def run(self): "Runs the image generation task on the assigned thread" - from easydiffusion import task_manager + from easydiffusion import task_manager, app context = runtime.context + config = app.getConfig() + + if config.get("block_nsfw", False): # override if set on the server + self.task_data.block_nsfw = True + if "nsfw_checker" not in self.task_data.filters: + self.task_data.filters.append("nsfw_checker") + self.models_data.model_paths["nsfw_checker"] = "nsfw_checker" def step_callback(): task_manager.keep_task_alive(self)