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 lines10111213131415169 unmodified lines # Load model once app.models = { 'adhaarModel': YOLO('models/aadhaarYolov8.pt'), 'panModel': YOLO('models/PanModal_v3.pt') # Load additional models as needed 'panModel': YOLO('models/PanYolo_v4.pt') # Load additional models as needed }
return app1234567891011121314151617181 unmodified line20212292324252627282914 unmodified lines44454630474849505111 unmodified lines63646566676869707172547374757614 unmodified lines9192937594import redef filter_array(arr): # Define the regex patterns pattern_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 array filtered_array = [ item for item in arr if not (pattern_alphanumeric_special.search(item) or pattern_numeric.match(item) or pattern_non_alpha.search(item)) ] return filtered_array
def 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"] "Permanent Account Number", "Father's Name", "14 /Name", "/Father's Name", 'HTH / Name']
# Initialize result object result = {14 unmodified lines for item in data: if item not in unwanted_words and not combination_pattern.search(item): cleaned_data.append(item)
# Check and extract PAN number pan_pattern = re.compile(r'^[A-Z]{5}[0-9]{4}[A-Z]$') for item in cleaned_data:11 unmodified lines break
# If only two values are left, assume they are name and father's name cleaned_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 name cleaned_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 name name_pattern = re.compile(r'^[A-Za-z .]+$') if len(cleaned_data) > 0 and name_pattern.match(cleaned_data[0]):14 unmodified lines result["error"] = f"{key} value is not found due to bad image." break return result return result1 unmodified line234556781 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 defaultdict# from collections import defaultdict
def 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