#!/usr/bin/env python3 """ AI Safety Lab - System Validation Script Validates the complete AI Safety Lab system for deployment readiness. This script checks imports, basic functionality, and system integrity. """ import sys import os import importlib.util from pathlib import Path def check_file_structure(): """Verify all required files are present""" print("šŸ” Checking file structure...") required_files = { 'app.py': 'Main Gradio application', 'requirements.txt': 'Python dependencies', 'README.md': 'Documentation', 'roadmap.md': 'Development roadmap', 'agents/red_team.py': 'Red teaming agent', 'agents/safety_judge.py': 'Safety judge agent', 'models/hf_interface.py': 'HuggingFace model interface', 'orchestration/loop.py': 'Evaluation orchestration', 'evals/metrics.py': 'Safety metrics calculator' } missing_files = [] for file_path, description in required_files.items(): if Path(file_path).exists(): print(f" āœ“ {file_path} - {description}") else: print(f" āŒ {file_path} - {description} - MISSING") missing_files.append(file_path) return len(missing_files) == 0 def check_python_syntax(): """Check Python syntax for all Python files""" print("\nšŸ Checking Python syntax...") python_files = list(Path(".").rglob("*.py")) syntax_errors = [] for py_file in python_files: try: with open(py_file, 'r', encoding='utf-8') as f: compile(f.read(), str(py_file), 'exec') print(f" āœ“ {py_file}") except SyntaxError as e: print(f" āŒ {py_file} - Syntax error: {e}") syntax_errors.append(str(py_file)) except Exception as e: print(f" āš ļø {py_file} - Error: {e}") return len(syntax_errors) == 0 def check_data_models(): """Test basic data model instantiation""" print("\nšŸ—ļø Testing data models...") try: from agents.red_team import AdversarialPrompt from agents.safety_judge import SafetyJudgment, HarmSeverity # Test AdversarialPrompt prompt = AdversarialPrompt( prompt='test prompt', attack_vector='test_vector', expected_violation='test_violation', complexity_score=0.5 ) print(" āœ“ AdversarialPrompt instantiation") # Test SafetyJudgment judgment = SafetyJudgment( overall_risk_score=0.3, policy_violation_likelihood=0.2, harm_severity=HarmSeverity.LOW, ambiguity_risk=0.1, exploitability=0.15, dimensions=[], flag_reasons=[], recommendation='APPROVE: Output appears safe' ) print(" āœ“ SafetyJudgment instantiation") return True except Exception as e: print(f" āŒ Data model error: {e}") return False def check_deployment_readiness(): """Check deployment-specific requirements""" print("\nšŸš€ Checking deployment readiness...") # Check Hugging Face token hf_token = os.environ.get('HUGGINGFACEHUB_API_TOKEN') if hf_token: print(" āœ“ HUGGINGFACEHUB_API_TOKEN found") else: print(" āš ļø HUGGINGFACEHUB_API_TOKEN not set (required for deployment)") # Check Gradio compatibility try: import gradio as gr print(" āœ“ Gradio available") except ImportError: print(" āŒ Gradio not available") return False # Check DSPy compatibility try: import dspy print(" āœ“ DSPy available") except ImportError: print(" āŒ DSPy not available") return False return True def main(): """Run complete system validation""" print("šŸ›”ļø AI Safety Lab - System Validation") print("=" * 50) # Run all checks structure_ok = check_file_structure() syntax_ok = check_python_syntax() models_ok = check_data_models() deployment_ok = check_deployment_readiness() # Summary print("\n" + "=" * 50) print("šŸ“‹ VALIDATION SUMMARY") print("=" * 50) checks = [ ("File Structure", structure_ok), ("Python Syntax", syntax_ok), ("Data Models", models_ok), ("Deployment Ready", deployment_ok) ] all_passed = True for check_name, passed in checks: status = "āœ“ PASS" if passed else "āŒ FAIL" print(f" {check_name:20} {status}") if not passed: all_passed = False print("\n" + "=" * 50) if all_passed: print("šŸŽ‰ ALL CHECKS PASSED - System ready for deployment!") print("\nNext steps:") print("1. Set HUGGINGFACEHUB_API_TOKEN environment variable") print("2. Deploy to Hugging Face Space") print("3. Run safety evaluations") return 0 else: print("āŒ SOME CHECKS FAILED - Fix issues before deployment") return 1 if __name__ == "__main__": sys.exit(main())