-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_analyze_button.py
More file actions
46 lines (33 loc) · 1.7 KB
/
test_analyze_button.py
File metadata and controls
46 lines (33 loc) · 1.7 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
#!/usr/bin/env python3
"""Test that the analyze functionality works correctly"""
import sys
import time
sys.path.append('app')
from app.utils import predict_bias_zero_shot, explain_with_lime
def test_analyze_functionality():
"""Test the core analyze functionality that the button should trigger"""
test_text = "The government's new progressive policy represents a significant step forward in addressing climate change through innovative environmental regulations that will benefit working families."
print("🔍 Testing Analyze Button Functionality...")
print(f"Text: {test_text[:100]}...")
# Test bias prediction (what happens when analyze button is clicked)
print("\n1️⃣ Testing bias prediction...")
start_time = time.time()
result = predict_bias_zero_shot(test_text)
prediction_time = time.time() - start_time
print(f"✅ Bias: {result['label']} ({result['prob']:.1%}) in {prediction_time:.1f}s")
# Test LIME explanation (what happens when explanation button is clicked)
print("\n2️⃣ Testing LIME explanation...")
start_time = time.time()
html = explain_with_lime(test_text, num_features=5, num_samples=25)
lime_time = time.time() - start_time
print(f"✅ LIME explanation completed in {lime_time:.1f}s")
print(f"HTML length: {len(html)} characters")
# Check quality
if "error" in html.lower() or len(html) < 1000:
print("⚠️ Warning: LIME explanation may have quality issues")
else:
print("✅ LIME explanation appears to be high quality")
print(f"\n📊 Total time: {prediction_time + lime_time:.1f}s")
return True
if __name__ == "__main__":
test_analyze_functionality()