Spaces:
Paused
Paused
Carlos Rosas
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -122,25 +122,13 @@ class pleiasBot:
|
|
122 |
return None, None, None
|
123 |
|
124 |
def format_references(text):
|
125 |
-
|
126 |
-
ref_pattern = r'<ref name="([^"]+)">"([^"]+)"</ref>'
|
127 |
-
references = re.finditer(ref_pattern, text)
|
128 |
|
129 |
-
# Create a mapping of reference IDs to their order of appearance
|
130 |
-
ref_mapping = {}
|
131 |
-
ref_number = 1
|
132 |
-
for match in references:
|
133 |
-
ref_id = match.group(1)
|
134 |
-
if ref_id not in ref_mapping:
|
135 |
-
ref_mapping[ref_id] = ref_number
|
136 |
-
ref_number += 1
|
137 |
-
|
138 |
-
# Now process the text with the consistent reference numbers
|
139 |
parts = []
|
140 |
current_pos = 0
|
141 |
-
|
142 |
-
|
143 |
-
for match in re.finditer(ref_pattern
|
144 |
# Add text before the reference
|
145 |
text_before = text[current_pos:match.start()].rstrip()
|
146 |
parts.append(text_before)
|
@@ -149,11 +137,12 @@ def format_references(text):
|
|
149 |
ref_id = match.group(1)
|
150 |
ref_text = match.group(2).strip()
|
151 |
|
152 |
-
#
|
153 |
-
tooltip_html = f'<span class="tooltip"><strong>[{
|
154 |
parts.append(tooltip_html)
|
155 |
|
156 |
current_pos = match.end()
|
|
|
157 |
|
158 |
# Add any remaining text
|
159 |
parts.append(text[current_pos:])
|
|
|
122 |
return None, None, None
|
123 |
|
124 |
def format_references(text):
|
125 |
+
ref_pattern = r'<ref name="([^"]+)">"([^"]+)"</ref>\.\s*'
|
|
|
|
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
parts = []
|
128 |
current_pos = 0
|
129 |
+
ref_number = 1
|
130 |
+
|
131 |
+
for match in re.finditer(ref_pattern, text):
|
132 |
# Add text before the reference
|
133 |
text_before = text[current_pos:match.start()].rstrip()
|
134 |
parts.append(text_before)
|
|
|
137 |
ref_id = match.group(1)
|
138 |
ref_text = match.group(2).strip()
|
139 |
|
140 |
+
# Add the reference with sequential numbering
|
141 |
+
tooltip_html = f'<span class="tooltip"><strong>[{ref_number}]</strong><span class="tooltiptext"><strong>{ref_id}</strong>: {ref_text}</span></span>.<br>'
|
142 |
parts.append(tooltip_html)
|
143 |
|
144 |
current_pos = match.end()
|
145 |
+
ref_number += 1
|
146 |
|
147 |
# Add any remaining text
|
148 |
parts.append(text[current_pos:])
|