-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
executable file
·169 lines (129 loc) · 5.21 KB
/
demo.py
File metadata and controls
executable file
·169 lines (129 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
"""
PPARSER System Demonstration Script
==================================
This script demonstrates the complete PPARSER multiagent system functionality.
"""
import asyncio
import sys
from pathlib import Path
# Add the current directory to the path for imports
sys.path.insert(0, str(Path(__file__).parent))
from pparser import __version__
from pparser.config import Config
from pparser.utils.logger import get_logger, setup_logging
logger = get_logger(__name__)
async def demo_system_status():
"""Demonstrate system status and configuration."""
print("PPARSER - Multiagent PDF to Markdown Converter")
print("=" * 60)
print(f"Version: {__version__}")
print()
# Load configuration
config = Config()
print("Configuration:")
print(f" • OpenAI Model: {config.openai_model}")
print(f" • Temperature: {config.openai_temperature}")
print(f" • Max Tokens: {config.openai_max_tokens}")
print(f" • Max Concurrent Pages: {config.max_concurrent_pages}")
print(f" • Chunk Size: {config.chunk_size}")
print(f" • Output Format: {config.output_format}")
print()
print("System Components:")
# Test imports
try:
from pparser.extractors import (
TextExtractor, ImageExtractor, TableExtractor,
FormulaExtractor, FormExtractor
)
print(" Content Extractors loaded successfully")
from pparser.agents import (
TextAnalysisAgent, ImageAnalysisAgent, TableAnalysisAgent,
FormulaAnalysisAgent, FormAnalysisAgent, StructureBuilderAgent,
QualityValidatorAgent
)
print(" LLM Agents loaded successfully")
from pparser.workflows import PDFWorkflow, BatchWorkflow
print(" LangGraph Workflows loaded successfully")
from pparser.processors import PDFProcessor, BatchProcessor
print(" Main Processors loaded successfully")
except Exception as e:
print(f" Import error: {e}")
return False
print()
print("System Status: All components loaded successfully!")
print()
# Demonstrate workflow visualization
try:
from pparser.processors import PDFProcessor
processor = PDFProcessor(config)
print("Workflow Visualization:")
print("-" * 30)
workflow_viz = processor.get_workflow_visualization()
print("Mermaid diagram generated successfully")
print(f"Diagram length: {len(workflow_viz)} characters")
print()
except Exception as e:
print(f" Workflow visualization error: {e}")
print("Available CLI Commands:")
print(" • python -m pparser single <pdf> -o <output>")
print(" • python -m pparser batch <input_dir> -o <output_dir>")
print(" • python -m pparser filelist <list.txt> -o <output_dir>")
print(" • python -m pparser status")
print(" • python -m pparser workflow")
print()
return True
async def demo_workflow_creation():
"""Demonstrate workflow creation without processing."""
print("Workflow Architecture:")
print("-" * 30)
try:
from pparser.workflows.pdf_workflow import PDFWorkflow
from langgraph.graph import StateGraph
# Create a workflow instance
workflow = PDFWorkflow()
print(" PDF Workflow created")
print(f" • Nodes: {len(workflow.workflow.nodes) if hasattr(workflow.workflow, 'nodes') else 'N/A'}")
print(" • Processing stages: Extract → Analyze → Build → Validate")
print()
# Show workflow stages
stages = [
"1. Content Extraction (Text, Images, Tables, Formulas, Forms)",
"2. LLM Analysis (Structure, Context, Enhancement)",
"3. Document Assembly (Markdown Generation)",
"4. Quality Validation (Content Check, Improvement)"
]
for stage in stages:
print(f" {stage}")
print()
except Exception as e:
print(f" Workflow creation error: {e}")
def main():
"""Main demonstration function."""
setup_logging(level="INFO")
print("\n" + "=" * 60)
print("PPARSER SYSTEM DEMONSTRATION")
print("=" * 60)
try:
# Run the async demonstration
result = asyncio.run(demo_system_status())
if result:
asyncio.run(demo_workflow_creation())
print("Demonstration completed successfully!")
print()
print("Next steps:")
print("1. Prepare PDF files for processing")
print("2. Use 'python -m pparser single <file>' to process individual PDFs")
print("3. Use 'python -m pparser batch <dir>' for bulk processing")
print("4. Check output Markdown files and extracted assets")
print()
else:
print("System validation failed")
return 1
except Exception as e:
logger.error(f"Demonstration failed: {e}", exc_info=True)
return 1
return 0
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)