Spaces:
Running
Running
Commit
·
b58c988
1
Parent(s):
10afe2d
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,16 @@ if os.path.isdir(cache_dir):
|
|
| 23 |
else:
|
| 24 |
gr.Warning("Cache directory creation error")
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def change_language(language_selection):
|
| 27 |
global language_code
|
| 28 |
language_code = language_choices[language_selection]
|
|
@@ -32,13 +42,13 @@ def change_language(language_selection):
|
|
| 32 |
def process(text, policy):
|
| 33 |
# Create the object, defining the language to use and the policy
|
| 34 |
# Further customization is possible by providing a config
|
|
|
|
| 35 |
if text == "":
|
| 36 |
print("Empty text field")
|
| 37 |
gr.Warning("No text present")
|
| 38 |
return ""
|
| 39 |
|
| 40 |
# Custom config to prevent loading of the Presidio plugin
|
| 41 |
-
# config = {FMT_CONFIG_PLUGIN: {"piisa-detectors-presidio": {"load": False}}}
|
| 42 |
proc = PiiTextProcessor(
|
| 43 |
lang=language_code, default_policy=policy, config="config.json"
|
| 44 |
)
|
|
@@ -54,11 +64,22 @@ def get_full_example(idx):
|
|
| 54 |
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
with gr.Row():
|
| 57 |
-
with gr.Column(scale=0, min_width=
|
| 58 |
-
logo = gr.Image(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
with gr.Column():
|
| 60 |
pass
|
| 61 |
-
with gr.Column(
|
|
|
|
|
|
|
|
|
|
| 62 |
lang_picker = gr.Dropdown(
|
| 63 |
choices=list(language_choices.keys()),
|
| 64 |
label="Select Language",
|
|
@@ -75,35 +96,37 @@ with gr.Blocks() as demo:
|
|
| 75 |
)
|
| 76 |
with gr.Column(scale=0, min_width=25):
|
| 77 |
pass
|
| 78 |
-
with gr.Column(scale=0, min_width=
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
pass
|
| 82 |
redact_btn = gr.Button(value="Redact", variant="primary", size="sm")
|
| 83 |
-
anonymize_btn = gr.Button(value="
|
| 84 |
placeholder_btn = gr.Button(
|
| 85 |
value="Placeholder", variant="primary", size="sm"
|
| 86 |
)
|
|
|
|
| 87 |
with gr.Column(scale=0, min_width=25):
|
| 88 |
pass
|
| 89 |
with gr.Column(
|
| 90 |
scale=2,
|
| 91 |
min_width=400,
|
| 92 |
):
|
| 93 |
-
|
| 94 |
label="Transformed Text",
|
| 95 |
lines=10,
|
| 96 |
show_copy_button=True,
|
| 97 |
interactive=False,
|
| 98 |
)
|
| 99 |
-
|
|
|
|
|
|
|
| 100 |
redact_btn.click(
|
| 101 |
fn=process,
|
| 102 |
inputs=[
|
| 103 |
text_original,
|
| 104 |
gr.Text(value="redact", visible=False),
|
| 105 |
],
|
| 106 |
-
outputs=
|
| 107 |
)
|
| 108 |
anonymize_btn.click(
|
| 109 |
fn=process,
|
|
@@ -111,22 +134,24 @@ with gr.Blocks() as demo:
|
|
| 111 |
text_original,
|
| 112 |
gr.Text(value="synthetic", visible=False),
|
| 113 |
],
|
| 114 |
-
outputs=
|
| 115 |
)
|
| 116 |
placeholder_btn.click(
|
| 117 |
fn=process,
|
| 118 |
inputs=[
|
| 119 |
text_original,
|
| 120 |
-
gr.Text(value="
|
| 121 |
],
|
| 122 |
-
outputs=
|
| 123 |
)
|
| 124 |
with gr.Row():
|
| 125 |
example_selector = gr.Dropdown(
|
| 126 |
examples_truncated, type="index", label="Examples"
|
| 127 |
)
|
| 128 |
example_selector.select(
|
| 129 |
-
get_full_example, inputs=example_selector, outputs=text_original
|
| 130 |
)
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
demo.queue().launch()
|
|
|
|
| 23 |
else:
|
| 24 |
gr.Warning("Cache directory creation error")
|
| 25 |
|
| 26 |
+
policy_help_string = """Policies are defined as follows:
|
| 27 |
+
|
| 28 |
+
1. **Annotate** - replace the PII instance by a \<TYPE:VALUE\> string, i.e. include both the PII type and its value
|
| 29 |
+
2. **Redact** - all PII instances are replaced by a \<PII\> generic string
|
| 30 |
+
3. **Placeholder** - replace with a prototypical value
|
| 31 |
+
4. **Synthetic** - substitute with synthetic data
|
| 32 |
+
|
| 33 |
+
For more information on the transformation policies, please refer to the guide [here](https://github.com/piisa/pii-transform/blob/main/doc/policies.md#pii-transformation-policies)"""
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def change_language(language_selection):
|
| 37 |
global language_code
|
| 38 |
language_code = language_choices[language_selection]
|
|
|
|
| 42 |
def process(text, policy):
|
| 43 |
# Create the object, defining the language to use and the policy
|
| 44 |
# Further customization is possible by providing a config
|
| 45 |
+
policy = policy.lower()
|
| 46 |
if text == "":
|
| 47 |
print("Empty text field")
|
| 48 |
gr.Warning("No text present")
|
| 49 |
return ""
|
| 50 |
|
| 51 |
# Custom config to prevent loading of the Presidio plugin
|
|
|
|
| 52 |
proc = PiiTextProcessor(
|
| 53 |
lang=language_code, default_policy=policy, config="config.json"
|
| 54 |
)
|
|
|
|
| 64 |
|
| 65 |
with gr.Blocks() as demo:
|
| 66 |
with gr.Row():
|
| 67 |
+
with gr.Column(scale=0, min_width=100):
|
| 68 |
+
logo = gr.Image(
|
| 69 |
+
"image.jpeg",
|
| 70 |
+
height=100,
|
| 71 |
+
width=100,
|
| 72 |
+
show_label=False,
|
| 73 |
+
show_download_button=False,
|
| 74 |
+
show_share_button=False,
|
| 75 |
+
mask_opacity=1.0,
|
| 76 |
+
)
|
| 77 |
with gr.Column():
|
| 78 |
pass
|
| 79 |
+
with gr.Column(
|
| 80 |
+
scale=0,
|
| 81 |
+
min_width=200,
|
| 82 |
+
):
|
| 83 |
lang_picker = gr.Dropdown(
|
| 84 |
choices=list(language_choices.keys()),
|
| 85 |
label="Select Language",
|
|
|
|
| 96 |
)
|
| 97 |
with gr.Column(scale=0, min_width=25):
|
| 98 |
pass
|
| 99 |
+
with gr.Column(scale=0, min_width=150):
|
| 100 |
+
gr.Markdown(value=""" <p style="text-align: center;">Select Policy</p>""")
|
| 101 |
+
annotate_btn = gr.Button(value="Annotate", variant="primary", size="sm")
|
|
|
|
| 102 |
redact_btn = gr.Button(value="Redact", variant="primary", size="sm")
|
| 103 |
+
anonymize_btn = gr.Button(value="Synthetic", variant="primary", size="sm")
|
| 104 |
placeholder_btn = gr.Button(
|
| 105 |
value="Placeholder", variant="primary", size="sm"
|
| 106 |
)
|
| 107 |
+
|
| 108 |
with gr.Column(scale=0, min_width=25):
|
| 109 |
pass
|
| 110 |
with gr.Column(
|
| 111 |
scale=2,
|
| 112 |
min_width=400,
|
| 113 |
):
|
| 114 |
+
text_modified = gr.TextArea(
|
| 115 |
label="Transformed Text",
|
| 116 |
lines=10,
|
| 117 |
show_copy_button=True,
|
| 118 |
interactive=False,
|
| 119 |
)
|
| 120 |
+
annotate_btn.click(
|
| 121 |
+
fn=process, inputs=[text_original, annotate_btn], outputs=text_modified
|
| 122 |
+
)
|
| 123 |
redact_btn.click(
|
| 124 |
fn=process,
|
| 125 |
inputs=[
|
| 126 |
text_original,
|
| 127 |
gr.Text(value="redact", visible=False),
|
| 128 |
],
|
| 129 |
+
outputs=text_modified,
|
| 130 |
)
|
| 131 |
anonymize_btn.click(
|
| 132 |
fn=process,
|
|
|
|
| 134 |
text_original,
|
| 135 |
gr.Text(value="synthetic", visible=False),
|
| 136 |
],
|
| 137 |
+
outputs=text_modified,
|
| 138 |
)
|
| 139 |
placeholder_btn.click(
|
| 140 |
fn=process,
|
| 141 |
inputs=[
|
| 142 |
text_original,
|
| 143 |
+
gr.Text(value="placeholder", visible=False),
|
| 144 |
],
|
| 145 |
+
outputs=text_modified,
|
| 146 |
)
|
| 147 |
with gr.Row():
|
| 148 |
example_selector = gr.Dropdown(
|
| 149 |
examples_truncated, type="index", label="Examples"
|
| 150 |
)
|
| 151 |
example_selector.select(
|
| 152 |
+
get_full_example, inputs=example_selector, outputs=[text_original]
|
| 153 |
)
|
| 154 |
+
with gr.Accordion(label="Help Panel", open=False):
|
| 155 |
+
gr.Markdown(value=policy_help_string)
|
| 156 |
+
|
| 157 |
demo.queue().launch()
|