anamargarida commited on
Commit
b44a561
·
verified ·
1 Parent(s): 4377058

Rename app_4.py to app_5.py

Browse files
Files changed (1) hide show
  1. app_4.py → app_5.py +22 -19
app_4.py → app_5.py RENAMED
@@ -136,27 +136,25 @@ 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
- 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
162
 
@@ -184,10 +182,15 @@ if st.button("Extract"):
184
 
185
  # Display first relation
186
  st.markdown(f"<strong>Relation 1:</strong>", unsafe_allow_html=True)
187
- st.markdown(f"**Cause:** {cause_text1}", unsafe_allow_html=True)
188
- st.markdown(f"**Effect:** {effect_text1}", unsafe_allow_html=True)
189
- st.markdown(f"**Signal:** {signal_text}", unsafe_allow_html=True)
190
 
 
 
 
 
 
 
 
 
191
  # Display second relation if beam search is enabled
192
  if beam_search:
193
 
 
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
+ if start_token is not None and end_token is not None:
140
+ if start_token <= end_token:
141
 
 
142
 
143
+ start_idx, end_idx = offset_mapping[start_token][0], offset_mapping[end_token][1]
144
+
145
+ if start_idx is not None and end_idx is not None and start_idx < end_idx:
146
+ return (
147
+ original_text[:start_idx]
148
+ + f"<mark style='background-color:{color}; padding:2px; border-radius:4px;'>"
149
+ + original_text[start_idx:end_idx]
150
+ + "</mark>"
151
+ + original_text[end_idx:]
152
+ )
153
+
154
+ return None
155
 
 
 
 
156
 
 
157
 
 
158
  cause_text1 = mark_text_by_position(input_text, start_cause1, end_cause1, "#FFD700") # Gold for cause
159
  effect_text1 = mark_text_by_position(input_text, start_effect1, end_effect1, "#90EE90") # Light green for effect
160
 
 
182
 
183
  # Display first relation
184
  st.markdown(f"<strong>Relation 1:</strong>", unsafe_allow_html=True)
 
 
 
185
 
186
+ if cause_text1 is None or effect_text1 is None:
187
+ st.write("The prediction is not correct for at least one span: The position of the predicted end token comes before the position of the start token.")
188
+ else:
189
+ st.markdown(f"**Cause:** {cause_text1}", unsafe_allow_html=True)
190
+ st.markdown(f"**Effect:** {effect_text1}", unsafe_allow_html=True)
191
+ st.markdown(f"**Signal:** {signal_text}", unsafe_allow_html=True)
192
+
193
+
194
  # Display second relation if beam search is enabled
195
  if beam_search:
196