File size: 2,390 Bytes
c83cd7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
from backend.api.claims import classify_claim
from backend.api.tone_intent import detect_tone_and_intent
from backend.api.fact_check import fact_check_claim
import json
# final verdict function
def get_final_verdict(claim_text: str) -> dict:
try:
# Classify the claim
classification = classify_claim(claim_text)
classification_type = classification.get("category", "Unknown")
# If the claim is not a factual claim, return an early verdict
if classification_type != "Factual Claim":
return {
"claim": claim_text,
"classification": classification_type,
"verdict": "Claim is not factual.",
"reasoning": "The claim does not fall under factual category. It is an opinion, irrelevant, or vague."
}
# Detect the tone of the claim
tone_intent = detect_tone_and_intent(claim_text)
tone = tone_intent.get("tone", "Unknown")
# If the tone is positive (Neutral, Persuasive, Humorous), proceed to fact-check
if tone in ["Neutral", "Persuasive", "Humorous"]:
fact_check_result = fact_check_claim(claim_text)
# Fact-checking results
verdict = fact_check_result.get("fact_check_result", "Unknown")
evidence = fact_check_result.get("evidence", "No evidence available.")
sources = fact_check_result.get("sources", [])
reasoning = fact_check_result.get("reasoning", "No reasoning available.")
return {
"claim": claim_text,
"classification": classification_type,
"tone": tone,
"fact_check_result": verdict,
"evidence": evidence,
"sources": sources,
"reasoning": reasoning
}
else:
return {
"claim": claim_text,
"classification": classification_type,
"tone": tone,
"verdict": "Claim has a non-positive tone.",
"reasoning": "The claim's tone is considered negative or misleading, hence not processed for fact-checking."
}
except Exception as e:
return {"error": f"An error occurred while processing the claim: {str(e)}"}
|