Skip to main content

Provides some of the tools the AI Horde uses for safety.

Project description

horde-safety

Provides safety features used by the horde, especially to do with image generation.

Note

This library is made with the default AI Horde worker in mind, and relies on the environment variable AIWORKER_CACHE_HOME to establish isolation of the clip models on disk. If you do not want to rely on a horde specific folder structure, define TRANSFORMERS_CACHE to define where you'd prefer the models to be. If neither are defined, the default huggingface folder location for the system used, typically ~/.cache, depending on other environnement variables, see the official huggingface docs for more info.

Installing

Make sure pytorch is installed, preferably with CUDA/ROCM support.

    pip install horde_safety

Use

This library currently relies on clip_interrogator. The check_for_csam function requires an instance of clip_interrogator.Interrogator to be passed. You can pass in on yourself, or use the helper function get_interrogator_no_blip (note that calling this function immediately loads the CLIP model).

    import PIL.Image

    from horde_safety.csam_checker import check_for_csam
    from horde_safety.interrogate import get_interrogator_no_blip

    interrogator = get_interrogator_no_blip()
    image: PIL.Image.Image
    prompt: str

    (...)

    is_csam, results, info = check_for_csam(
        interrogator=interrogator,
        image=image,
        prompt=prompt,
        model_info={"nsfw": True, "tags": []},
        # model_info can be found at https://github.com/Haidra-Org/AI-Horde-image-model-reference/
    )

    if is_csam:
        reject_job()

If you reject a job as a horde worker for CSAM, you should report 'state': 'csam' in the generate submit payload.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

horde_safety-0.1.1.tar.gz (47.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

horde_safety-0.1.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file horde_safety-0.1.1.tar.gz.

File metadata

  • Download URL: horde_safety-0.1.1.tar.gz
  • Upload date:
  • Size: 47.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for horde_safety-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e974c481a2be9e6af5a4dddb2d40fff2cbdda94f2e952a800be9a083cd31d7d7
MD5 c8e4e2c5c16d7bc381e44b132bd79b97
BLAKE2b-256 0484c63e5f9a27624857e1fd3a51f6e42bcc6d7704901dd8eaca84e3783d45d8

See more details on using hashes here.

File details

Details for the file horde_safety-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: horde_safety-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for horde_safety-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8449c1f6941efbacd10e59cfdaa079d31fb4296909dcf08063c75ad265b32d
MD5 de8eeeb90c39ebee6704957c07e2104b
BLAKE2b-256 d85602bd1007d3df544d901e4893ef3ed5d26cef9c6fb109a8fc1f1129dc0051

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page