Spaces:
Sleeping
Sleeping
Rename app_6.py to app_7.py
Browse files- app_6.py → app_7.py +10 -2
app_6.py → app_7.py
RENAMED
@@ -163,10 +163,18 @@ def extract_arguments(text, tokenizer, model, beam_search=True):
|
|
163 |
list2 = [start_cause2, end_cause2, start_effect2, end_effect2, start_signal, end_signal]
|
164 |
return cause1, cause2, effect1, effect2, signal, list1, list2
|
165 |
|
|
|
166 |
def mark_text(original_text, span, color):
|
167 |
-
"""Replace extracted span with a colored background marker."""
|
168 |
if span:
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
return original_text # Return unchanged text if no span is found
|
171 |
|
172 |
st.title("Causal Relation Extraction")
|
|
|
163 |
list2 = [start_cause2, end_cause2, start_effect2, end_effect2, start_signal, end_signal]
|
164 |
return cause1, cause2, effect1, effect2, signal, list1, list2
|
165 |
|
166 |
+
|
167 |
def mark_text(original_text, span, color):
|
168 |
+
"""Replace extracted span with a colored background marker, starting at the exact first token."""
|
169 |
if span:
|
170 |
+
# Get the starting index of the span in the original text
|
171 |
+
start_idx = original_text.find(span)
|
172 |
+
|
173 |
+
# Ensure the span is found and replace it with <mark> tags directly at the first token's position
|
174 |
+
if start_idx != -1:
|
175 |
+
# Replace the span with the mark tag at the exact first token position
|
176 |
+
return re.sub(re.escape(span), f"<mark style='background-color:{color}; padding:2px; border-radius:4px;'>{span}</mark>", original_text, flags=re.IGNORECASE)
|
177 |
+
|
178 |
return original_text # Return unchanged text if no span is found
|
179 |
|
180 |
st.title("Causal Relation Extraction")
|