Spaces:
Runtime error
Runtime error
pawandev commited on
Commit ·
3951fa7
1
Parent(s): 6d78d98
Added new model and did some modification in script of pan data extraction
Browse filesFiles changed (3)
9 unmodified lines101112131415169 unmodified lines# Load model onceapp.models = {'adhaarModel': YOLO('models/aadhaarYolov8.pt'),'panModel': YOLO('models/PanModal_v3.pt') # Load additional models as needed}return app9 unmodified lines101112131415169 unmodified lines# Load model onceapp.models = {'adhaarModel': YOLO('models/aadhaarYolov8.pt'),'panModel': YOLO('models/PanYolo_v4.pt') # Load additional models as needed}return app
12341 unmodified line678910111214 unmodified lines2728293031323311 unmodified lines4546474849505152535455565714 unmodified lines72737475import redef extract_panData(data):unwanted_words = ["Name", "/Name", 'Permanent', 'Account', 'Number', 'Card', 'नाम', '/Name',1 unmodified line"VIT VE Hra / Father's Nama", 'पिता का नाम/ Fal', 'पिता का नाम / Fathe', "पिता का नाम / Father's Na",'जन्म की तारीख /।', 'जन्म का ताराख', "पिता का नाम/ Father's Nam", 'नाम /Name', "पिता का नाम / Father's Name",'जन्म का वाराज़', 'Date of Birth', 'Permanent Account Number Card', "Date of Birth", "/Date of Birth","Permanent Account Number", "Father's Name", "14 /Name", "/Father's Name"]# Initialize result objectresult = {14 unmodified linesfor item in data:if item not in unwanted_words and not combination_pattern.search(item):cleaned_data.append(item)# Check and extract PAN numberpan_pattern = re.compile(r'^[A-Z]{5}[0-9]{4}[A-Z]$')for item in cleaned_data:11 unmodified linesbreak# If only two values are left, assume they are name and father's nameif len(cleaned_data) == 2:result["data"]["name"] = cleaned_data[0]result["data"]["fatherName"] = cleaned_data[1]else:# Further cleaning of the data array to extract name and father's namecleaned_data = [item for item in cleaned_data if not combination_pattern.search(item) and item not in unwanted_words]# Check and extract namename_pattern = re.compile(r'^[A-Za-z .]+$')if len(cleaned_data) > 0 and name_pattern.match(cleaned_data[0]):14 unmodified linesresult["error"] = f"{key} value is not found due to bad image."breakreturn result1234567891011121314151617181 unmodified line2021222324252627282914 unmodified lines444546474849505111 unmodified lines636465666768697071727374757614 unmodified lines91929394import redef filter_array(arr):# Define the regex patternspattern_alphanumeric_special = re.compile(r'[\w]+[^.\s\w]+|[^.\s\w]+[\w]+')pattern_numeric = re.compile(r'^[0-9]+$')pattern_non_alpha = re.compile(r'[^.\s]*[^a-zA-Z\s][^.\s]*')# Filter the arrayfiltered_array = [item for item in arrif not (pattern_alphanumeric_special.search(item) orpattern_numeric.match(item) orpattern_non_alpha.search(item))]return filtered_arraydef extract_panData(data):unwanted_words = ["Name", "/Name", 'Permanent', 'Account', 'Number', 'Card', 'नाम', '/Name',1 unmodified line"VIT VE Hra / Father's Nama", 'पिता का नाम/ Fal', 'पिता का नाम / Fathe', "पिता का नाम / Father's Na",'जन्म की तारीख /।', 'जन्म का ताराख', "पिता का नाम/ Father's Nam", 'नाम /Name', "पिता का नाम / Father's Name",'जन्म का वाराज़', 'Date of Birth', 'Permanent Account Number Card', "Date of Birth", "/Date of Birth","Permanent Account Number", "Father's Name", "14 /Name", "/Father's Name", 'HTH / Name']# Initialize result objectresult = {14 unmodified linesfor item in data:if item not in unwanted_words and not combination_pattern.search(item):cleaned_data.append(item)# Check and extract PAN numberpan_pattern = re.compile(r'^[A-Z]{5}[0-9]{4}[A-Z]$')for item in cleaned_data:11 unmodified linesbreak# If only two values are left, assume they are name and father's namecleaned_data = filter_array(cleaned_data)if len(cleaned_data) == 2:result["data"]["name"] = cleaned_data[0]result["data"]["fatherName"] = cleaned_data[1]else:# Further cleaning of the data array to extract name and father's namecleaned_data = [item for item in cleaned_data if not combination_pattern.search(item) and item not in unwanted_words]print(cleaned_data, "after cleaning")# Check and extract namename_pattern = re.compile(r'^[A-Za-z .]+$')if len(cleaned_data) > 0 and name_pattern.match(cleaned_data[0]):14 unmodified linesresult["error"] = f"{key} value is not found due to bad image."breakreturn result
1 unmodified line23456781 unmodified linefrom ...utils.azureOCR import analyze_imagefrom ...utils.imageUtils import resize_if_needed, all_cropped_images_to_one_imagefrom .panDataExtractor import extract_panDatafrom collections import defaultdictdef process_results(results, img):label_indices = {"pan_num": 0, "name": 1, "father": 2, "dob": 3}1 unmodified line23456781 unmodified linefrom ...utils.azureOCR import analyze_imagefrom ...utils.imageUtils import resize_if_needed, all_cropped_images_to_one_imagefrom .panDataExtractor import extract_panData# from collections import defaultdictdef process_results(results, img):label_indices = {"pan_num": 0, "name": 1, "father": 2, "dob": 3}
app/__init__.py+1-1
app/services/panServices/panDataExtractor.py+23-4
app/services/panServices/panOcr.py+1-1