Download simple_agentai_test.py from pravinai/InklyAI: direct link, hf CLI and curl.
- Browser
- Download file 9.26 kB
-
https://huggingface.co/pravinai/InklyAI/resolve/main/simple_agentai_test.py
- Command line
-
hf download hf://pravinai/InklyAI/simple_agentai_test.py
-
curl -L -o simple_agentai_test.py https://huggingface.co/pravinai/InklyAI/resolve/main/simple_agentai_test.py
9.26 kB
| """ | |
| Simple test for InklyAI AgentAI integration without Flask API. | |
| """ | |
| import sys | |
| import os | |
| sys.path.append('src') | |
| from agentai_integration import AgentAISignatureManager, AgentAISignatureAPI | |
| from src.models.siamese_network import SignatureVerifier | |
| from src.data.preprocessing import SignaturePreprocessor | |
| def test_agentai_integration(): | |
| """Test the AgentAI integration directly.""" | |
| print("π§ͺ Testing InklyAI AgentAI Integration (Direct)") | |
| print("=" * 60) | |
| # Initialize signature manager | |
| print("\n1. Initializing signature manager...") | |
| signature_manager = AgentAISignatureManager( | |
| threshold=0.75, | |
| device='auto' | |
| ) | |
| print(" β Signature manager initialized") | |
| # Check if sample data exists | |
| if not os.path.exists('data/samples/john_doe_1.png'): | |
| print("\nβ οΈ Sample data not found. Creating sample signatures...") | |
| from demo import create_sample_signatures | |
| create_sample_signatures() | |
| print(" β Sample signatures created") | |
| # Register test agents | |
| print("\n2. Registering test agents...") | |
| agents = [ | |
| ("agent_001", "data/samples/john_doe_1.png"), | |
| ("agent_002", "data/samples/jane_smith_1.png"), | |
| ("agent_003", "data/samples/bob_wilson_1.png") | |
| ] | |
| for agent_id, signature_template in agents: | |
| success = signature_manager.register_agent_signature(agent_id, signature_template) | |
| if success: | |
| print(f" β Registered {agent_id}") | |
| else: | |
| print(f" β Failed to register {agent_id}") | |
| # Test signature verification | |
| print("\n3. Testing signature verification...") | |
| test_cases = [ | |
| ("agent_001", "data/samples/john_doe_2.png", "Genuine signature"), | |
| ("agent_002", "data/samples/jane_smith_2.png", "Genuine signature"), | |
| ("agent_001", "data/samples/jane_smith_1.png", "Forged signature"), | |
| ("agent_002", "data/samples/bob_wilson_1.png", "Forged signature") | |
| ] | |
| for agent_id, signature_image, expected in test_cases: | |
| try: | |
| result = signature_manager.verify_agent_signature(agent_id, signature_image) | |
| print(f" {agent_id} vs {signature_image.split('/')[-1]}: " | |
| f"Verified={result.is_verified}, Similarity={result.similarity_score:.3f}, " | |
| f"Confidence={result.confidence:.3f}") | |
| except Exception as e: | |
| print(f" β Error verifying {agent_id}: {e}") | |
| # Test agent statistics | |
| print("\n4. Testing agent statistics...") | |
| for agent_id, _ in agents: | |
| try: | |
| stats = signature_manager.get_agent_verification_stats(agent_id) | |
| print(f" {agent_id}: {stats['total_verifications']} verifications, " | |
| f"success rate: {stats['success_rate']:.2%}") | |
| except Exception as e: | |
| print(f" β Error getting stats for {agent_id}: {e}") | |
| # Test agent deactivation/reactivation | |
| print("\n5. Testing agent deactivation/reactivation...") | |
| # Deactivate an agent | |
| deactivated = signature_manager.deactivate_agent("agent_001") | |
| print(f" Deactivated agent_001: {deactivated}") | |
| # Try to verify with deactivated agent | |
| result = signature_manager.verify_agent_signature("agent_001", "data/samples/john_doe_2.png") | |
| print(f" Deactivated agent verification: {result.is_verified} (should be False)") | |
| # Reactivate the agent | |
| reactivated = signature_manager.reactivate_agent("agent_001") | |
| print(f" Reactivated agent_001: {reactivated}") | |
| # Test batch verification | |
| print("\n6. Testing batch verification...") | |
| batch_requests = [ | |
| { | |
| "agent_id": "agent_001", | |
| "signature_image": "data/samples/john_doe_2.png", | |
| "context": {"test": True} | |
| }, | |
| { | |
| "agent_id": "agent_002", | |
| "signature_image": "data/samples/jane_smith_2.png", | |
| "context": {"test": True} | |
| } | |
| ] | |
| try: | |
| batch_results = signature_manager.batch_verify_agents(batch_requests) | |
| print(f" β Batch verification processed {len(batch_results)} requests") | |
| for result in batch_results: | |
| print(f" - {result.agent_id}: Verified={result.is_verified}, " | |
| f"Similarity={result.similarity_score:.3f}") | |
| except Exception as e: | |
| print(f" β Batch verification failed: {e}") | |
| # Test API wrapper | |
| print("\n7. Testing API wrapper...") | |
| api = AgentAISignatureAPI(signature_manager) | |
| # Test API endpoints | |
| api_result = api.verify_signature_endpoint({ | |
| "agent_id": "agent_001", | |
| "signature_image": "data/samples/john_doe_2.png", | |
| "context": {"api_test": True} | |
| }) | |
| if api_result['success']: | |
| print(f" β API verification: {api_result['is_verified']}, " | |
| f"Similarity: {api_result['similarity_score']:.3f}") | |
| else: | |
| print(f" β API verification failed: {api_result.get('error')}") | |
| print("\nπ AgentAI Integration Test Completed!") | |
| print("\nKey Features Demonstrated:") | |
| print("β Agent registration and management") | |
| print("β Signature verification with confidence scoring") | |
| print("β Agent statistics and monitoring") | |
| print("β Agent activation/deactivation") | |
| print("β Batch processing") | |
| print("β API wrapper functionality") | |
| print("β Error handling and logging") | |
| return True | |
| def demonstrate_agentai_use_cases(): | |
| """Demonstrate real-world AgentAI use cases.""" | |
| print("\n" + "=" * 60) | |
| print("π’ AgentAI Use Case Demonstrations") | |
| print("=" * 60) | |
| # Initialize signature manager | |
| signature_manager = AgentAISignatureManager(threshold=0.75) | |
| # Register agents for different use cases | |
| use_cases = [ | |
| ("financial_agent", "data/samples/john_doe_1.png", "Financial AI Agent"), | |
| ("healthcare_agent", "data/samples/jane_smith_1.png", "Healthcare AI Agent"), | |
| ("legal_agent", "data/samples/bob_wilson_1.png", "Legal AI Agent") | |
| ] | |
| print("\n1. Multi-Agent System Authentication") | |
| print("-" * 40) | |
| for agent_id, signature_template, description in use_cases: | |
| if os.path.exists(signature_template): | |
| signature_manager.register_agent_signature(agent_id, signature_template) | |
| print(f" β {description} registered") | |
| # Simulate agent communication | |
| print("\n2. Simulating Agent Communication") | |
| print("-" * 40) | |
| # Financial agent needs to verify healthcare agent's signature | |
| if "healthcare_agent" in signature_manager.agent_signatures: | |
| result = signature_manager.verify_agent_signature( | |
| "healthcare_agent", | |
| "data/samples/jane_smith_2.png" | |
| ) | |
| print(f" Financial Agent verifying Healthcare Agent: {result.is_verified}") | |
| # Legal agent needs to verify financial agent's signature | |
| if "financial_agent" in signature_manager.agent_signatures: | |
| result = signature_manager.verify_agent_signature( | |
| "financial_agent", | |
| "data/samples/john_doe_2.png" | |
| ) | |
| print(f" Legal Agent verifying Financial Agent: {result.is_verified}") | |
| print("\n3. Audit Trail and Compliance") | |
| print("-" * 40) | |
| # Show verification history | |
| print(f" Total verifications logged: {len(signature_manager.verification_history)}") | |
| for result in signature_manager.verification_history[-3:]: # Show last 3 | |
| print(f" - {result.agent_id}: {result.is_verified} at {result.timestamp}") | |
| print("\n4. Security and Access Control") | |
| print("-" * 40) | |
| # Test with deactivated agent | |
| signature_manager.deactivate_agent("financial_agent") | |
| result = signature_manager.verify_agent_signature("financial_agent", "data/samples/john_doe_2.png") | |
| print(f" Deactivated agent verification: {result.is_verified} (should be False)") | |
| # Reactivate and test again | |
| signature_manager.reactivate_agent("financial_agent") | |
| result = signature_manager.verify_agent_signature("financial_agent", "data/samples/john_doe_2.png") | |
| print(f" Reactivated agent verification: {result.is_verified}") | |
| print("\nβ AgentAI Use Case Demonstrations Completed!") | |
| if __name__ == "__main__": | |
| print("InklyAI AgentAI Integration - Direct Testing") | |
| print("=" * 60) | |
| try: | |
| # Run basic integration test | |
| test_agentai_integration() | |
| # Run use case demonstrations | |
| demonstrate_agentai_use_cases() | |
| print("\n" + "=" * 60) | |
| print("π― Integration Summary") | |
| print("=" * 60) | |
| print("InklyAI successfully integrates with AgentAI systems to provide:") | |
| print("β’ Biometric authentication for AI agents") | |
| print("β’ Secure multi-agent communication") | |
| print("β’ Audit trails for compliance") | |
| print("β’ Scalable signature verification") | |
| print("β’ Real-time fraud detection") | |
| print("\nReady for production deployment! π") | |
| except Exception as e: | |
| print(f"\nβ Test failed with error: {e}") | |
| import traceback | |
| traceback.print_exc() | |