Spaces:
Sleeping
Sleeping
| #!/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() | |