InklyAI / test_web_ui.py
pravinai's picture
Upload folder using huggingface_hub
8eab354 verified
"""
Test script for InklyAI Web UI
"""
import requests
import json
import os
import time
from pathlib import Path
def test_web_ui():
"""Test the web UI functionality."""
print("πŸ§ͺ Testing InklyAI Web UI")
print("=" * 50)
base_url = "http://localhost:8080"
# Test 1: Health check
print("\n1. Testing health check...")
try:
response = requests.get(f"{base_url}/api/health")
health = response.json()
print(f" βœ… Health status: {health['status']}")
print(f" βœ… Agents registered: {health['agents_registered']}")
except Exception as e:
print(f" ❌ Health check failed: {e}")
return False
# Test 2: Get agents
print("\n2. Testing agent listing...")
try:
response = requests.get(f"{base_url}/api/agents")
agents = response.json()
print(f" βœ… Found {agents['total_agents']} agents")
for agent in agents['agents']:
print(f" - {agent['agent_id']} ({'Active' if agent['is_active'] else 'Inactive'})")
except Exception as e:
print(f" ❌ Agent listing failed: {e}")
# Test 3: Test signature verification (if sample data exists)
print("\n3. Testing signature verification...")
if os.path.exists('data/samples/john_doe_1.png') and os.path.exists('data/samples/john_doe_2.png'):
try:
# Test with sample signatures
with open('data/samples/john_doe_1.png', 'rb') as f1, open('data/samples/john_doe_2.png', 'rb') as f2:
files = {
'signature1': ('john_doe_1.png', f1, 'image/png'),
'signature2': ('john_doe_2.png', f2, 'image/png')
}
data = {'agent_id': 'Agent_01'}
response = requests.post(f"{base_url}/api/verify", files=files, data=data)
result = response.json()
if result['success']:
print(f" βœ… Verification successful")
print(f" βœ… Similarity: {result['similarity_score']:.3f}")
print(f" βœ… Verified: {result['is_verified']}")
else:
print(f" ❌ Verification failed: {result['error']}")
except Exception as e:
print(f" ❌ Signature verification failed: {e}")
else:
print(" ⚠️ Sample data not found. Run demo.py first to create sample signatures.")
# Test 4: Test agent stats
print("\n4. Testing agent statistics...")
try:
response = requests.get(f"{base_url}/api/stats")
stats = response.json()
if stats['success']:
print(f" βœ… Statistics loaded successfully")
for agent_id, agent_stats in stats['stats'].items():
print(f" - {agent_id}: {agent_stats['total_verifications']} verifications, "
f"success rate: {agent_stats['success_rate']:.1%}")
else:
print(f" ❌ Stats failed: {stats['error']}")
except Exception as e:
print(f" ❌ Agent stats failed: {e}")
print("\nπŸŽ‰ Web UI tests completed!")
print(f"\n🌐 Access the web UI at: {base_url}")
print(f"πŸ“Š Agent management at: {base_url}/agents")
return True
def check_web_server():
"""Check if the web server is running."""
try:
response = requests.get("http://localhost:8080/api/health", timeout=5)
return response.status_code == 200
except:
return False
if __name__ == "__main__":
print("InklyAI Web UI Test Suite")
print("=" * 50)
# Check if web server is running
if not check_web_server():
print("❌ Web server is not running!")
print("Please start the web server with:")
print(" python web_app.py")
print("\nThen run this test script again.")
exit(1)
print("βœ… Web server is running")
# Run tests
test_web_ui()
print("\n" + "=" * 50)
print("Web UI Test Summary:")
print("βœ… Health monitoring")
print("βœ… Agent management")
print("βœ… Signature verification")
print("βœ… Statistics and reporting")
print("βœ… Error handling")
print("\nπŸš€ Web UI is ready for use!")