D Ф m i И i q ц e L Ф y e r commited on
Commit
3f5e84d
·
1 Parent(s): fdaeab5

Fix: API URL detection & add missing NER/EEAT data

Browse files
syscred/static/index.html CHANGED
@@ -927,9 +927,35 @@
927
 
928
  <script>
929
  // Backend URLs
 
 
930
  const LOCAL_API_URL = 'http://localhost:5001';
931
- const REMOTE_API_URL = 'https://domloyer-syscred.hf.space';
932
- let API_URL = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
933
 
934
  function toggleBackend() {
935
  const toggle = document.getElementById('backendToggle');
@@ -939,7 +965,7 @@
939
 
940
  if (toggle.checked) {
941
  API_URL = REMOTE_API_URL;
942
- status.textContent = 'Backend: HF Space (ML complet, plus lent)';
943
  status.className = 'backend-status remote';
944
  labelLocal.classList.remove('active');
945
  labelRemote.classList.add('active');
@@ -950,7 +976,7 @@
950
  labelLocal.classList.add('active');
951
  labelRemote.classList.remove('active');
952
  }
953
- console.log('[SysCRED] Backend switched to:', API_URL);
954
  }
955
 
956
  async function analyzeUrl() {
 
927
 
928
  <script>
929
  // Backend URLs
930
+ // Empty string means relative path (same domain), which works for HF Space
931
+ const REMOTE_API_URL = '';
932
  const LOCAL_API_URL = 'http://localhost:5001';
933
+
934
+ // Detect if we are already on localhost
935
+ const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
936
+ let API_URL = isLocalhost ? LOCAL_API_URL : REMOTE_API_URL;
937
+
938
+ // Set initial toggle state based on environment
939
+ document.addEventListener('DOMContentLoaded', () => {
940
+ const toggle = document.getElementById('backendToggle');
941
+ const status = document.getElementById('backendStatus');
942
+ const labelLocal = document.getElementById('labelLocal');
943
+ const labelRemote = document.getElementById('labelRemote');
944
+
945
+ if (isLocalhost) {
946
+ toggle.checked = false;
947
+ status.textContent = 'Backend: localhost:5001 (léger, sans ML)';
948
+ status.className = 'backend-status local';
949
+ labelLocal.classList.add('active');
950
+ labelRemote.classList.remove('active');
951
+ } else {
952
+ toggle.checked = true;
953
+ status.textContent = 'Backend: HF Space (ML complet)';
954
+ status.className = 'backend-status remote';
955
+ labelLocal.classList.remove('active');
956
+ labelRemote.classList.add('active');
957
+ }
958
+ });
959
 
960
  function toggleBackend() {
961
  const toggle = document.getElementById('backendToggle');
 
965
 
966
  if (toggle.checked) {
967
  API_URL = REMOTE_API_URL;
968
+ status.textContent = 'Backend: HF Space (ML complet)';
969
  status.className = 'backend-status remote';
970
  labelLocal.classList.remove('active');
971
  labelRemote.classList.add('active');
 
976
  labelLocal.classList.add('active');
977
  labelRemote.classList.remove('active');
978
  }
979
+ console.log('[SysCRED] Backend switched to:', API_URL || 'Relative Path (HF Space)');
980
  }
981
 
982
  async function analyzeUrl() {
syscred/verification_system.py CHANGED
@@ -338,6 +338,21 @@ class CredibilityVerificationSystem:
338
 
339
  # 4. Semantic Coherence
340
  results['coherence_score'] = self._calculate_coherence(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
 
342
  return results
343
 
@@ -743,7 +758,7 @@ class CredibilityVerificationSystem:
743
  })
744
  report['sourcesUtilisees'].append({
745
  'type': 'Fact Check API',
746
- 'results_count': len(external_data.fact_checks)
747
  })
748
  # [NEW] Add TREC evidence source
749
  if evidences:
@@ -753,6 +768,16 @@ class CredibilityVerificationSystem:
753
  'corpus': 'AP88-90',
754
  'results_count': len(evidences)
755
  })
 
 
 
 
 
 
 
 
 
 
756
 
757
  return report
758
 
 
338
 
339
  # 4. Semantic Coherence
340
  results['coherence_score'] = self._calculate_coherence(text)
341
+
342
+ # 5. [NEW] E-E-A-T Score Calculation
343
+ if HAS_EEAT:
344
+ try:
345
+ # Initialize calc if needed (lazy load)
346
+ if not hasattr(self, 'eeat_calculator') or self.eeat_calculator is None:
347
+ self.eeat_calculator = EEATCalculator()
348
+
349
+ # Calculate score
350
+ eeat = self.eeat_calculator.calculate_eeat(text, results.get('named_entities', []))
351
+ # Store in results as dict
352
+ results['eeat_score'] = eeat.to_dict()
353
+ print(f"[NLP] EEAT Score calculated: {eeat.overall_score:.2f}")
354
+ except Exception as e:
355
+ print(f"[NLP] EEAT error: {e}")
356
 
357
  return results
358
 
 
758
  })
759
  report['sourcesUtilisees'].append({
760
  'type': 'Fact Check API',
761
+ 'results_count': len(external_data.fact_checks) if external_data.fact_checks else 0
762
  })
763
  # [NEW] Add TREC evidence source
764
  if evidences:
 
768
  'corpus': 'AP88-90',
769
  'results_count': len(evidences)
770
  })
771
+
772
+ # [FIX] Add explicit fields for frontend
773
+ if nlp_results.get('named_entities'):
774
+ report['ner_entities'] = nlp_results.get('named_entities')
775
+
776
+ # Add EEAT score if available (from rule_results or nlp_results)
777
+ if 'eeat_score' in rule_results:
778
+ report['eeat_score'] = rule_results['eeat_score']
779
+ elif 'eeat_score' in nlp_results:
780
+ report['eeat_score'] = nlp_results['eeat_score']
781
 
782
  return report
783