Varshithdharmaj's picture
Refactor: Restructure project into modular architecture (MVM²)
bc03b37
Raw
History Blame
5.71 kB
"""
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)