FacehuggerShield automatically locks down operations for specific modules. It was designed to non-destructively restrict access to HuggingFace libraries, but can be used with any library.
FacehuggerShield was specifically designed to override HuggingFace libraries, so the following examples show how to do that.
Install with HuggingFace libraries (or any other library you want to restrict).
pip install facehuggershield
Import in your application's main entry file (e.g. main.py
), import facehuggershield
before importing
any other libraries.
from facehuggershield.huggingface import activate
activate()
Now you can use HuggingFace libraries without worrying about telemetry, networking or file writes.
See the activate
function in the huggingface/init.py file.
FacehuggerShield uses nullscream to intercept blacklisted modules and return Noop modules in their place. The noop modules are empty classes with functions that return Magic noop classes. The magic class functions in turn respond with Magic classes.
This allows anything on the blacklist to be importable, but not executable.
By overriding certain functions in HuggingFace libraries, FacehuggerShield is able to prevent the use of HuggingFace Hub.
FacehuggerShield also makes use of darklock to lock down network services, and shadowlogger to intercept and reroute logs.
These libraries are combined under defendatron, a simple coordinator library.
FacehuggerShield contains all of the required settings for defendatron, as well as the best HuggingFace Library settings for privacy.
Although FacehuggerShield was specifically created to contain or nuke certain portions of the HuggingFace libraries, it can be configured to work with any library as it is simply a configuration wrapper around the previously mentioned modules which do the real work.
If you want to add support for other libraries
- Copy and paste the
huggingface
directory, name it after the library you're creating a configuration for - Modify all of the files in the new directory to fit your needs using the HuggingFace settings as your example