Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| from dataclasses import dataclass | |
| from typing import List, Dict, Any | |
| 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 | |