Update app.py
Browse files
app.py
CHANGED
|
@@ -39,7 +39,7 @@ from rule_detector import DEFAULT_RULEBASE_ALLOWED_ENTITY_TYPES, detect_by_rules
|
|
| 39 |
|
| 40 |
DEFAULT_MODEL_ID = os.getenv("MODEL_ID", "AITeamUIT/gliner2-multi-full-21-6-base")
|
| 41 |
DEFAULT_THRESHOLD = float(os.getenv("THRESHOLD", "0.5"))
|
| 42 |
-
DEFAULT_CHUNK_CHARS = int(os.getenv("CHUNK_CHARS", "
|
| 43 |
MAX_WIDTH = int(os.getenv("MAX_WIDTH", "30"))
|
| 44 |
|
| 45 |
PII_LABEL_DESCRIPTIONS: Dict[str, str] = {
|
|
@@ -126,22 +126,21 @@ NUMERIC_MASK_LABELS = {
|
|
| 126 |
try:
|
| 127 |
from gliner2.processor import WhitespaceTokenSplitter
|
| 128 |
|
| 129 |
-
|
| 130 |
IMPROVED_PATTERN = re.compile(
|
| 131 |
r"""
|
| 132 |
# Scheme / www URL
|
| 133 |
(?:(?:https?|ftp)://|www\.)[^\s<>"'`{}|\\^]*[^\s<>"'`{}|\\^.,;:!?()\[\]]
|
| 134 |
-
|
| 135 |
# Email address
|
| 136 |
|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}
|
| 137 |
-
|
| 138 |
# Social/user handle
|
| 139 |
|@[a-z0-9_](?:[a-z0-9_.-]{0,28}[a-z0-9_])?
|
| 140 |
-
|
| 141 |
# IPv4 address. Allows sentence punctuation after the IP, but avoids
|
| 142 |
# matching inside a longer dotted numeric sequence.
|
| 143 |
|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}(?=$|[^\w])(?!\.\d)
|
| 144 |
-
|
| 145 |
# IPv6 address, including compressed forms and optional zone IDs.
|
| 146 |
|(?:
|
| 147 |
(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}
|
|
@@ -154,13 +153,13 @@ try:
|
|
| 154 |
|:(?:(?::[0-9a-f]{1,4}){1,7}|:)
|
| 155 |
|(?:[0-9a-f]{1,4}:){1,7}:
|
| 156 |
)(?:%[0-9a-z_.-]+)?(?![0-9a-f:])
|
| 157 |
-
|
| 158 |
# Strict JWT-like token
|
| 159 |
|[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}
|
| 160 |
-
|
| 161 |
# Shorter dot-separated token-like string, e.g. sk-abc.def.ghi
|
| 162 |
|(?=[a-z0-9_.-]*[-_\d])[a-z0-9_-]{2,}(?:\.[a-z0-9_-]{2,}){2,}
|
| 163 |
-
|
| 164 |
# Bare domain / URL-like candidate. Validation belongs downstream; this
|
| 165 |
# tokenizer only keeps plausible URL spans from being split into pieces.
|
| 166 |
|(?<![\w@])
|
|
@@ -169,18 +168,18 @@ try:
|
|
| 169 |
(?=$|/|:|[^\w-])
|
| 170 |
(?::\d{2,5})?
|
| 171 |
(?:/(?:[^\s<>"'`{}|\\^]*[^\s<>"'`{}|\\^.,;:!?()\[\]])?)?
|
| 172 |
-
|
| 173 |
# Letter-containing word token: must have at least one letter or
|
| 174 |
# underscore (the [^\W\d] anchor). Freely joins via hyphen/underscore,
|
| 175 |
# so Jean-Pierre, B-52, 30A-12345, well-known, and 3D-model all stay
|
| 176 |
# atomic. The leading \d* allows digit-run prefixes (30A, 13th, 3D).
|
| 177 |
|(?:\d*[^\W\d]\w*)(?:[-_]\w+)*
|
| 178 |
-
|
| 179 |
# Pure digit sequence: hyphens/underscores only join other digit groups.
|
| 180 |
# "555-1234" stays atomic; "13-tuổi" → "13" / "-" / "tuổi" so the
|
| 181 |
# numeric entity (AGE, DATE, …) is not fused with the surrounding word.
|
| 182 |
|\d+(?:[-_]\d+)*
|
| 183 |
-
|
| 184 |
# Fallback: any single non-space character.
|
| 185 |
|\S
|
| 186 |
""",
|
|
|
|
| 39 |
|
| 40 |
DEFAULT_MODEL_ID = os.getenv("MODEL_ID", "AITeamUIT/gliner2-multi-full-21-6-base")
|
| 41 |
DEFAULT_THRESHOLD = float(os.getenv("THRESHOLD", "0.5"))
|
| 42 |
+
DEFAULT_CHUNK_CHARS = int(os.getenv("CHUNK_CHARS", "1000"))
|
| 43 |
MAX_WIDTH = int(os.getenv("MAX_WIDTH", "30"))
|
| 44 |
|
| 45 |
PII_LABEL_DESCRIPTIONS: Dict[str, str] = {
|
|
|
|
| 126 |
try:
|
| 127 |
from gliner2.processor import WhitespaceTokenSplitter
|
| 128 |
|
|
|
|
| 129 |
IMPROVED_PATTERN = re.compile(
|
| 130 |
r"""
|
| 131 |
# Scheme / www URL
|
| 132 |
(?:(?:https?|ftp)://|www\.)[^\s<>"'`{}|\\^]*[^\s<>"'`{}|\\^.,;:!?()\[\]]
|
| 133 |
+
|
| 134 |
# Email address
|
| 135 |
|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}
|
| 136 |
+
|
| 137 |
# Social/user handle
|
| 138 |
|@[a-z0-9_](?:[a-z0-9_.-]{0,28}[a-z0-9_])?
|
| 139 |
+
|
| 140 |
# IPv4 address. Allows sentence punctuation after the IP, but avoids
|
| 141 |
# matching inside a longer dotted numeric sequence.
|
| 142 |
|(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}(?=$|[^\w])(?!\.\d)
|
| 143 |
+
|
| 144 |
# IPv6 address, including compressed forms and optional zone IDs.
|
| 145 |
|(?:
|
| 146 |
(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}
|
|
|
|
| 153 |
|:(?:(?::[0-9a-f]{1,4}){1,7}|:)
|
| 154 |
|(?:[0-9a-f]{1,4}:){1,7}:
|
| 155 |
)(?:%[0-9a-z_.-]+)?(?![0-9a-f:])
|
| 156 |
+
|
| 157 |
# Strict JWT-like token
|
| 158 |
|[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}\.[a-z0-9_-]{10,}
|
| 159 |
+
|
| 160 |
# Shorter dot-separated token-like string, e.g. sk-abc.def.ghi
|
| 161 |
|(?=[a-z0-9_.-]*[-_\d])[a-z0-9_-]{2,}(?:\.[a-z0-9_-]{2,}){2,}
|
| 162 |
+
|
| 163 |
# Bare domain / URL-like candidate. Validation belongs downstream; this
|
| 164 |
# tokenizer only keeps plausible URL spans from being split into pieces.
|
| 165 |
|(?<![\w@])
|
|
|
|
| 168 |
(?=$|/|:|[^\w-])
|
| 169 |
(?::\d{2,5})?
|
| 170 |
(?:/(?:[^\s<>"'`{}|\\^]*[^\s<>"'`{}|\\^.,;:!?()\[\]])?)?
|
| 171 |
+
|
| 172 |
# Letter-containing word token: must have at least one letter or
|
| 173 |
# underscore (the [^\W\d] anchor). Freely joins via hyphen/underscore,
|
| 174 |
# so Jean-Pierre, B-52, 30A-12345, well-known, and 3D-model all stay
|
| 175 |
# atomic. The leading \d* allows digit-run prefixes (30A, 13th, 3D).
|
| 176 |
|(?:\d*[^\W\d]\w*)(?:[-_]\w+)*
|
| 177 |
+
|
| 178 |
# Pure digit sequence: hyphens/underscores only join other digit groups.
|
| 179 |
# "555-1234" stays atomic; "13-tuổi" → "13" / "-" / "tuổi" so the
|
| 180 |
# numeric entity (AGE, DATE, …) is not fused with the surrounding word.
|
| 181 |
|\d+(?:[-_]\d+)*
|
| 182 |
+
|
| 183 |
# Fallback: any single non-space character.
|
| 184 |
|\S
|
| 185 |
""",
|