-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from sequestrae_engine.document_parsing.parser import PDFToMarkdownParser | ||
|
||
|
||
def parse_pdfs_command(api_key, project_dir, limit=5): | ||
if limit is None: | ||
limit = 5 | ||
print(f"Max number of files to process: {limit}") | ||
|
||
if not api_key: | ||
print("Error: LLAMA_API_KEY is required") | ||
return 1 | ||
|
||
parser = PDFToMarkdownParser(api_key=api_key) | ||
project_path = Path(project_dir) | ||
|
||
if not project_path.exists(): | ||
print(f"Error: Directory not found at {project_path}") | ||
return 1 | ||
|
||
pdf_count = 0 | ||
for folder_path in project_path.iterdir(): | ||
if not folder_path.name.startswith(".") and folder_path.is_dir() and pdf_count < limit: | ||
for pdf_path in folder_path.glob("*.pdf"): | ||
if pdf_path.is_file() and "report" in pdf_path.stem.lower(): | ||
pdf_count += 1 | ||
parser.parse_pdf(pdf_path) | ||
|
||
print(f"Successfully processed {pdf_count} PDF files") | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import argparse | ||
import os | ||
import sys | ||
|
||
from . import commands | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Sequestrae Engine CLI") | ||
subparsers = parser.add_subparsers(dest="command") | ||
|
||
# Parse PDFs command | ||
parse_pdfs_parser = subparsers.add_parser( | ||
"parse-pdf", help="Parse PDF audit report files to Markdown" | ||
) | ||
parse_pdfs_parser.add_argument( | ||
"--api-key", help="Llama API key", default=os.environ.get("LLAMA_API_KEY") | ||
) | ||
parse_pdfs_parser.add_argument("--project-dir", help="Project data directory", required=True) | ||
parse_pdfs_parser.add_argument("--limit", help="Maximum number of PDFs to process", type=int) | ||
parse_pdfs_parser.set_defaults( | ||
func=lambda args: commands.parse_pdfs_command(args.api_key, args.project_dir, args.limit) | ||
) | ||
|
||
args = parser.parse_args() | ||
if hasattr(args, "func"): | ||
exit_status = args.func(args) | ||
else: | ||
parser.print_help() | ||
exit_status = 1 | ||
return exit_status | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |