Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/report gen #185

Merged
merged 22 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ myenv/
__pycache__/
.DS_Store
**/.DS_Store
env
Binary file added backend/Detection_Engine/GND_LSG.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Empty file.
21 changes: 18 additions & 3 deletions backend/Detection_Engine/biometric_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def biometric_detect_all(self,pdf_path):
# clean up folders
if (pdf_path.endswith('.pdf')):
# extract_images_from_pdf(pdf_path)
images = [f'./Detection_Engine/extracted_images/pdf_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/pdf_images')]

images = [f'./Detection_Engine/extracted_images/pdf_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/pdf_images') if i.endswith('.png')]

output = []
for image in images:
output.append(self.biometric_detect_people(image))
Expand All @@ -71,7 +73,7 @@ def biometric_detect_all(self,pdf_path):

elif (pdf_path.endswith('.docx')):
# extract_images_from_docx(pdf_path)
images = [f'./Detection_Engine/extracted_images/docx_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/docx_images')]
images = [f'./Detection_Engine/extracted_images/docx_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/docx_images') if i.endswith('.png')]
output = []
for image in images:
output.append(self.biometric_detect_people(image))
Expand All @@ -84,7 +86,7 @@ def biometric_detect_all(self,pdf_path):

elif (pdf_path.endswith('.xlsx')):
# extract_images_from_excel(pdf_path)
images = [f'./Detection_Engine/extracted_images/xlsx_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/xlsx_images')]
images = [f'./Detection_Engine/extracted_images/xlsx_images/{i}' for i in os.listdir('./Detection_Engine/extracted_images/xlsx_images') if i.endswith('.png')]
# images = [f'extracted_images/xlsx_images/{i}' for i in os.listdir('extracted_images/xlsx_images')]
output = []
for image in images:
Expand All @@ -95,6 +97,19 @@ def biometric_detect_all(self,pdf_path):
os.remove(file)

return output

directories = [
"./Detection_Engine/extracted_images/xlsx_images",
"./Detection_Engine/extracted_images/docx_images",
"./Detection_Engine/extracted_images/pdf_images"
]

for directory in directories:
all_files = glob.glob(os.path.join(directory, '*'))
for file in all_files:
os.remove(file)

return output



Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions backend/Detection_Engine/detection_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from .regex_layer import regex_layer
from .report_generation_layer import report_generation_layer

import datetime
import os

class detection_engine:

def __init__(self):
Expand Down Expand Up @@ -72,6 +75,36 @@ def process(self, path, path_):
status = "Compliant"
else:
status = "Non-compliant"

#----------------------------------------------------------REPORT GEN------------------------------------------------------------------#

location_report = self.report_generator.location_report_generation(text)
ner_result_report = self.report_generator.ner_report_generation(text)
reg_result_personal_report = self.regex_report_personal(text)
reg_result_financial_report = self.regex_report_financial(text)
reg_result_contact_report = self.regex_report_contact(text)
ca_statement_report = self.report_generator.CA_report_generation(text)
gi_result_report = self.report_generator.gen_report(text)
em_result_report = self.report_generator.EM_report(text)
md_result_report = self.report_generator.MD_report(text)
image_result_report = self.report_generator.Image_report_generation(path_)

violation_data = {
"score": {
"Location": location_report,
"NER": ner_result_report,
"Personal": reg_result_personal_report,
"Financial": reg_result_financial_report,
"Contact": reg_result_contact_report,
"Consent Agreement": ca_statement_report,
"Genetic": gi_result_report,
"Ethnic": em_result_report,
"Medical": md_result_report,
"Biometric": image_result_report,
}
}

#----------------------------------------------------------REPORT GEN END------------------------------------------------------------------#

result = ""
result += status
Expand Down Expand Up @@ -111,6 +144,65 @@ def process(self, path, path_):
# print(path_)
# print(self.report_generator.Image_report(path_))
return result

#----------------------------------------------------------REPORT GEN------------------------------------------------------------------#

def report_generation(self, path, path_):

text = path

location_report = self.report_generator.location_report_generation(text)
ner_result_report = self.report_generator.ner_report_generation(text)
reg_result_personal_report = self.regex_report_personal(text)
reg_result_financial_report = self.regex_report_financial(text)
reg_result_contact_report = self.regex_report_contact(text)
ca_statement_report = self.report_generator.CA_report_generation(text)
gi_result_report = self.report_generator.gen_report(text)
em_result_report = self.report_generator.EM_report(text)
md_result_report = self.report_generator.MD_report(text)
image_result_report = self.report_generator.Image_report_generation(path_)

status = 1

if (reg_result_personal_report > 0 or
reg_result_financial_report > 0 or
reg_result_contact_report > 0 or
gi_result_report > 0 or
em_result_report > 0 or
md_result_report > 0 or
image_result_report > 0):

status = 0


violation_data = {
"score": {
"Status": status,
"Location": location_report,
"NER": ner_result_report,
"Personal": reg_result_personal_report,
"Financial": reg_result_financial_report,
"Contact": reg_result_contact_report,
"Consent Agreement": ca_statement_report,
"Genetic": gi_result_report,
"Ethnic": em_result_report,
"Medical": md_result_report,
"Biometric": image_result_report,
}
}

timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
# output_file = f"violation_report_{timestamp}.pdf"
output_dir = os.path.join(".", "Generated_Reports")
output_file = os.path.join(output_dir, f"violation_report_{timestamp}.pdf")

if not os.path.exists(output_dir):
os.makedirs(output_dir)

self.report_generator.generate_pdf(violation_data, output_file)
return violation_data

#----------------------------------------------------------REPORT GEN END------------------------------------------------------------------#


if __name__ == "__main__":
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading