#!/usr/bin/env python3 """ Test script for the improved AI text detector """ import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__))) from app import AdvancedAITextDetector def test_detector(): """Test the detector with various text samples""" print("Initializing detector...") detector = AdvancedAITextDetector() # Test cases test_cases = [ { "name": "Human - Conversational", "text": "So yesterday I'm at the coffee shop, right? And this guy next to me is having the LOUDEST phone conversation about his crypto investments. Like, dude, we get it, you bought Dogecoin. But here's the thing - he kept saying he was gonna be a millionaire by next week. Next week! I almost choked on my latte.", "expected": "human" }, { "name": "AI - ChatGPT Style", "text": "Artificial intelligence has revolutionized numerous industries in recent years. It's important to note that this technology offers both opportunities and challenges. Machine learning algorithms can process vast amounts of data, identify patterns, and make predictions with remarkable accuracy. Furthermore, AI applications span various domains including healthcare, finance, and transportation.", "expected": "ai" }, { "name": "Human - Personal Reflection", "text": "I've been thinking about this whole social media thing lately. You know, I used to post everything - what I ate for breakfast, random thoughts, selfies. But now I'm kinda over it? Like, I still check Instagram and stuff, but I don't feel the need to share every little thing anymore.", "expected": "human" }, { "name": "AI - Formal Academic", "text": "The implementation of machine learning algorithms requires careful consideration of various factors. It is essential to understand that these systems must be designed with robust error handling mechanisms. Additionally, the development process should incorporate comprehensive testing protocols to ensure optimal performance.", "expected": "ai" } ] print("\n" + "="*80) print("TESTING IMPROVED AI TEXT DETECTOR") print("="*80) for i, test_case in enumerate(test_cases, 1): print(f"\n{i}. {test_case['name']}") print("-" * 50) result = detector.detect(test_case['text']) print(f"AI Probability: {result['ai_probability']}%") print(f"Classification: {result['classification']}") print(f"Confidence: {result['confidence']}") # Check if result matches expectation ai_prob = result['ai_probability'] if test_case['expected'] == 'human' and ai_prob < 40: print("✅ CORRECT - Human text correctly identified") elif test_case['expected'] == 'ai' and ai_prob > 60: print("✅ CORRECT - AI text correctly identified") else: print("❌ INCORRECT - Misclassification detected") # Show key indicators if 'statistical_analysis' in result: stats = result['statistical_analysis'] print(f"Human Patterns: {stats.get('human_patterns', 0):.2f}") print(f"ChatGPT Patterns: {stats.get('chatgpt_patterns', 0):.2f}") print(f"Conversational: {stats.get('conversational_patterns', 0):.2f}") print("\n" + "="*80) print("TEST COMPLETE") print("="*80) if __name__ == "__main__": test_detector()