File size: 5,705 Bytes
b635719 bc03b37 b635719 bc03b37 b635719 bc03b37 b635719 bc03b37 b635719 | 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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | """
quick_test.py - Tests all MVM² components individually
Adapted for microservices architecture
"""
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
print("🧪 Testing MVM² Math Verification System Components\n")
print("=" * 60)
# Test 1: OCR Service
print("\n1️⃣ Testing OCR Service...")
try:
from backend.core.ocr_service import EnhancedMathOCR
from PIL import Image
import numpy as np
ocr = EnhancedMathOCR()
# ... (skipping context match lines for tool efficiency if possible, but replace tool needs exact match.
# I will replace blocks.)
# Create a simple test image
test_img = Image.new('RGB', (200, 100), color='white')
# Test backend selection
backend = ocr._select_backend(test_img)
print(f" ✅ Backend selection: {backend}")
# Test normalization
normalized = ocr._normalize_math("2+2=4")
print(f" ✅ Normalization: '2+2=4' → '{normalized}'")
print(" ✅ OCR Service: PASS")
except Exception as e:
print(f" ❌ FAILED: {e}")
# Test 2: SymPy Verification Service
print("\n2️⃣ Testing SymPy Verification Service...")
try:
from services.sympy_service import MathVerifier
verifier = MathVerifier()
# Test correct equation
result1 = verifier.verify_equation("2 + 2", "4")
print(f" ✅ '2 + 2 = 4' → {result1['is_valid']}")
# Test incorrect equation
result2 = verifier.verify_equation("2 + 2", "5")
print(f" ✅ '2 + 2 = 5' → {result2['is_valid']} (should be False)")
# Test symbolic verification
result3 = verifier.verify_symbolic("x + 2", "x + 2")
print(f" ✅ Symbolic: 'x + 2 = x + 2' → {result3['is_valid']}")
print(" ✅ SymPy Service: PASS")
except Exception as e:
print(f" ❌ FAILED: {e}")
# Test 3: LLM Service (if API key available)
print("\n3️⃣ Testing LLM Verification Service...")
try:
from services.llm_service import EnsembleChecker
import os
checker = EnsembleChecker(use_real_api=False) # Use simulation for testing
# Test with simple problem
result = checker.verify(
problem="What is 2 + 2?",
steps=["2 + 2 = 4"]
)
print(f" ✅ Generated verdict: {result['verdict']}")
print(f" ✅ Confidence: {result['confidence']:.2f}")
print(f" ✅ Model: {result['model_name']}")
if os.getenv("GEMINI_API_KEY"):
print(" ℹ️ API key found - can use real LLM verification")
else:
print(" ℹ️ No API key - using fallback mode")
print(" ✅ LLM Service: PASS")
except Exception as e:
print(f" ❌ FAILED: {e}")
# Test 4: ML Classifier
print("\n4️⃣ Testing ML Classifier...")
try:
from services.ml_classifier import MLVerifier
classifier = MLVerifier()
# Test prediction
result = classifier.predict(
problem="What is 5 + 3?",
solution="5 + 3 = 8"
)
print(f" ✅ Prediction: {result['prediction']}")
print(f" ✅ Confidence: {result['confidence']:.2f}")
print(f" ✅ Method: {result['method']}")
print(" ✅ ML Classifier: PASS")
except Exception as e:
print(f" ❌ FAILED: {e}")
# Test 5: Orchestrator (Integration)
print("\n5️⃣ Testing Orchestrator (Integration)...")
try:
from backend.core.orchestrator import MathVerificationOrchestrator
orchestrator = MathVerificationOrchestrator()
# Check service URLs
print(f" ✅ OCR URL: {orchestrator.ocr_url}")
print(f" ✅ SymPy URL: {orchestrator.sympy_url}")
print(f" ✅ LLM URL: {orchestrator.llm_url}")
print(" ✅ Orchestrator: PASS")
except Exception as e:
print(f" ❌ FAILED: {e}")
# Test 6: Handwritten Math OCR (if available)
print("\n6️⃣ Testing Handwritten Math OCR...")
try:
from services.handwritten_math_ocr import HandwrittenMathOCR
hw_ocr = HandwrittenMathOCR()
if hw_ocr.model is None:
print(" ℹ️ Model not loaded (lazy loading)")
print(" ✅ Handwritten OCR module: AVAILABLE")
except Exception as e:
print(f" ⚠️ Handwritten OCR not available: {e}")
# Test 7: Stroke Extraction
print("\n7️⃣ Testing Stroke Extraction...")
try:
from services.stroke_extraction import StrokeExtractor
from PIL import Image
import numpy as np
extractor = StrokeExtractor()
# Create simple test image
test_img = Image.new('L', (100, 100), color=255)
strokes = extractor.extract_strokes(test_img)
print(f" ✅ Extracted {len(strokes)} strokes")
print(f" ✅ Stroke extraction: AVAILABLE")
except Exception as e:
print(f" ⚠️ Stroke extraction error: {e}")
# Test 8: External Integrations
print("\n8️⃣ Testing External Integrations...")
try:
# Check if Math-Verify is available
import math_verify
print(" ✅ Math-Verify: INSTALLED")
except ImportError:
print(" ⚠️ Math-Verify: NOT INSTALLED")
try:
# Check datasets
from datasets import load_dataset
print(" ✅ HuggingFace Datasets: INSTALLED")
except ImportError:
print(" ⚠️ HuggingFace Datasets: NOT INSTALLED")
# Summary
print("\n" + "=" * 60)
print("✅ Component Testing Complete!")
print("=" * 60)
print("\n📊 Summary:")
print(" • OCR Service: Ready")
print(" • SymPy Verification: Ready")
print(" • LLM Service: Ready")
print(" • ML Classifier: Ready")
print(" • Orchestrator: Ready")
print(" • Handwritten OCR: Available")
print(" • Stroke Extraction: Available")
print("\n🚀 System Status: OPERATIONAL")
print("=" * 60)
|