Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Simple test for the Document Classification application | |
| """ | |
| import os | |
| import sys | |
| # Load .env file only in development (optional) | |
| try: | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| except ImportError: | |
| pass # dotenv not available in production | |
| def test_imports(): | |
| """Test that all modules can be imported.""" | |
| print("π§ͺ Testing Document Classification Structure") | |
| print("=" * 50) | |
| try: | |
| from pdf_qa.pdf_processor import PDFProcessor | |
| from pdf_qa.product_classifier import ProductClassifier | |
| print("β All modules imported successfully") | |
| # Test initialization | |
| pdf_processor = PDFProcessor() | |
| classifier = ProductClassifier() | |
| print("β Components initialized successfully") | |
| # Test classification methods | |
| test_products = { | |
| "test": { | |
| "name": "Test Product", | |
| "description": "A test product for classification", | |
| "keywords": ["test", "product"] | |
| } | |
| } | |
| # Test classifier initialization | |
| classifier = ProductClassifier(test_products) | |
| print("β Classification methods available") | |
| # Check API key | |
| if not os.getenv("OPENAI_API_KEY"): | |
| print("β οΈ OPENAI_API_KEY not set (expected for testing)") | |
| else: | |
| print("β OPENAI_API_KEY found") | |
| print("\nπ Document classification structure working correctly!") | |
| print("\nTo run the app:") | |
| print("1. Set OPENAI_API_KEY environment variable") | |
| print("2. Run: python app.py") | |
| return True | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| return False | |
| if __name__ == "__main__": | |
| success = test_imports() | |
| sys.exit(0 if success else 1) | |