Ejemplo n.º 1
0
def update_state(file_name):
    payload = {
        'parent_name': globals.PARENT_NAME,
        'group_name': globals.GROUP_NAME,
        'container_name': globals.RECEIVE_TOPIC,
        'file_name': file_name,
        'client_id': globals.CLIENT_ID
    }
    try:
        requests.request("POST", globals.DASHBOARD_URL,  data=payload)
    except Exception as e:
        print(f"{e} EXCEPTION IN UPDATE STATE API CALL......")
        err_logger(f"{e} EXCEPTION IN UPDATE STATE API CALL......FILE ID {FILE_ID}")
Ejemplo n.º 2
0
def save_to_db(db_object, labels, scores):
    try:
        print("*****************SAVING TO DB******************************")
        print("in save")
        print(db_object)
        print(db_object.id)
        db_object.labels = labels
        db_object.scores = scores
        db_object.save()
        print("*****************SAVED TO DB******************************")
    except Exception as e:
        print(" ERROR IN SAVE TO DB")
        err_logger(str(e)+" ERROR IN SAVE TO DB")
Ejemplo n.º 3
0
def save_to_db(db_object, feature_to_save, file):
    try:
        print("*****************SAVING TO DB******************************")
        print("in save")
        feature_obj = Features()
        feature_obj.document = db_object
        feature_obj.feature = feature_to_save
        feature_obj.file = file
        feature_obj.save()
        print("*****************SAVED TO DB******************************")
    except Exception as e:
        print(" ERROR IN SAVE TO DB")
        err_logger(str(e)+" ERROR IN SAVE TO DB")
Ejemplo n.º 4
0
 global_init()
 message = message.value
 db_key = str(message)
 print(db_key, 'db_key')
 FILE_ID = db_key
 try:
     db_object = Cache.objects.get(pk=db_key)
     file_name = db_object.file_name
     print("#############################################")
     print("########## PROCESSING FILE " + file_name)
     print("#############################################")
     final_labels = db_object.labels
     final_scores = db_object.scores
 except Exception as e:
     print("EXCEPTION IN FETCHING FROM DATABASE......")
     err_logger(str(e) + " EXCEPTION IN FETCHING FROM DATABASE......FILE ID " + FILE_ID)
     continue
 if db_object.is_doc_type:
     """document"""
     if db_object.contains_images:
         images_array = []
         for image in db_object.files:
             pdf_image = str(uuid.uuid4()) + ".jpg"
             with open(pdf_image, 'wb') as file_to_save:
                 file_to_save.write(image.file.read())
             images_array.append(pdf_image)
         for image in images_array:
             try:
                 response = predict(file_name=image)
                 for label, score in zip(response["labels"], response['scores']):
                     if label not in final_labels: