PDF_analyst / test_deployment.py
JatsTheAIGen's picture
Initial deployment of PDF Analysis & Orchestrator with enhanced features
2c5e855
#!/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())