From e8d379ae8becac75ccd8f988388498ce2b24fba9 Mon Sep 17 00:00:00 2001 From: Wyatt Lansford <22553069+wylansford@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:23:14 -0700 Subject: [PATCH 1/2] adding has_guardrails_endpoint flag --- app.py | 24 ++++++++++++++++++++++++ inferless-runtime-config.yaml | 4 ++++ inferless.yaml | 0 validator/main.py | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app.py create mode 100644 inferless-runtime-config.yaml create mode 100644 inferless.yaml diff --git a/app.py b/app.py new file mode 100644 index 0000000..4878144 --- /dev/null +++ b/app.py @@ -0,0 +1,24 @@ +from typing import Any, Dict, List, cast + + +from presidio_analyzer import AnalyzerEngine +from presidio_anonymizer import AnonymizerEngine + + +class InferlessPythonModel: + def initialize(self): + self.pii_analyzer = AnalyzerEngine() + self.pii_anonymizer = AnonymizerEngine() + + def infer(self, inputs: Dict[str, Any]): + results = self.pii_analyzer.analyze( + text=inputs["text"], entities=inputs["entities"], language="en" + ) + results = cast(List[Any], results) + anonymized_text = self.pii_anonymizer.anonymize( + text=inputs["text"], analyzer_results=results + ).text + return anonymized_text + + def finalize(self): + pass diff --git a/inferless-runtime-config.yaml b/inferless-runtime-config.yaml new file mode 100644 index 0000000..6c3b295 --- /dev/null +++ b/inferless-runtime-config.yaml @@ -0,0 +1,4 @@ +build: + system_packages: + python_packages: + - "presidio_analyzer" \ No newline at end of file diff --git a/inferless.yaml b/inferless.yaml new file mode 100644 index 0000000..e69de29 diff --git a/validator/main.py b/validator/main.py index 3e064f8..b40bed6 100644 --- a/validator/main.py +++ b/validator/main.py @@ -9,7 +9,7 @@ ) -@register_validator(name="guardrails/sensitive_topics", data_type="string") +@register_validator(name="guardrails/sensitive_topics", data_type="string", has_guardrails_endpoint=True) class SensitiveTopic(RestrictToTopic): # type: ignore """Checks if text contains any sensitive topics. From 2b305ff1c8e4b93502085fb7e8ceb840e0c30b61 Mon Sep 17 00:00:00 2001 From: Wyatt Lansford <22553069+wylansford@users.noreply.github.com> Date: Wed, 17 Jul 2024 15:33:57 -0700 Subject: [PATCH 2/2] removing old inferless files --- app.py | 24 ------------------------ inferless-runtime-config.yaml | 4 ---- inferless.yaml | 0 3 files changed, 28 deletions(-) delete mode 100644 app.py delete mode 100644 inferless-runtime-config.yaml delete mode 100644 inferless.yaml diff --git a/app.py b/app.py deleted file mode 100644 index 4878144..0000000 --- a/app.py +++ /dev/null @@ -1,24 +0,0 @@ -from typing import Any, Dict, List, cast - - -from presidio_analyzer import AnalyzerEngine -from presidio_anonymizer import AnonymizerEngine - - -class InferlessPythonModel: - def initialize(self): - self.pii_analyzer = AnalyzerEngine() - self.pii_anonymizer = AnonymizerEngine() - - def infer(self, inputs: Dict[str, Any]): - results = self.pii_analyzer.analyze( - text=inputs["text"], entities=inputs["entities"], language="en" - ) - results = cast(List[Any], results) - anonymized_text = self.pii_anonymizer.anonymize( - text=inputs["text"], analyzer_results=results - ).text - return anonymized_text - - def finalize(self): - pass diff --git a/inferless-runtime-config.yaml b/inferless-runtime-config.yaml deleted file mode 100644 index 6c3b295..0000000 --- a/inferless-runtime-config.yaml +++ /dev/null @@ -1,4 +0,0 @@ -build: - system_packages: - python_packages: - - "presidio_analyzer" \ No newline at end of file diff --git a/inferless.yaml b/inferless.yaml deleted file mode 100644 index e69de29..0000000