Spaces:
Sleeping
Sleeping
fix/library-versions
#3
by
Paulo
- opened
- CHANGES.md +0 -10
- app.py +11 -19
- config.json +2 -1
- requirements.txt +9 -5
CHANGES.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
# ChangeLog
|
| 2 |
-
|
| 3 |
-
## v. 1.1
|
| 4 |
-
* updated library versions
|
| 5 |
-
* cache directory defined as subdirectory of home dir
|
| 6 |
-
* cache dir for Transformers set as environment variable, instead of
|
| 7 |
-
in config file
|
| 8 |
-
|
| 9 |
-
## v. 1.0
|
| 10 |
-
* initial version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
# Set the HF cache directory for the Transformers plugin
|
| 5 |
-
cache_dir = Path.home() / "app"/ "cache"
|
| 6 |
-
cache_dir.mkdir(parents=True, exist_ok=True)
|
| 7 |
-
os.environ["HUGGINGFACE_HUB_CACHE"] = str(cache_dir)
|
| 8 |
-
|
| 9 |
-
from pii_process.api import PiiTextProcessor
|
| 10 |
from pii_extract.defs import FMT_CONFIG_PLUGIN
|
| 11 |
-
import gradio as gr
|
| 12 |
|
| 13 |
-
# Test if the cache directory exists
|
| 14 |
-
if cache_dir.is_dir():
|
| 15 |
-
gr.Info("Cache directory created at "+str(cache_dir))
|
| 16 |
-
else:
|
| 17 |
-
gr.Warning("Cache directory creation error")
|
| 18 |
-
|
| 19 |
-
# Read examples
|
| 20 |
examples = []
|
| 21 |
with open("examples.txt", "r") as f:
|
| 22 |
examples = f.readlines()
|
|
@@ -29,14 +15,19 @@ language_choices = {
|
|
| 29 |
"German": "de",
|
| 30 |
"French": "fr",
|
| 31 |
}
|
| 32 |
-
|
| 33 |
language_code = "en"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
policy_help_string = """
|
| 36 |
Policies are defined as follows:
|
| 37 |
|
| 38 |
-
1. **Annotate** - replace the PII instance by a
|
| 39 |
-
2. **Redact** - all PII instances are replaced by a
|
| 40 |
3. **Placeholder** - replace with a prototypical value
|
| 41 |
4. **Synthetic** - substitute with synthetic data
|
| 42 |
|
|
@@ -179,3 +170,4 @@ with gr.Blocks() as demo:
|
|
| 179 |
with gr.Accordion(label="Help Panel", open=False):
|
| 180 |
gr.Markdown(value=policy_help_string)
|
| 181 |
demo.queue().launch()
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from pii_transform.api.e2e import PiiTextProcessor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from pii_extract.defs import FMT_CONFIG_PLUGIN
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
examples = []
|
| 7 |
with open("examples.txt", "r") as f:
|
| 8 |
examples = f.readlines()
|
|
|
|
| 15 |
"German": "de",
|
| 16 |
"French": "fr",
|
| 17 |
}
|
|
|
|
| 18 |
language_code = "en"
|
| 19 |
+
cache_dir = "/home/user/app/cache"
|
| 20 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 21 |
+
if os.path.isdir(cache_dir):
|
| 22 |
+
gr.Info("Cache directory created at "+cache_dir)
|
| 23 |
+
else:
|
| 24 |
+
gr.Warning("Cache directory creation error")
|
| 25 |
|
| 26 |
policy_help_string = """
|
| 27 |
Policies are defined as follows:
|
| 28 |
|
| 29 |
+
1. **Annotate** - replace the PII instance by a \<TYPE:VALUE\> string, i.e. include both the PII type and its value
|
| 30 |
+
2. **Redact** - all PII instances are replaced by a \<PII\> generic string
|
| 31 |
3. **Placeholder** - replace with a prototypical value
|
| 32 |
4. **Synthetic** - substitute with synthetic data
|
| 33 |
|
|
|
|
| 170 |
with gr.Accordion(label="Help Panel", open=False):
|
| 171 |
gr.Markdown(value=policy_help_string)
|
| 172 |
demo.queue().launch()
|
| 173 |
+
|
config.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
{
|
| 5 |
"format": "piisa:config:pii-extract-plg-transformers:main:v1",
|
| 6 |
"task_config": {
|
|
|
|
| 7 |
"reuse_engine": true,
|
| 8 |
"aggregation": "max",
|
| 9 |
"models": [
|
|
@@ -73,4 +74,4 @@
|
|
| 73 |
}
|
| 74 |
}
|
| 75 |
]
|
| 76 |
-
}
|
|
|
|
| 4 |
{
|
| 5 |
"format": "piisa:config:pii-extract-plg-transformers:main:v1",
|
| 6 |
"task_config": {
|
| 7 |
+
"cachedir": "/home/user/app/cache",
|
| 8 |
"reuse_engine": true,
|
| 9 |
"aggregation": "max",
|
| 10 |
"models": [
|
|
|
|
| 74 |
}
|
| 75 |
}
|
| 76 |
]
|
| 77 |
+
}
|
requirements.txt
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
-
|
| 2 |
-
pii-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pii-data==0.4.0
|
| 2 |
+
pii-extract-base==0.5.0
|
| 3 |
+
pii-extract-plg-presidio==0.3.2
|
| 4 |
+
pii-extract-plg-regex==0.4.1
|
| 5 |
+
pii-extract-plg-transformers==0.1.1
|
| 6 |
+
pii-preprocess==0.0.4
|
| 7 |
+
pii-transform==0.5.1
|
| 8 |
+
torch==2.1.0
|
| 9 |
+
transformers==4.34.0
|