| """ |
| 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) |
|
|
| |
| print("\n1️⃣ Testing OCR Service...") |
| try: |
| from backend.core.ocr_service import EnhancedMathOCR |
| from PIL import Image |
| import numpy as np |
| |
| ocr = EnhancedMathOCR() |
|
|
| |
| |
|
|
| |
| |
| test_img = Image.new('RGB', (200, 100), color='white') |
| |
| |
| backend = ocr._select_backend(test_img) |
| print(f" ✅ Backend selection: {backend}") |
| |
| |
| 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}") |
|
|
| |
| print("\n2️⃣ Testing SymPy Verification Service...") |
| try: |
| from services.sympy_service import MathVerifier |
| |
| verifier = MathVerifier() |
| |
| |
| result1 = verifier.verify_equation("2 + 2", "4") |
| print(f" ✅ '2 + 2 = 4' → {result1['is_valid']}") |
| |
| |
| result2 = verifier.verify_equation("2 + 2", "5") |
| print(f" ✅ '2 + 2 = 5' → {result2['is_valid']} (should be False)") |
| |
| |
| 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}") |
|
|
| |
| print("\n3️⃣ Testing LLM Verification Service...") |
| try: |
| from services.llm_service import EnsembleChecker |
| import os |
| |
| checker = EnsembleChecker(use_real_api=False) |
| |
| |
| 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}") |
|
|
| |
| print("\n4️⃣ Testing ML Classifier...") |
| try: |
| from services.ml_classifier import MLVerifier |
| |
| classifier = MLVerifier() |
| |
| |
| 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}") |
|
|
| |
| print("\n5️⃣ Testing Orchestrator (Integration)...") |
| try: |
| from backend.core.orchestrator import MathVerificationOrchestrator |
| |
| orchestrator = MathVerificationOrchestrator() |
| |
| |
| 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}") |
|
|
| |
| 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}") |
|
|
| |
| print("\n7️⃣ Testing Stroke Extraction...") |
| try: |
| from services.stroke_extraction import StrokeExtractor |
| from PIL import Image |
| import numpy as np |
| |
| extractor = StrokeExtractor() |
| |
| |
| 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}") |
|
|
| |
| print("\n8️⃣ Testing External Integrations...") |
| try: |
| |
| import math_verify |
| print(" ✅ Math-Verify: INSTALLED") |
| except ImportError: |
| print(" ⚠️ Math-Verify: NOT INSTALLED") |
|
|
| try: |
| |
| from datasets import load_dataset |
| print(" ✅ HuggingFace Datasets: INSTALLED") |
| except ImportError: |
| print(" ⚠️ HuggingFace Datasets: NOT INSTALLED") |
|
|
| |
| 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) |
|
|