Spaces:
Running
Running
v. 1.1
Browse files* updated library versions
* cache directory defined as subdirectory of home dir
* cache dir for Transformers set as environment variable, instead of
in config file
- CHANGES.md +10 -0
- app.py +19 -11
- config.json +1 -2
- requirements.txt +5 -9
CHANGES.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,8 +1,22 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,19 +29,14 @@ language_choices = {
|
|
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
|
30 |
-
2. **Redact** - all PII instances are replaced by a
|
31 |
3. **Placeholder** - replace with a prototypical value
|
32 |
4. **Synthetic** - substitute with synthetic data
|
33 |
|
@@ -170,4 +179,3 @@ with gr.Blocks() as demo:
|
|
170 |
with gr.Accordion(label="Help Panel", open=False):
|
171 |
gr.Markdown(value=policy_help_string)
|
172 |
demo.queue().launch()
|
173 |
-
|
|
|
|
|
1 |
import os
|
2 |
+
from pathlib import Path
|
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 |
"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 <TYPE:VALUE> string, i.e. include both the PII type and its value
|
39 |
+
2. **Redact** - all PII instances are replaced by a <PII> generic string
|
40 |
3. **Placeholder** - replace with a prototypical value
|
41 |
4. **Synthetic** - substitute with synthetic data
|
42 |
|
|
|
179 |
with gr.Accordion(label="Help Panel", open=False):
|
180 |
gr.Markdown(value=policy_help_string)
|
181 |
demo.queue().launch()
|
|
config.json
CHANGED
@@ -4,7 +4,6 @@
|
|
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,4 +73,4 @@
|
|
74 |
}
|
75 |
}
|
76 |
]
|
77 |
-
}
|
|
|
4 |
{
|
5 |
"format": "piisa:config:pii-extract-plg-transformers:main:v1",
|
6 |
"task_config": {
|
|
|
7 |
"reuse_engine": true,
|
8 |
"aggregation": "max",
|
9 |
"models": [
|
|
|
73 |
}
|
74 |
}
|
75 |
]
|
76 |
+
}
|
requirements.txt
CHANGED
@@ -1,9 +1,5 @@
|
|
1 |
-
|
2 |
-
pii-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
pii-preprocess==0.0.4
|
7 |
-
pii-transform==0.5.1
|
8 |
-
torch==2.1.0
|
9 |
-
transformers==4.34.0
|
|
|
1 |
+
wheel
|
2 |
+
pii-process[transformers] >= 0.1.1
|
3 |
+
|
4 |
+
torch>=2.2
|
5 |
+
transformers>=4.34.0
|
|
|
|
|
|
|
|