Import & Excel Mapping: - Add ImportMappingModal with column mapping and preview - Integrate modal into FileUploadZone - Add Excel lookup metadata source with file upload - Create excelService for API calls - Show success indicators after configuration Registration & Auth: - Create RegisterPage with form validation - Add /register route in App.tsx - Add registration link in LoginPage - Password strength validation (min 8 chars) AI Generation: - Integrate MetadataAnalyzer in backend files upload - Add AI generation case in metadata_service - Error handling for missing OPENAI_API_KEY - Test script for AI integration Stats & UI Polish: - Add storage stats cards to Dashboard (files, storage, users) - Fix vite.svg 404 by replacing with emoji favicon - Enhanced loading states with spinner - Improved drag-drop visual feedback - Fix TypeScript errors with vite-env.d.ts All features now match Flask v3.1 functionality: ✅ Import from CSV/Excel/JSON with column mapping ✅ Excel lookup table ✅ AI metadata generation ✅ Template system ✅ User registration ✅ Statistics dashboard ✅ All builds successfully, TypeScript clean Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
146 lines
4.3 KiB
Python
146 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify AI metadata generation integration
|
|
Run this after installing dependencies: pip install -r requirements.txt
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Add backend to path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
def test_imports():
|
|
"""Test that all imports work"""
|
|
print("Testing imports...")
|
|
|
|
try:
|
|
from app.services.metadata_service import MetadataService, get_metadata_service
|
|
print("✅ MetadataService imported successfully")
|
|
|
|
from app.processors.metadata_analyzer import MetadataAnalyzer
|
|
print("✅ MetadataAnalyzer imported successfully")
|
|
|
|
from app.processors.file_detector import FileDetector, FileType
|
|
print("✅ FileDetector imported successfully")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ Import failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_service_initialization():
|
|
"""Test MetadataService initialization"""
|
|
print("\nTesting MetadataService initialization...")
|
|
|
|
try:
|
|
from app.services.metadata_service import get_metadata_service
|
|
|
|
service = get_metadata_service()
|
|
print("✅ MetadataService initialized successfully")
|
|
|
|
# Check extractors
|
|
print(f" - Extractors: {len(service.extractors)} types")
|
|
|
|
# Check updaters
|
|
print(f" - Updaters: {len(service.updaters)} types")
|
|
|
|
# Check AI analyzer (may be None if no OPENAI_API_KEY)
|
|
analyzer = service.ai_analyzer
|
|
if analyzer:
|
|
print(f"✅ AI Analyzer initialized with model: {analyzer.model}")
|
|
else:
|
|
print("⚠️ AI Analyzer not available (OPENAI_API_KEY not configured)")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ Initialization failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
|
|
def test_ai_metadata_generation():
|
|
"""Test AI metadata generation (if OPENAI_API_KEY is configured)"""
|
|
print("\nTesting AI metadata generation...")
|
|
|
|
try:
|
|
from app.services.metadata_service import get_metadata_service
|
|
from app.processors.file_detector import FileType
|
|
|
|
service = get_metadata_service()
|
|
|
|
# Check if AI is available
|
|
if not service.ai_analyzer:
|
|
print("⚠️ Skipping AI test (OPENAI_API_KEY not configured)")
|
|
return True
|
|
|
|
# Test with sample content
|
|
test_content = """
|
|
This is a technical document about the 3M Filtek Universal Restorative.
|
|
It provides comprehensive shade selection guidelines for dental professionals.
|
|
The document covers proper color matching techniques and application procedures.
|
|
"""
|
|
|
|
test_filename = "3M_Filtek_Shade_Guide.pdf"
|
|
|
|
metadata = service.ai_analyzer.analyze_content(
|
|
content=test_content,
|
|
filename=test_filename,
|
|
file_type=FileType.PDF
|
|
)
|
|
|
|
print(f"✅ AI metadata generated:")
|
|
print(f" - Title: {metadata.get('title', 'N/A')[:80]}...")
|
|
print(f" - Subject: {metadata.get('subject', 'N/A')[:80]}...")
|
|
print(f" - Keywords: {metadata.get('keywords', 'N/A')[:80]}...")
|
|
print(f" - Tokens used: {metadata.get('_tokens_used', 0)}")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ AI generation test failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Run all tests"""
|
|
print("=" * 60)
|
|
print("AI Metadata Generation Integration Test")
|
|
print("=" * 60)
|
|
|
|
results = []
|
|
|
|
# Test imports
|
|
results.append(("Imports", test_imports()))
|
|
|
|
# Test service initialization
|
|
results.append(("Service Init", test_service_initialization()))
|
|
|
|
# Test AI generation (if available)
|
|
results.append(("AI Generation", test_ai_metadata_generation()))
|
|
|
|
# Print summary
|
|
print("\n" + "=" * 60)
|
|
print("Test Summary:")
|
|
print("=" * 60)
|
|
|
|
for test_name, result in results:
|
|
status = "✅ PASS" if result else "❌ FAIL"
|
|
print(f"{status}: {test_name}")
|
|
|
|
all_passed = all(result for _, result in results)
|
|
|
|
if all_passed:
|
|
print("\n🎉 All tests passed!")
|
|
return 0
|
|
else:
|
|
print("\n⚠️ Some tests failed. Check details above.")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|