Spaces:
Sleeping
Sleeping
Normalizing whitespace & adding copy button
Browse files
app.py
CHANGED
|
@@ -69,12 +69,19 @@ def insert_points(text):
|
|
| 69 |
text = ''.join(result)
|
| 70 |
|
| 71 |
# -----------------------------
|
| 72 |
-
# 4) CLEAN UP:
|
| 73 |
# -----------------------------
|
| 74 |
-
#
|
| 75 |
-
text = re.sub(r'\n\
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
text = re.sub(r'^\n+', '', text)
|
|
|
|
| 78 |
# Ensure no consecutive tags
|
| 79 |
text = re.sub(r'(\[POSITION_\d{3}]\n)\s*\[POSITION_\d{3}]', r'\1', text)
|
| 80 |
|
|
@@ -91,11 +98,13 @@ demo = gr.Interface(
|
|
| 91 |
placeholder="Paste your text here...",
|
| 92 |
label="Your Input Text"
|
| 93 |
),
|
| 94 |
-
outputs=gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 95 |
title="Insert Point Tagger",
|
| 96 |
description=(
|
| 97 |
-
|
| 98 |
-
|
| 99 |
),
|
| 100 |
)
|
| 101 |
|
|
|
|
| 69 |
text = ''.join(result)
|
| 70 |
|
| 71 |
# -----------------------------
|
| 72 |
+
# 4) CLEAN UP: Normalize spacing around tags
|
| 73 |
# -----------------------------
|
| 74 |
+
# Ensure exactly one newline before each tag
|
| 75 |
+
text = re.sub(r'([^\n])\[POSITION_', r'\1\n[POSITION_', text)
|
| 76 |
+
text = re.sub(r'\n+(\[POSITION_)', r'\n\1', text)
|
| 77 |
+
|
| 78 |
+
# Ensure exactly one newline after each tag
|
| 79 |
+
text = re.sub(r'(\[POSITION_\d{3}])([^\n])', r'\1\n\2', text)
|
| 80 |
+
text = re.sub(r'(\[POSITION_\d{3}])\n+', r'\1\n', text)
|
| 81 |
+
|
| 82 |
+
# Remove any newlines at the very beginning of the text
|
| 83 |
text = re.sub(r'^\n+', '', text)
|
| 84 |
+
|
| 85 |
# Ensure no consecutive tags
|
| 86 |
text = re.sub(r'(\[POSITION_\d{3}]\n)\s*\[POSITION_\d{3}]', r'\1', text)
|
| 87 |
|
|
|
|
| 98 |
placeholder="Paste your text here...",
|
| 99 |
label="Your Input Text"
|
| 100 |
),
|
| 101 |
+
outputs=gr.Textbox(
|
| 102 |
+
label="Processed Text with Tags",
|
| 103 |
+
show_copy_button=True # Enable copy button
|
| 104 |
+
),
|
| 105 |
title="Insert Point Tagger",
|
| 106 |
description=(
|
| 107 |
+
"This processor inserts numbered tags between paragraphs and before #-headers"
|
|
|
|
| 108 |
),
|
| 109 |
)
|
| 110 |
|