Spaces:
Sleeping
Sleeping
Update predictor.py
Browse files- predictor.py +11 -4
predictor.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
from utilities import predict
|
| 4 |
|
| 5 |
st.set_page_config(layout="wide")
|
|
@@ -32,6 +33,14 @@ def result_form(result, user_label):
|
|
| 32 |
predicted_label = max(probabilities, key=probabilities.get)
|
| 33 |
return probabilities[user_label] < 0.35 or predicted_label != user_label
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def create_expander_with_check_button(label, title, context, predict_func):
|
| 36 |
claim_key = f"{label}_input"
|
| 37 |
evidence_key = f"{label}_evidence_selected"
|
|
@@ -50,10 +59,8 @@ def create_expander_with_check_button(label, title, context, predict_func):
|
|
| 50 |
result = predict_func(context, claim)
|
| 51 |
if result_form(result, label):
|
| 52 |
if label != 'NEI': # NEI does not require evidence
|
| 53 |
-
# Split context into sentences
|
| 54 |
-
sentences =
|
| 55 |
-
# Remove leading/trailing whitespaces
|
| 56 |
-
sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
|
| 57 |
# Display available sentences as options
|
| 58 |
st.multiselect(f"Selected evidence for {label}", sentences, default=st.session_state[label_e_ops], key=evidence_key)
|
| 59 |
else:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import re
|
| 4 |
from utilities import predict
|
| 5 |
|
| 6 |
st.set_page_config(layout="wide")
|
|
|
|
| 33 |
predicted_label = max(probabilities, key=probabilities.get)
|
| 34 |
return probabilities[user_label] < 0.35 or predicted_label != user_label
|
| 35 |
|
| 36 |
+
def split_sentences(context):
|
| 37 |
+
# Regular expression to split text into sentences
|
| 38 |
+
pattern = r'(?<!\.\.\.)(?<=[.!?]) +|\.\.\.(?= )'
|
| 39 |
+
sentences = re.split(pattern, context)
|
| 40 |
+
# Remove leading/trailing whitespaces
|
| 41 |
+
sentences = [sentence.strip() for sentence in sentences if sentence.strip()]
|
| 42 |
+
return sentences
|
| 43 |
+
|
| 44 |
def create_expander_with_check_button(label, title, context, predict_func):
|
| 45 |
claim_key = f"{label}_input"
|
| 46 |
evidence_key = f"{label}_evidence_selected"
|
|
|
|
| 59 |
result = predict_func(context, claim)
|
| 60 |
if result_form(result, label):
|
| 61 |
if label != 'NEI': # NEI does not require evidence
|
| 62 |
+
# Split context into sentences with special handling for ellipses
|
| 63 |
+
sentences = split_sentences(context)
|
|
|
|
|
|
|
| 64 |
# Display available sentences as options
|
| 65 |
st.multiselect(f"Selected evidence for {label}", sentences, default=st.session_state[label_e_ops], key=evidence_key)
|
| 66 |
else:
|