cv-analysis-service/scripts/client_mock.py
2022-03-14 21:26:49 +01:00

53 lines
1.5 KiB
Python

# python client_mock.py --pdf_path=/home/iriley/Documents/pdfs/unscanned/06.pdf --operations=table-parsing
import argparse
import json
import requests
from vidocp.utils.preprocessing import open_pdf
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--pdf_path", required=True, help="path to PDF file")
parser.add_argument(
"--first_page", type=int, required=False, default=0, help="page number from which to start (starts at 0)"
)
parser.add_argument(
"--last_page",
type=int,
required=False,
default=None,
help="page number at which to stop (non-inclusive); specify None to go to the end",
)
parser.add_argument(
"--operations",
type=str,
required=False,
help="Comma-separated list of operations, any of the following: \ntable-parsing\nredaction-detection\
\nfigure-detection\nlayout-detection",
default="table-parsing"
)
args = parser.parse_args()
return args
def main(args):
# files = {"name": (
# "name",
# open(args.pdf_path, "rb"),
# "file object corresponding to pdf file",
# {"operations": args.operations.split(",")}
# )
# }
response = requests.post("http://127.0.0.1:5000/tables", data=open(args.pdf_path, "rb"))
response.raise_for_status()
predictions = response.json()
print(json.dumps(predictions, indent=2))
if __name__ == "__main__":
args = parse_args()
main(args)