super-document-processor 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- super_document_processor/__init__.py +28 -0
- super_document_processor/document_processors/process_docx.py +824 -0
- super_document_processor/document_processors/process_images.py +39 -0
- super_document_processor/document_processors/process_msg.py +62 -0
- super_document_processor/document_processors/process_pdf.py +715 -0
- super_document_processor/document_processors/process_plain_text.py +25 -0
- super_document_processor/document_processors/process_pptx.py +367 -0
- super_document_processor/main.py +826 -0
- super_document_processor/processor.py +135 -0
- super_document_processor/utils/aspose_slide_renderer.py +103 -0
- super_document_processor/utils/chunker.py +127 -0
- super_document_processor/utils/docx_image_utils.py +167 -0
- super_document_processor/utils/docx_xml_parser.py +73 -0
- super_document_processor/utils/optimizer.py +49 -0
- super_document_processor/utils/pdf_image_utils.py +90 -0
- super_document_processor/utils/pdf_table_utils.py +627 -0
- super_document_processor/utils/pptx_components_extract.py +2197 -0
- super_document_processor/utils/pptx_converter.py +170 -0
- super_document_processor/utils/vlm.py +176 -0
- super_document_processor-0.1.3.dist-info/METADATA +376 -0
- super_document_processor-0.1.3.dist-info/RECORD +25 -0
- super_document_processor-0.1.3.dist-info/WHEEL +5 -0
- super_document_processor-0.1.3.dist-info/entry_points.txt +2 -0
- super_document_processor-0.1.3.dist-info/licenses/LICENSE +21 -0
- super_document_processor-0.1.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
logger = logging.getLogger("super_document_processor.images")
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from super_document_processor.utils.vlm import generate_image_description
|
|
8
|
+
except ImportError:
|
|
9
|
+
from utils.vlm import generate_image_description
|
|
10
|
+
|
|
11
|
+
def process_image_file(img_path: str, original_filename: str = None, process_images: bool = None, model: str = None) -> dict:
|
|
12
|
+
if not isinstance(img_path, str):
|
|
13
|
+
raise TypeError(f"Image input must be a file path string, got {type(img_path)}")
|
|
14
|
+
|
|
15
|
+
display_name = os.path.basename(original_filename) if original_filename else os.path.basename(img_path)
|
|
16
|
+
|
|
17
|
+
if not process_images:
|
|
18
|
+
raise ValueError(
|
|
19
|
+
f"Processing image file '{display_name}' requires image processing to be enabled.\n"
|
|
20
|
+
"Please enable image processing via CLI (--process-images) or API ('process_images': True)."
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
if not model:
|
|
24
|
+
raise ValueError(
|
|
25
|
+
"Cannot process images: No vision model specified.\n"
|
|
26
|
+
"Please specify a vision-capable model via CLI (--model) or API ('model' parameter)."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
with open(img_path, "rb") as f:
|
|
30
|
+
image_bytes = f.read()
|
|
31
|
+
|
|
32
|
+
description = generate_image_description(image_bytes, model=model)
|
|
33
|
+
logger.debug(f"Generated description for image '{display_name}'")
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
"content": description,
|
|
37
|
+
"chunkIndex": 1,
|
|
38
|
+
"filename": display_name
|
|
39
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import logging
|
|
3
|
+
import extract_msg
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger("super_document_processor.msg")
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from super_document_processor.utils.chunker import collector
|
|
9
|
+
except ImportError:
|
|
10
|
+
from utils.chunker import collector
|
|
11
|
+
|
|
12
|
+
def process_msg_file(filename, original_filename=None):
|
|
13
|
+
"""
|
|
14
|
+
Extract text content from a .msg (Outlook email) file.
|
|
15
|
+
Returns chunks of content similar to other document processors.
|
|
16
|
+
"""
|
|
17
|
+
display_name = os.path.basename(original_filename) if original_filename else os.path.basename(filename)
|
|
18
|
+
try:
|
|
19
|
+
# Open and extract the MSG file
|
|
20
|
+
msg = extract_msg.Message(filename)
|
|
21
|
+
|
|
22
|
+
# Extract main content
|
|
23
|
+
content_parts = []
|
|
24
|
+
|
|
25
|
+
# Subject
|
|
26
|
+
if msg.subject:
|
|
27
|
+
content_parts.append(f"Subject: {msg.subject}")
|
|
28
|
+
|
|
29
|
+
# Sender and recipients
|
|
30
|
+
if msg.sender:
|
|
31
|
+
content_parts.append(f"From: {msg.sender}")
|
|
32
|
+
if msg.to:
|
|
33
|
+
content_parts.append(f"To: {msg.to}")
|
|
34
|
+
if msg.cc:
|
|
35
|
+
content_parts.append(f"CC: {msg.cc}")
|
|
36
|
+
|
|
37
|
+
# Email body
|
|
38
|
+
if msg.body:
|
|
39
|
+
content_parts.append(f"\n{msg.body}")
|
|
40
|
+
|
|
41
|
+
# Combine all content
|
|
42
|
+
full_content = "\n".join(content_parts)
|
|
43
|
+
|
|
44
|
+
# Add to collector for chunking
|
|
45
|
+
collector.add(full_content)
|
|
46
|
+
|
|
47
|
+
# Get chunked texts
|
|
48
|
+
all_chunks = []
|
|
49
|
+
chunked_texts = collector.get_chunked_texts()
|
|
50
|
+
for i, chunk in enumerate(chunked_texts, 1):
|
|
51
|
+
all_chunks.append({
|
|
52
|
+
"content": f"--- Chunk {i} ---\n{chunk}",
|
|
53
|
+
"chunkIndex": i,
|
|
54
|
+
"filename": display_name
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
collector.clear()
|
|
58
|
+
return all_chunks
|
|
59
|
+
|
|
60
|
+
except Exception as e:
|
|
61
|
+
logger.error(f"Error processing MSG file '{display_name}': {e}")
|
|
62
|
+
return []
|