Spaces:
Sleeping
Sleeping
File size: 1,516 Bytes
89fd50e 186fe46 89fd50e |
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 |
from __future__ import annotations
from dataclasses import dataclass
from typing import List, Dict, Any
@dataclass
class NewsArticle:
title: str
content: str
url: str
source: str
published_date: str
scraped_date: str
article_id: str
language: str = "english" # Default to english, matches the JavaScript implementation
def normalize_result(result: Dict[str, Any]) -> Dict[str, Any]:
out = {
"verdict": result.get("verdict", "UNVERIFIED"),
"confidence": result.get("confidence", 0.0),
"reasoning": result.get("reasoning", ""),
"supporting_evidence": result.get("supporting_evidence", []) or [],
"contradicting_evidence": result.get("contradicting_evidence", []) or [],
"context_quality": result.get("context_quality", "unknown"),
}
c = out["confidence"]
try:
if isinstance(c, str):
c = float(c.strip().replace("%", ""))
c = float(c)
if c > 1.0:
c = c / 100.0
if c < 0:
c = 0.0
if c > 1:
c = 1.0
except Exception:
c = 0.0
out["confidence"] = c
if not isinstance(out["supporting_evidence"], list):
out["supporting_evidence"] = [str(out["supporting_evidence"])]
if not isinstance(out["contradicting_evidence"], list):
out["contradicting_evidence"] = [str(out["contradicting_evidence"])]
if isinstance(out["verdict"], str):
out["verdict"] = out["verdict"].upper()
return out
|