-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_final.py
More file actions
103 lines (84 loc) · 4.05 KB
/
Copy pathtest_final.py
File metadata and controls
103 lines (84 loc) · 4.05 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""
Test script to verify the final implementation
"""
import requests
import json
def test_analyze_text():
base_url = "http://localhost:8000"
print("🧪 Testing Final Implementation")
print("=" * 50)
# Test case
test_text = "Scientists at NASA have discovered a new exoplanet that could potentially support life. The planet, named TOI-715 b, is located about 137 light-years away from Earth."
print(f"Test Text: {test_text}")
print("\nPerforming analysis with SerpAPI sources...")
try:
response = requests.post(
f"{base_url}/analyze_text",
json={"text": test_text},
timeout=30
)
if response.status_code == 200:
result = response.json()
print("✅ Analysis successful!")
print(f"\n📝 Text Analysis:")
print(f" Classification: {result.get('classification')}")
print(f" Confidence: {result.get('confidence', 0):.2f}")
print(f" Language: {result.get('language')}")
print(f" Explanation: {result.get('explanation', '')[:150]}...")
print(f"\n📊 Sources Information:")
print(f" Sources Found: {result.get('sources_found', 0)}")
if result.get('credibility_summary'):
summary = result['credibility_summary']
print(f" Average Credibility: {summary.get('average_credibility', 0):.2f}")
print(f" High Credibility Sources: {summary.get('high_credibility_count', 0)}")
print(f" Medium Credibility Sources: {summary.get('medium_credibility_count', 0)}")
print(f" Low Credibility Sources: {summary.get('low_credibility_count', 0)}")
if result.get('verified_sources'):
print(f"\n📰 Top Sources:")
for i, source in enumerate(result['verified_sources'][:3], 1):
print(f" {i}. {source.get('title', 'N/A')[:60]}...")
print(f" Domain: {source.get('domain', 'N/A')}")
print(f" Credibility: {source.get('authenticity_score', 0):.2f}")
print(f" Assessment: {source.get('assessment', 'N/A')}")
print()
return True
else:
print(f"❌ Analysis failed: {response.status_code}")
print(f" Response: {response.text}")
return False
except requests.exceptions.RequestException as e:
print(f"❌ Request failed: {e}")
return False
def test_health():
base_url = "http://localhost:8000"
print("\n🏥 Testing Health Check...")
try:
response = requests.get(f"{base_url}/health", timeout=5)
if response.status_code == 200:
health_data = response.json()
print("✅ Health check passed")
print(f" Gemini available: {health_data.get('services', {}).get('gemini', False)}")
print(f" SerpAPI available: {health_data.get('services', {}).get('serpapi', False)}")
return True
else:
print(f"❌ Health check failed: {response.status_code}")
return False
except requests.exceptions.RequestException as e:
print(f"❌ Health check failed: {e}")
return False
if __name__ == "__main__":
print("🚀 Testing Final Fake News Detector Implementation")
print("=" * 60)
# Test health first
if test_health():
# Test main functionality
test_analyze_text()
print("\n" + "=" * 60)
print("🎉 Final Implementation Test Completed!")
print("\nKey Features:")
print("✅ ML Fallback removed - Pure Gemini + SerpAPI integration")
print("✅ SerpAPI sources sent to Gemini for enhanced analysis")
print("✅ Sources displayed in extension with credibility scores")
print("✅ All endpoints now include source verification")
print("✅ Enhanced analysis with real-time source cross-referencing")