#!/usr/bin/env python3 """ Test script for PDF Analysis & Orchestrator deployment Run this to verify all components are working correctly """ import os import sys import asyncio from pathlib import Path def test_imports(): """Test that all required modules can be imported""" print("šŸ” Testing imports...") try: import gradio as gr print("āœ… Gradio imported successfully") except ImportError as e: print(f"āŒ Gradio import failed: {e}") return False try: import openai print("āœ… OpenAI imported successfully") except ImportError as e: print(f"āŒ OpenAI import failed: {e}") return False try: import pdfplumber print("āœ… pdfplumber imported successfully") except ImportError as e: print(f"āŒ pdfplumber import failed: {e}") return False try: import numpy as np print("āœ… NumPy imported successfully") except ImportError as e: print(f"āŒ NumPy import failed: {e}") return False try: from reportlab.lib.pagesizes import letter print("āœ… ReportLab imported successfully") except ImportError as e: print(f"āŒ ReportLab import failed: {e}") return False return True def test_config(): """Test configuration loading""" print("\nšŸ”§ Testing configuration...") try: from config import Config print("āœ… Config module imported successfully") # Test configuration values print(f" - OpenAI Model: {Config.OPENAI_MODEL}") print(f" - Chunk Size: {Config.CHUNK_SIZE}") print(f" - Cache Enabled: {Config.CACHE_ENABLED}") print(f" - Max Upload MB: {Config.MAX_FILE_SIZE_MB}") return True except Exception as e: print(f"āŒ Config test failed: {e}") return False def test_utils(): """Test utility functions""" print("\nšŸ› ļø Testing utilities...") try: from utils import chunk_text, get_file_hash, load_pdf_text_cached print("āœ… Core utilities imported successfully") # Test chunking test_text = "This is a test document. " * 1000 # Create long text chunks = chunk_text(test_text, 100) print(f" - Chunking test: {len(chunks)} chunks created") # Test file hash test_file = Path("test.txt") test_file.write_text("test content") file_hash = get_file_hash(str(test_file)) print(f" - File hash test: {file_hash[:8]}...") test_file.unlink() # Clean up return True except Exception as e: print(f"āŒ Utils test failed: {e}") return False def test_agents(): """Test agent initialization""" print("\nšŸ¤– Testing agents...") try: from agents import AnalysisAgent, CollaborationAgent, ConversationAgent, MasterOrchestrator print("āœ… Agent classes imported successfully") # Test agent creation analysis_agent = AnalysisAgent("TestAgent", "gpt-4", 0) print(" - AnalysisAgent created successfully") # Test orchestrator agents = { "analysis": analysis_agent, "collab": CollaborationAgent("TestCollab", "gpt-4", 0), "conversation": ConversationAgent("TestConv", "gpt-4", 0) } orchestrator = MasterOrchestrator(agents) print(" - MasterOrchestrator created successfully") return True except Exception as e: print(f"āŒ Agents test failed: {e}") return False def test_managers(): """Test manager classes""" print("\nšŸ“‹ Testing managers...") try: from utils.prompts import PromptManager from utils.export import ExportManager print("āœ… Manager classes imported successfully") # Test prompt manager prompt_manager = PromptManager() prompts = prompt_manager.get_all_prompts() print(f" - PromptManager: {len(prompts)} default prompts loaded") # Test export manager export_manager = ExportManager() print(" - ExportManager created successfully") return True except Exception as e: print(f"āŒ Managers test failed: {e}") return False def test_environment(): """Test environment variables""" print("\nšŸŒ Testing environment...") openai_key = os.environ.get("OPENAI_API_KEY") if openai_key: print("āœ… OPENAI_API_KEY is set") print(f" - Key starts with: {openai_key[:8]}...") else: print("āš ļø OPENAI_API_KEY not set (required for full functionality)") # Check other important environment variables env_vars = [ "OPENAI_MODEL", "CHUNK_SIZE", "CACHE_ENABLED", "ANALYSIS_MAX_UPLOAD_MB" ] for var in env_vars: value = os.environ.get(var) if value: print(f" - {var}: {value}") else: print(f" - {var}: using default") return True def test_gradio_interface(): """Test Gradio interface creation""" print("\nšŸŽØ Testing Gradio interface...") try: # Import the main app components from app import demo print("āœ… Gradio interface created successfully") # Test if the interface has the expected components if hasattr(demo, 'blocks'): print(" - Interface has blocks structure") return True except Exception as e: print(f"āŒ Gradio interface test failed: {e}") return False def main(): """Run all tests""" print("šŸš€ PDF Analysis & Orchestrator - Deployment Test") print("=" * 50) tests = [ test_imports, test_config, test_utils, test_agents, test_managers, test_environment, test_gradio_interface ] passed = 0 total = len(tests) for test in tests: try: if test(): passed += 1 except Exception as e: print(f"āŒ Test {test.__name__} failed with exception: {e}") print("\n" + "=" * 50) print(f"šŸ“Š Test Results: {passed}/{total} tests passed") if passed == total: print("šŸŽ‰ All tests passed! Your deployment is ready.") return 0 else: print("āš ļø Some tests failed. Please check the errors above.") return 1 if __name__ == "__main__": sys.exit(main())