Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -898,47 +898,51 @@ def analyze_single_message(text, thresholds):
|
|
| 898 |
logger.debug("Empty text, returning zeros")
|
| 899 |
return 0.0, [], [], {"label": "none"}, 1, 0.0, None, {'assessment': 'neutral', 'confidence': 0.5}
|
| 900 |
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
|
| 943 |
# EARLY SUPPORTIVE MESSAGE CHECK
|
| 944 |
innocent_indicators = [
|
|
|
|
| 898 |
logger.debug("Empty text, returning zeros")
|
| 899 |
return 0.0, [], [], {"label": "none"}, 1, 0.0, None, {'assessment': 'neutral', 'confidence': 0.5}
|
| 900 |
|
| 901 |
+
# BOUNDARY HEALTH CHECK - Add this new section
|
| 902 |
+
logger.debug("\n🛡️ BOUNDARY HEALTH ANALYSIS")
|
| 903 |
+
logger.debug("-" * 40)
|
| 904 |
+
boundary_class, boundary_confidence = predict_boundary_health(text) # Unpack the tuple
|
| 905 |
+
boundary_assessment = get_boundary_assessment(text, boundary_class, boundary_confidence)
|
| 906 |
+
logger.debug(f"Boundary Class: {boundary_class} ({['Respected', 'Violated', 'Dismissed', 'Manipulative'][boundary_class]})")
|
| 907 |
+
logger.debug(f"Boundary Confidence: {boundary_confidence:.3f}")
|
| 908 |
+
logger.debug(f"Boundary Assessment: {boundary_assessment['label']}")
|
| 909 |
+
|
| 910 |
+
# Get sentiment EARLY - BEFORE any early returns
|
| 911 |
+
sent_inputs = sentiment_tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 912 |
+
sent_inputs = {k: v.to(device) for k, v in sent_inputs.items()}
|
| 913 |
+
with torch.no_grad():
|
| 914 |
+
sent_logits = sentiment_model(**sent_inputs).logits[0]
|
| 915 |
+
sent_probs = torch.softmax(sent_logits, dim=-1).cpu().numpy()
|
| 916 |
+
|
| 917 |
+
# Add detailed logging
|
| 918 |
+
logger.debug("\n🎭 SENTIMENT ANALYSIS DETAILS")
|
| 919 |
+
logger.debug(f"Raw logits: {sent_logits}")
|
| 920 |
+
logger.debug(f"Probabilities: supportive={sent_probs[0]:.3f}, undermining={sent_probs[1]:.3f}")
|
| 921 |
+
|
| 922 |
+
# Make sure we're using the correct index mapping
|
| 923 |
+
sentiment = SENTIMENT_LABELS[int(np.argmax(sent_probs))]
|
| 924 |
+
logger.debug(f"Selected sentiment: {sentiment}")
|
| 925 |
+
|
| 926 |
+
# UPDATE THE OVERRIDE CONDITION:
|
| 927 |
+
# Now we need to check if boundary_class == 0 (Respected) instead of checking a probability
|
| 928 |
+
if (boundary_class != 0 and # Not "Respected"
|
| 929 |
+
boundary_confidence < 0.7 and
|
| 930 |
+
sentiment == "supportive" and
|
| 931 |
+
len(text.split()) > 50 and
|
| 932 |
+
any(phrase in text.lower() for phrase in [
|
| 933 |
+
"i need you to", "i want to understand", "this isn't about",
|
| 934 |
+
"about accuracy", "willing to do something different"
|
| 935 |
+
])):
|
| 936 |
+
|
| 937 |
+
logger.debug("🔄 Boundary assessment override: Sophisticated healthy boundary detected")
|
| 938 |
+
boundary_assessment = {
|
| 939 |
+
'assessment': 'healthy',
|
| 940 |
+
'label': 'Healthy Boundary (Sophisticated)',
|
| 941 |
+
'confidence': 0.85,
|
| 942 |
+
'description': 'Complex but healthy boundary-setting communication',
|
| 943 |
+
'recommendations': ['Continue this thoughtful, direct approach']
|
| 944 |
+
}
|
| 945 |
+
|
| 946 |
|
| 947 |
# EARLY SUPPORTIVE MESSAGE CHECK
|
| 948 |
innocent_indicators = [
|