Spaces:
Running
Running
Update app_3.py
Browse files
app_3.py
CHANGED
@@ -136,19 +136,26 @@ def extract_arguments(text, tokenizer, model, beam_search=True):
|
|
136 |
def mark_text_by_position(original_text, start_token, end_token, color):
|
137 |
"""Marks text in the original string based on character positions."""
|
138 |
# Inserts tags into the original text based on token offsets.
|
|
|
|
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
start_idx, end_idx = offset_mapping[start_token][0], offset_mapping[end_token][1]
|
142 |
-
|
143 |
-
if start_idx is not None and end_idx is not None and start_idx <= end_idx:
|
144 |
-
return (
|
145 |
-
original_text[:start_idx]
|
146 |
-
+ f"<mark style='background-color:{color}; padding:2px; border-radius:4px;'>"
|
147 |
-
+ original_text[start_idx:end_idx]
|
148 |
-
+ "</mark>"
|
149 |
-
+ original_text[end_idx:]
|
150 |
-
)
|
151 |
return original_text
|
|
|
152 |
|
153 |
cause_text1 = mark_text_by_position(input_text, start_cause1, end_cause1, "#FFD700") # Gold for cause
|
154 |
effect_text1 = mark_text_by_position(input_text, start_effect1, end_effect1, "#90EE90") # Light green for effect
|
@@ -163,7 +170,7 @@ def extract_arguments(text, tokenizer, model, beam_search=True):
|
|
163 |
|
164 |
st.title("Causal Relation Extraction")
|
165 |
input_text = st.text_area("Enter your text here:", height=300)
|
166 |
-
beam_search = st.radio("Enable Beam Search?", ('No', 'Yes')) == 'Yes'
|
167 |
|
168 |
|
169 |
if st.button("Extract_Now_1"):
|
|
|
136 |
def mark_text_by_position(original_text, start_token, end_token, color):
|
137 |
"""Marks text in the original string based on character positions."""
|
138 |
# Inserts tags into the original text based on token offsets.
|
139 |
+
|
140 |
+
if start_token is not None and end_token is not None and start_token <= end_token:
|
141 |
|
142 |
+
start_idx, end_idx = offset_mapping[start_token][0], offset_mapping[end_token][1]
|
143 |
+
|
144 |
+
if start_idx is not None and end_idx is not None and start_idx < end_idx:
|
145 |
+
return (
|
146 |
+
original_text[:start_idx]
|
147 |
+
+ f"<mark style='background-color:{color}; padding:2px; border-radius:4px;'>"
|
148 |
+
+ original_text[start_idx:end_idx]
|
149 |
+
+ "</mark>"
|
150 |
+
+ original_text[end_idx:]
|
151 |
+
)
|
152 |
+
|
153 |
+
if start_token > end_token:
|
154 |
+
st.write("The prediction is not correct: The position of the predicted end token comes before the position of the start token.")
|
155 |
+
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
return original_text
|
158 |
+
|
159 |
|
160 |
cause_text1 = mark_text_by_position(input_text, start_cause1, end_cause1, "#FFD700") # Gold for cause
|
161 |
effect_text1 = mark_text_by_position(input_text, start_effect1, end_effect1, "#90EE90") # Light green for effect
|
|
|
170 |
|
171 |
st.title("Causal Relation Extraction")
|
172 |
input_text = st.text_area("Enter your text here:", height=300)
|
173 |
+
beam_search = st.radio("Enable Position Selector & Beam Search?", ('No', 'Yes')) == 'Yes'
|
174 |
|
175 |
|
176 |
if st.button("Extract_Now_1"):
|