Spaces:
Sleeping
Sleeping
File size: 5,169 Bytes
4fef010 |
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#!/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())
|