From 0b96980cc5edaf8ff2e6dee33a75e8fd11112418 Mon Sep 17 00:00:00 2001 From: Isaac Riley Date: Mon, 11 Apr 2022 09:44:47 +0200 Subject: [PATCH] keyword 'show' to fix annotation script without causing problems for non-script usage --- .gitignore | 1 + cv_analysis/figure_detection.py | 2 +- cv_analysis/redaction_detection.py | 2 +- cv_analysis/table_parsing.py | 2 +- scripts/annotate.py | 8 ++++---- src/run_service.py | 6 ------ 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 433612c..f3b659b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ build_venv/ /cv_analysis.egg-info/PKG-INFO /cv_analysis.egg-info/SOURCES.txt /cv_analysis.egg-info/top_level.txt +/.vscode/ diff --git a/cv_analysis/figure_detection.py b/cv_analysis/figure_detection.py index 927a9b7..c4b4b30 100644 --- a/cv_analysis/figure_detection.py +++ b/cv_analysis/figure_detection.py @@ -28,7 +28,7 @@ def detect_figures(image: np.array): return list(rects) -def detect_figures_in_pdf(pdf_path, page_index=1, show=True): +def detect_figures_in_pdf(pdf_path, page_index=1, show=False): page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0] page = np.array(page) diff --git a/cv_analysis/redaction_detection.py b/cv_analysis/redaction_detection.py index 29e49a5..c58e106 100644 --- a/cv_analysis/redaction_detection.py +++ b/cv_analysis/redaction_detection.py @@ -36,7 +36,7 @@ def find_redactions(image: np.array, min_normalized_area=200000): return [] -def annotate_redactions_in_pdf(pdf_path, page_index=1, show=True): +def annotate_redactions_in_pdf(pdf_path, page_index=1, show=False): page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0] page = np.array(page) diff --git a/cv_analysis/table_parsing.py b/cv_analysis/table_parsing.py index 9bfdcba..404b7ed 100644 --- a/cv_analysis/table_parsing.py +++ b/cv_analysis/table_parsing.py @@ -141,7 +141,7 @@ def parse_table(image: np.array, show=False): return list(rects) -def annotate_tables_in_pdf(pdf_path, page_index=0, deskew=False, show=True): +def annotate_tables_in_pdf(pdf_path, page_index=0, deskew=False, show=False): page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0] page = np.array(page) if deskew: diff --git a/scripts/annotate.py b/scripts/annotate.py index 306e60c..03ab3db 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -20,10 +20,10 @@ def parse_args(): if __name__ == "__main__": args = parse_args() if args.type == "table": - annotate_tables_in_pdf(args.pdf_path, page_index=args.page_index) + annotate_tables_in_pdf(args.pdf_path, page_index=args.page_index, show=True) elif args.type == "redaction": - annotate_redactions_in_pdf(args.pdf_path, page_index=args.page_index) + annotate_redactions_in_pdf(args.pdf_path, page_index=args.page_index, show=True) elif args.type == "layout": - annotate_layout_in_pdf(args.pdf_path, page_index=args.page_index) + annotate_layout_in_pdf(args.pdf_path, page_index=args.page_index, show=True) elif args.type == "figure": - detect_figures_in_pdf(args.pdf_path, page_index=args.page_index) + detect_figures_in_pdf(args.pdf_path, page_index=args.page_index, show=True) diff --git a/src/run_service.py b/src/run_service.py index 34d6148..68d1e08 100644 --- a/src/run_service.py +++ b/src/run_service.py @@ -2,7 +2,6 @@ import json import tracemalloc from sys import getsizeof import logging -from typing import List from flask import Flask, request, jsonify from prometheus_client import Counter, Gauge from prometheus_flask_exporter import PrometheusMetrics @@ -21,15 +20,10 @@ from cv_analysis.config import CONFIG def suppress_user_warnings(): import warnings - warnings.filterwarnings("ignore") def main(): - run_server() - - -def run_server(): file_counter = Counter("cv_analysis_file_counter", "count processed files") # page_counter = Counter("cv_analysis_page_counter", "count pages from processed files") ram_metric = Gauge("cv_analysis_memory_usage", "Memory usage in Mb")