Example #1
0
 def post(self):
     json_data = request.get_json(force=True)
     app_context.init()
     app_context.application_context = json_data
     log_info(
         "Resource Layout_Detector_WF  Layout_Detector service started",
         app_context.application_context)
     task_id = str("LD-" + str(time.time()).replace('.', '')[0:13])
     task_starttime = eval(str(time.time()).replace('.', '')[0:13])
     #json_data = request.get_json(force = True)
     try:
         error_validator = ValidationResponse(DOWNLOAD_FOLDER)
         if error_validator.format_error(json_data) is True:
             response_gen = Response(json_data, DOWNLOAD_FOLDER)
             response = response_gen.workflow_response(
                 task_id, task_starttime)
             log_info(
                 "Resource Layout_Detector_WF Layout_Detector api response completed",
                 app_context.application_context)
             return jsonify(response)
     except FormatError as e:
         log_error(
             "Resource Layout_Detector_WF Input json format is not correct or dict_key is missing",
             app_context.application_context, e)
         return Status.ERR_request_input_format.value
Example #2
0
    def nonwf_response(self):
        log_info("non workflow response started the response generation",
                 app_context.application_context)
        input_files = self.json_data['input']['inputs']
        app_context.init()
        app_context.application_context = self.json_data
        error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)
        try:
            error_validator.inputfile_list_error(input_files)
            # output_file_response = list()
            # for item in input_files:
            #     input_filename, in_file_type, identifier = file_ops.accessing_files(item['file'])
            #     output_json_data = DocumentStructure(None, input_filename)
            #     output_filename_json = file_ops.writing_json_file(i, output_json_data, self.DOWNLOAD_FOLDER)
            #     file_res = file_ops.one_filename_response(input_filename, output_filename_json, in_file_type)
            #     output_file_response.append(file_res)
            response_true = Status.SUCCESS.value
            #response_true['output'] = output_file_response

            output_json_data = Service(app_context=app_context)
            output_filename_json = file_ops.writing_json_file(
                0, output_json_data, self.DOWNLOAD_FOLDER)
            response_true = file_ops.one_filename_response(
                output_filename_json, langs=' ')

            log_info(
                "non workflow_response successfully generated response for rest server",
                app_context.application_context)
            response_true = copy.deepcopy(response_true)
            return response_true

        except FileErrors as e:
            response_custom = Status.ERR_STATUS.value
            response_custom['message'] = e.message
            response = file_ops.error_handler(response_custom, e.code, False)
            log_exception(
                "non workflow_response some error occured while validating file",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except ServiceError as e:
            response_custom = Status.ERR_STATUS.value
            response_custom['message'] = str(e)
            response = file_ops.error_handler(response_custom, "SERVICE_ERROR",
                                              False)
            log_exception(
                "non workflow_response Something went wrong during ocr.",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
Example #3
0
    def post(self):
        json_data = request.get_json(force=True)
        app_context.init()
        app_context.application_context = json_data
        log_info("Resource Vision_OCR service started", app_context.application_context)

        try:
            error_validator = ValidationResponse(DOWNLOAD_FOLDER)
            if error_validator.format_error(json_data) is True:
                response_gen = Response(json_data, DOWNLOAD_FOLDER)
                response = response_gen.nonwf_response()
                log_info("Resource Vision_OCR api response completed", app_context.application_context)
                return jsonify(response)
        except FormatError as e:
            log_error("Resource Vision_OCR Input json format is not correct or dict_key is missing", app_context.application_context, e)
            return Status.ERR_request_input_format.value
Example #4
0
    def workflow_response(self, task_id, task_starttime, debug_flush=False):

        app_context.init()
        app_context.application_context = {}

        input_files, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(self.json_data)
        log_info("workflow_response started the response generation", app_context.application_context)
        error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)
        try:
            error_validator.wf_keyerror(jobid, workflow_id, tool_name, step_order)
            error_validator.inputfile_list_error(input_files)
            output_file_response = list()
            for i, item in enumerate(input_files):
                input_filename, in_file_type, in_locale     = file_ops.accessing_files(item)
                self.json_data['taskID']                   = task_id
                app_context.application_context             = self.json_data
                
                if debug_flush == False:
                    bm_response = DocumentStructure(app_context=app_context, file_name=input_filename, lang=in_locale)
                    if bm_response['code'] == 200:
                        
                        output_filename_json = file_ops.writing_json_file(i, bm_response['rsp'], self.DOWNLOAD_FOLDER)
                        file_res = file_ops.one_filename_response(input_filename, output_filename_json, in_locale, in_file_type)
                        output_file_response.append(file_res)
                        task_endtime = str(time.time()).replace('.', '')
                        response_true = CustomResponse(Status.SUCCESS.value, jobid, task_id)
                        response_success = response_true.success_response(workflow_id, task_starttime, task_endtime, tool_name, step_order, output_file_response)
                        response = copy.deepcopy(response_success)
                        log_info("successfully generated response for workflow", app_context.application_context)
                        
                        return response
                    else:
                        post_error_wf(bm_response.code, bm_response.message, app_context.application_context, None)
                        return None
                else:
                    log_info('flushing queue data, not handling file {}'.format(input_files), app_context.application_context)
                    post_error_wf(400, 'flushing queue data, not handling file {}'.format(input_files), app_context.application_context, None)
                    return None

            
        except WorkflowkeyError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code, "WORKFLOWKEY-ERROR", True)
            log_exception("workflow_response workflow key error: key value missing", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except FileErrors as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = e.message
            response = file_ops.error_handler(response_custom.status_code, e.code, True)
            log_exception("workflow_response some error occured while validating file", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except ServiceError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid, task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code, "SERVICE_ERROR", True)
            log_exception("workflow_response Something went wrong during pdf to block conversion.", app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
Example #5
0
from anuvaad_auditor.loghandler import log_info
from anuvaad_auditor.loghandler import log_error
from src.services import main
from src.services.get_underline import get_underline
from services import get_xml
from src.services.child_text_unify_to_parent import ChildTextUnify
from services.preprocess import prepocess_pdf_regions
from services.get_tables import page_num_correction, get_text_table_line_df
from src.services.ocr_text_utilities import tesseract_ocr
from src.services.get_response import process_image_df, process_table_df, df_to_json, process_line_df

from utilities.filesystem import (create_directory, read_directory_files)
import config

import src.utilities.app_context as app_context
app_context.init()

from src.services import main


def run_test(document_directory):
    start_time = time.time()

    files = read_directory_files(document_directory, "*.pdf")
    for file in files:
        app_context.application_context = dict({
            'task_id':
            'BM-DUMMY',
            'filename':
            os.path.basename(file)
        })
Example #6
0
    def workflow_response(self, task_id, task_starttime):

        app_context.init()
        app_context.application_context = self.json_data

        input_params, workflow_id, jobid, tool_name, step_order = file_ops.json_input_format(
            self.json_data)
        log_info("workflow_response started the response generation",
                 app_context.application_context)
        error_validator = ValidationResponse(self.DOWNLOAD_FOLDER)

        try:
            error_validator.wf_keyerror(jobid, workflow_id, tool_name,
                                        step_order)

            # --------------------------

            result = process_incoming_request(app_context, input_params[0],
                                              jobid, workflow_id)

            # --------------------------

            task_endtime = eval(str(time.time()).replace('.', '')[0:13])
            response_true = CustomResponse(Status.SUCCESS.value, jobid,
                                           task_id)
            response_success = response_true.success_response(
                workflow_id, task_starttime, task_endtime, tool_name,
                step_order, result)
            log_info(
                "workflow_response : successfully generated response for workflow",
                app_context.application_context)
            return response_success

        except WorkflowkeyError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code,
                                              "WORKFLOWKEY-ERROR", True)
            log_exception(
                "workflow_response workflow key error: key value missing",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except FileErrors as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = e.message
            response = file_ops.error_handler(response_custom.status_code,
                                              e.code, True)
            log_exception(
                "workflow_response some error occured while validating file",
                app_context.application_context, e)
            response = copy.deepcopy(response)
            return response
        except ServiceError as e:
            response_custom = CustomResponse(Status.ERR_STATUS.value, jobid,
                                             task_id)
            response_custom.status_code['message'] = str(e)
            response = file_ops.error_handler(response_custom.status_code,
                                              "SERVICE_ERROR", True)
            log_exception("workflow_response Something went wrong during ocr.",
                          app_context.application_context, e)
            response = copy.deepcopy(response)
            return response