Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -121,6 +121,7 @@ def evaluate_answer(answer, question, kb):
|
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
|
|
|
| 124 |
key = hash_key(kb, question)
|
| 125 |
if key not in SCHEMA_CACHE:
|
| 126 |
SCHEMA_CACHE[key] = generate_schema_with_llm(kb, question)
|
|
@@ -128,6 +129,7 @@ def evaluate_answer(answer, question, kb):
|
|
| 128 |
schema = SCHEMA_CACHE[key]
|
| 129 |
logs["schema"] = schema
|
| 130 |
|
|
|
|
| 131 |
claims = decompose_answer(answer)
|
| 132 |
logs["claims"] = claims
|
| 133 |
|
|
@@ -149,35 +151,21 @@ def evaluate_answer(answer, question, kb):
|
|
| 149 |
|
| 150 |
logs["coverage"] = coverage
|
| 151 |
|
| 152 |
-
# ---------------- CONTRADICTION CHECK ----------------
|
| 153 |
-
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
# logs["contradictions"] = contradictions
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
relevant_kb = schema.get("required_concepts", [])
|
| 170 |
-
|
| 171 |
-
for claim in claims:
|
| 172 |
-
for sent in relevant_kb:
|
| 173 |
-
probs = softmax_logits(nli_model.predict([(sent, claim)]))
|
| 174 |
-
if probs[0] > CONTRADICTION_THRESHOLD:
|
| 175 |
-
contradictions.append({
|
| 176 |
-
"claim": claim,
|
| 177 |
-
"sentence": sent,
|
| 178 |
-
"confidence": round(probs[0] * 100, 1)
|
| 179 |
-
})
|
| 180 |
|
|
|
|
| 181 |
|
| 182 |
# ---------------- FINAL DECISION ----------------
|
| 183 |
if contradictions:
|
|
@@ -190,6 +178,7 @@ for claim in claims:
|
|
| 190 |
logs["final_verdict"] = verdict
|
| 191 |
return verdict, logs
|
| 192 |
|
|
|
|
| 193 |
# ============================================================
|
| 194 |
# GRADIO UI
|
| 195 |
# ============================================================
|
|
|
|
| 121 |
}
|
| 122 |
}
|
| 123 |
|
| 124 |
+
# ---------------- SCHEMA ----------------
|
| 125 |
key = hash_key(kb, question)
|
| 126 |
if key not in SCHEMA_CACHE:
|
| 127 |
SCHEMA_CACHE[key] = generate_schema_with_llm(kb, question)
|
|
|
|
| 129 |
schema = SCHEMA_CACHE[key]
|
| 130 |
logs["schema"] = schema
|
| 131 |
|
| 132 |
+
# ---------------- ANSWER CLAIMS ----------------
|
| 133 |
claims = decompose_answer(answer)
|
| 134 |
logs["claims"] = claims
|
| 135 |
|
|
|
|
| 151 |
|
| 152 |
logs["coverage"] = coverage
|
| 153 |
|
| 154 |
+
# ---------------- CONTRADICTION CHECK (FIXED) ----------------
|
| 155 |
+
contradictions = []
|
| 156 |
+
relevant_kb = schema.get("required_concepts", [])
|
| 157 |
|
| 158 |
+
for claim in claims:
|
| 159 |
+
for sent in relevant_kb:
|
| 160 |
+
probs = softmax_logits(nli_model.predict([(sent, claim)]))
|
| 161 |
+
if probs[0] > CONTRADICTION_THRESHOLD:
|
| 162 |
+
contradictions.append({
|
| 163 |
+
"claim": claim,
|
| 164 |
+
"sentence": sent,
|
| 165 |
+
"confidence": round(probs[0] * 100, 1)
|
| 166 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
logs["contradictions"] = contradictions
|
| 169 |
|
| 170 |
# ---------------- FINAL DECISION ----------------
|
| 171 |
if contradictions:
|
|
|
|
| 178 |
logs["final_verdict"] = verdict
|
| 179 |
return verdict, logs
|
| 180 |
|
| 181 |
+
|
| 182 |
# ============================================================
|
| 183 |
# GRADIO UI
|
| 184 |
# ============================================================
|