BtB-ExpC commited on
Commit
a21041f
·
1 Parent(s): ed14152

Normalizing whitespace & adding copy button

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -69,12 +69,19 @@ def insert_points(text):
69
  text = ''.join(result)
70
 
71
  # -----------------------------
72
- # 4) CLEAN UP: Remove excess newlines
73
  # -----------------------------
74
- # Remove extra blank lines before tags
75
- text = re.sub(r'\n\n+(\[POSITION_)', r'\n\1', text)
76
- # Remove extra blank lines at the beginning
 
 
 
 
 
 
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(label="Processed Text with Tags"),
 
 
 
95
  title="Insert Point Tagger",
96
  description=(
97
- "This processor inserts numbered tags between paragraphs and before #-headers"
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