Upload folder using huggingface_hub
Browse files
server.py
CHANGED
|
@@ -206,6 +206,34 @@ if GLINER_AVAILABLE:
|
|
| 206 |
except Exception as e:
|
| 207 |
print(f"[!] Could not load GLiNER: {e}")
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
analyzer = AnalyzerEngine(nlp_engine=nlp_engine, registry=registry, supported_languages=["en"])
|
| 210 |
anonymizer = AnonymizerEngine()
|
| 211 |
print("[+] Presidio engines ready!")
|
|
|
|
| 206 |
except Exception as e:
|
| 207 |
print(f"[!] Could not load GLiNER: {e}")
|
| 208 |
|
| 209 |
+
# ---- Custom Informal Date Recognizer ----
|
| 210 |
+
import re
|
| 211 |
+
from presidio_analyzer import Pattern, PatternRecognizer
|
| 212 |
+
|
| 213 |
+
MONTHS = r"(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|jun(?:e)?|jul(?:y)?|aug(?:ust)?|sep(?:t(?:ember)?)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)"
|
| 214 |
+
|
| 215 |
+
informal_date_patterns = [
|
| 216 |
+
# "9th march", "10th march", "1st january", "23rd april"
|
| 217 |
+
Pattern("ordinal_month", rf"\b\d{{1,2}}(?:st|nd|rd|th)\s+{MONTHS}\b", 0.85),
|
| 218 |
+
# "march 9th", "april 10th", "january 1st"
|
| 219 |
+
Pattern("month_ordinal", rf"\b{MONTHS}\s+\d{{1,2}}(?:st|nd|rd|th)?\b", 0.85),
|
| 220 |
+
# "march 2024", "april 2025"
|
| 221 |
+
Pattern("month_year", rf"\b{MONTHS}\s+\d{{4}}\b", 0.80),
|
| 222 |
+
# "9th march 2024"
|
| 223 |
+
Pattern("ordinal_month_year", rf"\b\d{{1,2}}(?:st|nd|rd|th)\s+{MONTHS}\s+\d{{4}}\b", 0.90),
|
| 224 |
+
# standalone months in context: "in march", "on april", "by december"
|
| 225 |
+
Pattern("standalone_month", rf"\b(?:in|on|by|before|after|since|until|during)\s+{MONTHS}\b", 0.70),
|
| 226 |
+
]
|
| 227 |
+
|
| 228 |
+
date_recognizer = PatternRecognizer(
|
| 229 |
+
supported_entity="DATE_TIME",
|
| 230 |
+
name="InformalDateRecognizer",
|
| 231 |
+
patterns=informal_date_patterns,
|
| 232 |
+
supported_language="en",
|
| 233 |
+
)
|
| 234 |
+
registry.add_recognizer(date_recognizer)
|
| 235 |
+
print("[+] Informal date recognizer added!")
|
| 236 |
+
|
| 237 |
analyzer = AnalyzerEngine(nlp_engine=nlp_engine, registry=registry, supported_languages=["en"])
|
| 238 |
anonymizer = AnonymizerEngine()
|
| 239 |
print("[+] Presidio engines ready!")
|