Spaces:
Sleeping
Sleeping
File size: 4,338 Bytes
c30b695 | 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 | #!/usr/bin/env python
"""
Setup verification script for OFP Bad Word Sentinel
Run this to verify all components are installed correctly
"""
import sys
import importlib
def check_module(module_name, display_name=None):
"""Check if a module can be imported"""
display = display_name or module_name
try:
importlib.import_module(module_name)
print(f"β {display} is installed")
return True
except ImportError:
print(f"β {display} is NOT installed")
return False
def check_project_files():
"""Check if project files exist"""
import os
files = [
'app.py',
'requirements.txt',
'README.md',
'config/config.yaml',
'config/wordlist.txt',
'src/__init__.py',
'src/models.py',
'src/ofp_client.py',
'src/profanity_detector.py',
'src/sentinel.py',
'tests/test_profanity.py',
'tests/test_ofp_client.py',
'tests/test_sentinel.py'
]
print("\nProject Files:")
all_exist = True
for file in files:
if os.path.exists(file):
print(f"β {file}")
else:
print(f"β {file} MISSING")
all_exist = False
return all_exist
def test_profanity_detector():
"""Test profanity detector functionality"""
try:
from src.profanity_detector import ProfanityDetector
detector = ProfanityDetector()
# Test basic detection
assert detector.is_profane("This is shit"), "Failed to detect profanity"
assert not detector.is_profane("This is nice"), "False positive"
print("\nProfanity Detector:")
print("β Basic detection works")
print("β No false positives")
return True
except Exception as e:
print(f"\nβ Profanity detector test failed: {e}")
return False
def test_ofp_models():
"""Test OFP models"""
try:
from src.models import Envelope, DialogEvent, create_envelope
# Create test envelope
envelope = create_envelope(
conversation_id="test:123",
speaker_uri="tag:test,2025:sentinel",
events=[]
)
# Convert to JSON and back
json_str = envelope.to_json()
print("\nOFP Models:")
print("β Envelope creation works")
print("β JSON serialization works")
return True
except Exception as e:
print(f"\nβ OFP models test failed: {e}")
return False
def test_sentinel():
"""Test sentinel initialization"""
try:
from src.sentinel import BadWordSentinel
from src.profanity_detector import ProfanityDetector
detector = ProfanityDetector()
sentinel = BadWordSentinel(
speaker_uri="tag:test,2025:sentinel",
service_url="http://test.com",
profanity_detector=detector,
convener_uri="tag:test,2025:convener",
convener_url="http://test.com"
)
status = sentinel.get_status()
print("\nSentinel:")
print("β Sentinel initialization works")
print("β Status retrieval works")
return True
except Exception as e:
print(f"\nβ Sentinel test failed: {e}")
return False
def main():
"""Run all verification checks"""
print("=" * 60)
print("OFP Bad Word Sentinel - Setup Verification")
print("=" * 60)
print("\nRequired Dependencies:")
deps_ok = all([
check_module('gradio'),
check_module('better_profanity', 'better-profanity'),
check_module('apscheduler', 'APScheduler'),
check_module('requests'),
check_module('yaml', 'pyyaml')
])
files_ok = check_project_files()
detector_ok = test_profanity_detector()
models_ok = test_ofp_models()
sentinel_ok = test_sentinel()
print("\n" + "=" * 60)
if all([deps_ok, files_ok, detector_ok, models_ok, sentinel_ok]):
print("β ALL CHECKS PASSED")
print("\nYou're ready to run the sentinel!")
print("Run: python app.py")
sys.exit(0)
else:
print("β SOME CHECKS FAILED")
print("\nPlease fix the issues above before running.")
print("Try: pip install -r requirements.txt")
sys.exit(1)
if __name__ == '__main__':
main()
|