Spaces:
Runtime error
Runtime error
Rename pipelines/anonyize.py to pipelines/anonymize.py
Browse files
pipelines/{anonyize.py → anonymize.py}
RENAMED
|
@@ -8,7 +8,6 @@ RE_EMAIL = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
|
|
| 8 |
RE_PHONE = re.compile(r"(?:\+?\d{1,3}[ -]?)?(?:\(\d{2,4}\)[ -]?)?\d{2,4}[ -]?\d{2,4}[ -]?\d{3,4}")
|
| 9 |
RE_NAME = re.compile(r"(?:(?:氏名[::]?)[\t ]*)(\S+)")
|
| 10 |
|
| 11 |
-
|
| 12 |
def anonymize_text(text: str):
|
| 13 |
anon_map = {}
|
| 14 |
|
|
@@ -36,21 +35,19 @@ def anonymize_text(text: str):
|
|
| 36 |
|
| 37 |
return t, anon_map
|
| 38 |
|
| 39 |
-
|
| 40 |
def render_anonymized_pdf(text: str) -> bytes:
|
| 41 |
buf = io.BytesIO()
|
| 42 |
c = canvas.Canvas(buf, pagesize=A4)
|
| 43 |
-
width, height = A4
|
| 44 |
|
| 45 |
margin = 15 * mm
|
| 46 |
line_height = 5 * mm
|
| 47 |
x = margin
|
| 48 |
-
y =
|
| 49 |
|
| 50 |
for line in text.splitlines():
|
| 51 |
if y < margin:
|
| 52 |
c.showPage()
|
| 53 |
-
y =
|
| 54 |
c.drawString(x, y, line[:1200])
|
| 55 |
y -= line_height
|
| 56 |
|
|
|
|
| 8 |
RE_PHONE = re.compile(r"(?:\+?\d{1,3}[ -]?)?(?:\(\d{2,4}\)[ -]?)?\d{2,4}[ -]?\d{2,4}[ -]?\d{3,4}")
|
| 9 |
RE_NAME = re.compile(r"(?:(?:氏名[::]?)[\t ]*)(\S+)")
|
| 10 |
|
|
|
|
| 11 |
def anonymize_text(text: str):
|
| 12 |
anon_map = {}
|
| 13 |
|
|
|
|
| 35 |
|
| 36 |
return t, anon_map
|
| 37 |
|
|
|
|
| 38 |
def render_anonymized_pdf(text: str) -> bytes:
|
| 39 |
buf = io.BytesIO()
|
| 40 |
c = canvas.Canvas(buf, pagesize=A4)
|
|
|
|
| 41 |
|
| 42 |
margin = 15 * mm
|
| 43 |
line_height = 5 * mm
|
| 44 |
x = margin
|
| 45 |
+
y = A4[1] - margin
|
| 46 |
|
| 47 |
for line in text.splitlines():
|
| 48 |
if y < margin:
|
| 49 |
c.showPage()
|
| 50 |
+
y = A4[1] - margin
|
| 51 |
c.drawString(x, y, line[:1200])
|
| 52 |
y -= line_height
|
| 53 |
|