aubynsamuel05 commited on
Commit
8e1f84c
Β·
1 Parent(s): f86b3df

add: source details to comprehensive verification output

Browse files
Files changed (2) hide show
  1. deploy/index.py +18 -9
  2. deploy/main/claim_verifier.py +3 -3
deploy/index.py CHANGED
@@ -147,24 +147,25 @@ class FakeNewsDetector:
147
  print(f" ❌ Network analysis error: {e}")
148
  return {"score": 0.1, "domain_diversity": 0.0}
149
 
150
- def _verify_claim(self, headline: str, search_results: List[str]) -> float:
151
  """Verifies the claim against the content of the found sources."""
152
  print("βœ… Verifying Claims...")
153
 
154
  if not search_results:
155
  print(" ❌ No search results for claim verification")
156
- return 0.4
157
 
158
  try:
159
  verification = self.claim_verifier.verify_claim_against_sources(
160
  headline, search_results
161
  )
162
- claim_verification_score = self._to_float(verification.get("score", 0.4))
 
163
  print(f" '{headline}': {claim_verification_score:.2f}")
164
- return claim_verification_score
165
  except Exception as e:
166
  print(f" ❌ Claim verification error: {e}")
167
- return 0.4
168
 
169
  def _calculate_final_score_and_verdict(
170
  self, component_scores: Dict[str, float]
@@ -229,6 +230,10 @@ class FakeNewsDetector:
229
  )
230
  print(f" β€’ Domain Diversity: {components['network']['domain_diversity']:.2f}")
231
 
 
 
 
 
232
  def comprehensive_verify(
233
  self, raw_headline: str, results_to_check: int = 8
234
  ) -> Dict:
@@ -270,7 +275,7 @@ class FakeNewsDetector:
270
  "suspicious_count": 0,
271
  },
272
  "network": {"score": 0.0, "domain_diversity": 0.0},
273
- "claim_verification": {"score": 0.0},
274
  },
275
  }
276
 
@@ -301,7 +306,7 @@ class FakeNewsDetector:
301
  "suspicious_count": 0,
302
  },
303
  "network": {"score": 0.1, "domain_diversity": 0.0},
304
- "claim_verification": {"score": 0.1},
305
  },
306
  }
307
 
@@ -311,7 +316,8 @@ class FakeNewsDetector:
311
  self._analyze_source_credibility(search_results)
312
  )
313
  network_analysis = self._analyze_network_propagation(search_results)
314
- claim_verification_score = self._verify_claim(raw_headline, search_results)
 
315
 
316
  # Step 3: Consolidate component scores (ensure all are Python floats)
317
  component_scores = {
@@ -360,7 +366,10 @@ class FakeNewsDetector:
360
  "score": round(network_analysis["score"], 2),
361
  "domain_diversity": round(network_analysis["domain_diversity"], 2),
362
  },
363
- "claim_verification": {"score": round(claim_verification_score, 2)},
 
 
 
364
  },
365
  }
366
 
 
147
  print(f" ❌ Network analysis error: {e}")
148
  return {"score": 0.1, "domain_diversity": 0.0}
149
 
150
+ def _verify_claim(self, headline: str, search_results: List[str]) -> Dict[str, Any]:
151
  """Verifies the claim against the content of the found sources."""
152
  print("βœ… Verifying Claims...")
153
 
154
  if not search_results:
155
  print(" ❌ No search results for claim verification")
156
+ return {"score": 0.3, "source_details": []}
157
 
158
  try:
159
  verification = self.claim_verifier.verify_claim_against_sources(
160
  headline, search_results
161
  )
162
+ claim_verification_score = self._to_float(verification.get("score", 0.3))
163
+ source_details = verification.get("source_details", [])
164
  print(f" '{headline}': {claim_verification_score:.2f}")
165
+ return {"score": claim_verification_score, "source_details": source_details}
166
  except Exception as e:
167
  print(f" ❌ Claim verification error: {e}")
168
+ return {"score": 0.3, "source_details": []}
169
 
170
  def _calculate_final_score_and_verdict(
171
  self, component_scores: Dict[str, float]
 
230
  )
231
  print(f" β€’ Domain Diversity: {components['network']['domain_diversity']:.2f}")
232
 
233
+ print(
234
+ f" β€’ Source Details: {components['claim_verification']['source_details'][0:1]}"
235
+ )
236
+
237
  def comprehensive_verify(
238
  self, raw_headline: str, results_to_check: int = 8
239
  ) -> Dict:
 
275
  "suspicious_count": 0,
276
  },
277
  "network": {"score": 0.0, "domain_diversity": 0.0},
278
+ "claim_verification": {"score": 0.0, "source_details": []},
279
  },
280
  }
281
 
 
306
  "suspicious_count": 0,
307
  },
308
  "network": {"score": 0.1, "domain_diversity": 0.0},
309
+ "claim_verification": {"score": 0.1, "source_details": []},
310
  },
311
  }
312
 
 
316
  self._analyze_source_credibility(search_results)
317
  )
318
  network_analysis = self._analyze_network_propagation(search_results)
319
+ claim_verification_result = self._verify_claim(raw_headline, search_results)
320
+ claim_verification_score = claim_verification_result["score"]
321
 
322
  # Step 3: Consolidate component scores (ensure all are Python floats)
323
  component_scores = {
 
366
  "score": round(network_analysis["score"], 2),
367
  "domain_diversity": round(network_analysis["domain_diversity"], 2),
368
  },
369
+ "claim_verification": {
370
+ "score": round(claim_verification_score, 2),
371
+ "source_details": claim_verification_result["source_details"],
372
+ },
373
  },
374
  }
375
 
deploy/main/claim_verifier.py CHANGED
@@ -194,7 +194,6 @@ class ClaimVerifier:
194
  def _get_user_agent(self) -> str:
195
  ua = self.user_agents[self.current_ua_index]
196
  self.current_ua_index = (self.current_ua_index + 1) % len(self.user_agents)
197
- print(f"Using User-Agent: {ua}")
198
  return ua
199
 
200
  def _cache_key(self, text: str) -> str:
@@ -278,8 +277,9 @@ class ClaimVerifier:
278
  except TimeoutError:
279
  logging.warning("⏰ Timeout: Some URLs were skipped.")
280
 
281
- for source_detail in source_details:
282
- logging.info(f"Source Details:\n{source_detail}\n")
 
283
  support_sum = sum(support_scores)
284
 
285
  if total_weight > 0:
 
194
  def _get_user_agent(self) -> str:
195
  ua = self.user_agents[self.current_ua_index]
196
  self.current_ua_index = (self.current_ua_index + 1) % len(self.user_agents)
 
197
  return ua
198
 
199
  def _cache_key(self, text: str) -> str:
 
277
  except TimeoutError:
278
  logging.warning("⏰ Timeout: Some URLs were skipped.")
279
 
280
+ # for source_detail in source_details:
281
+ # logging.info(f"Source Details:\n{source_detail}\n")
282
+
283
  support_sum = sum(support_scores)
284
 
285
  if total_weight > 0: