Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,8 +74,12 @@ def analyze_article(text: str) -> dict:
|
|
| 74 |
sentiment_score = 0.0 # Neutral
|
| 75 |
|
| 76 |
# Emotion Classification
|
| 77 |
-
emotion_results = models["emotion"](safe_text)
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
tone_scores = {res["label"]: res["score"] for res in emotion_results}
|
| 80 |
primary_tone = emotion_results[0]["label"]
|
| 81 |
else:
|
|
@@ -224,10 +228,13 @@ def check_contradiction(text_a: str, text_b: str) -> dict:
|
|
| 224 |
models = _load_nlp_models()
|
| 225 |
premise = text_a[:400]
|
| 226 |
hypothesis = text_b[:400]
|
| 227 |
-
|
| 228 |
nli_input = {"text": premise, "text_pair": hypothesis}
|
| 229 |
-
result = models["nli"](nli_input)
|
| 230 |
|
|
|
|
|
|
|
|
|
|
| 231 |
return {"relationship": result["label"], "confidence": result["score"]}
|
| 232 |
|
| 233 |
|
|
@@ -286,7 +293,7 @@ if st.session_state.results_a and st.session_state.results_b:
|
|
| 286 |
if nli_result:
|
| 287 |
if nli_result["relationship"].upper() == "CONTRADICTION":
|
| 288 |
st.error(f"**NARRATIVE CONTRADICTION** (Confidence: {nli_result['confidence']:.2f}) - These sources are disputing each other's facts.")
|
| 289 |
-
elif nli_result["relationship"] == "ENTAILMENT":
|
| 290 |
st.success(f"**NARRATIVE ALIGNMENT** (Confidence: {nli_result['confidence']:.2f}) - These sources agree on the core premise.")
|
| 291 |
else:
|
| 292 |
st.info(f"**NEUTRAL RELATIONSHIP** - These sources are discussing the topic without direct contradiction or alignment.")
|
|
|
|
| 74 |
sentiment_score = 0.0 # Neutral
|
| 75 |
|
| 76 |
# Emotion Classification
|
| 77 |
+
emotion_results = models["emotion"](safe_text)
|
| 78 |
+
|
| 79 |
+
if isinstance(emotion_results, list) and isinstance(emotion_results[0], list):
|
| 80 |
+
emotion_results = emotion_results[0]
|
| 81 |
+
|
| 82 |
+
if isinstance(emotion_results, list) and len(emotion_results) > 0:
|
| 83 |
tone_scores = {res["label"]: res["score"] for res in emotion_results}
|
| 84 |
primary_tone = emotion_results[0]["label"]
|
| 85 |
else:
|
|
|
|
| 228 |
models = _load_nlp_models()
|
| 229 |
premise = text_a[:400]
|
| 230 |
hypothesis = text_b[:400]
|
| 231 |
+
|
| 232 |
nli_input = {"text": premise, "text_pair": hypothesis}
|
| 233 |
+
result = models["nli"](nli_input)
|
| 234 |
|
| 235 |
+
if isinstance(result, list):
|
| 236 |
+
result = result[0]
|
| 237 |
+
|
| 238 |
return {"relationship": result["label"], "confidence": result["score"]}
|
| 239 |
|
| 240 |
|
|
|
|
| 293 |
if nli_result:
|
| 294 |
if nli_result["relationship"].upper() == "CONTRADICTION":
|
| 295 |
st.error(f"**NARRATIVE CONTRADICTION** (Confidence: {nli_result['confidence']:.2f}) - These sources are disputing each other's facts.")
|
| 296 |
+
elif nli_result["relationship"].upper() == "ENTAILMENT":
|
| 297 |
st.success(f"**NARRATIVE ALIGNMENT** (Confidence: {nli_result['confidence']:.2f}) - These sources agree on the core premise.")
|
| 298 |
else:
|
| 299 |
st.info(f"**NEUTRAL RELATIONSHIP** - These sources are discussing the topic without direct contradiction or alignment.")
|