-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_usage.py
More file actions
79 lines (60 loc) · 1.86 KB
/
Copy pathbasic_usage.py
File metadata and controls
79 lines (60 loc) · 1.86 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
"""
Basic usage examples for aigrok.
This module demonstrates common usage patterns for the aigrok library.
"""
from aigrok import process_document, Config
def basic_text_extraction():
"""Basic text extraction from a PDF."""
result = process_document(
"sample.pdf", prompt="Extract the main content", model="gpt-3.5-turbo"
)
if result.success:
print(f"Content: {result.text}")
print(f"Page count: {result.page_count}")
else:
print(f"Error: {result.error}")
def structured_data_extraction():
"""Extract structured data in JSON format."""
schema = {
"title": "string",
"authors": ["string"],
"publication_date": "string",
"abstract": "string",
}
result = process_document(
"paper.pdf", prompt="Extract paper metadata", format="json", schema=schema
)
if result.success:
metadata = result.metadata
print(f"Title: {metadata['title']}")
print(f"Authors: {', '.join(metadata['authors'])}")
def vision_analysis():
"""Analyze images in a PDF."""
result = process_document(
"presentation.pdf",
prompt="Describe the charts and images",
model="gpt-4-vision",
)
if result.success:
print(f"Analysis: {result.text}")
def custom_configuration():
"""Example with custom configuration."""
# Load config
config = Config.load()
# Update settings
config.update(
text_model="claude-3",
vision_model="gemini-pro-vision",
ocr_enabled=True,
ocr_languages=["en", "es"],
)
# Save changes
config.save()
# Process with new config
process_document("multilingual.pdf")
print(f"Processed with {config.text_model}")
if __name__ == "__main__":
basic_text_extraction()
structured_data_extraction()
vision_analysis()
custom_configuration()