Spaces:
Runtime error
Runtime error
pawandev commited on
Commit ·
43ca488
1
Parent(s): d62425f
Added new pan model and change ocrsetting and extraction regex as per new model
Browse filesFiles changed (4)
9 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 app9 unmodified lines101112131415169 unmodified lines# Load model onceapp.models = {'adhaarModel': YOLO('models/aadhaarYolov8.pt'),'panModel': YOLO('models/PanModel_v5.pt') # Load additional models as needed}return app
27 unmodified lines2829303132338 unmodified lines4243444546476 unmodified lines5455565758596027 unmodified linesimg_data = base64.b64decode(imgBuffer)img = Image.open(BytesIO(img_data))img.verify() # Verify image formatimg = Image.open(io.BytesIO(img_data)) # Re-open image after verificationexcept (base64.binascii.Error, ValueError) as decode_err:return jsonify({"error": f"Image decoding failed: {str(decode_err)}"}), 4008 unmodified linesresponse = session.get(img_url)response.raise_for_status()img = Image.open(BytesIO(response.content))img.verify() # Verify image formatimg = Image.open(BytesIO(response.content)) # Re-open image after verification6 unmodified lines# Run detectionmodel = current_app.models.get('panModel')results = model.predict(source=img, save=False)# print(results,"model result")extracted_data = process_results(results, img)# print(extracted_data, "extracted data")27 unmodified lines282930313233348 unmodified lines434445464748496 unmodified lines5657585960616227 unmodified linesimg_data = base64.b64decode(imgBuffer)img = Image.open(BytesIO(img_data))img.verify() # Verify image formatprint(img, "img")img = Image.open(io.BytesIO(img_data)) # Re-open image after verificationexcept (base64.binascii.Error, ValueError) as decode_err:return jsonify({"error": f"Image decoding failed: {str(decode_err)}"}), 4008 unmodified linesresponse = session.get(img_url)response.raise_for_status()img = Image.open(BytesIO(response.content))print(img, "img")img.verify() # Verify image formatimg = Image.open(BytesIO(response.content)) # Re-open image after verification6 unmodified lines# Run detectionmodel = current_app.models.get('panModel')results = model.predict(source=img, imgsz=680, iou=0.7, augment=True)# print(results,"model result")extracted_data = process_results(results, img)# print(extracted_data, "extracted data")
2 unmodified lines3456789101112131415163 unmodified lines2021222324252620 unmodified lines474849505152532 unmodified lines# 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_array3 unmodified lines"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']20 unmodified lines# Check and extract PAN numberpan_pattern = re.compile(r'^[A-Z]{5}[0-9]{4}[A-Z]$')for item in cleaned_data:if pan_pattern.match(item):result["data"]["panNo"] = item2 unmodified lines3456789101112131415163 unmodified lines202122232425262720 unmodified lines484950515253542 unmodified lines# Define the regex patternspattern_alphanumeric_special = re.compile(r'[\w]+[^.\s\w]+|[^.\s\w]+[\w]+')pattern_numeric = re.compile(r'^[0-9]+$')pattern_special_chars = re.compile(r'[^a-zA-Z.\s]+')# Filter the arrayfiltered_array = [item for item in arrif not (pattern_alphanumeric_special.search(item) orpattern_numeric.match(item) orpattern_special_chars.search(item))]return filtered_array3 unmodified lines"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',"inent Account Number", "anent Account Number C","Permanent Account Number Car",'ugr Name']20 unmodified lines# Check and extract PAN numberpan_pattern = re.compile(r'^[A-Z]{5}\s*[0-9]{4}\s*[A-Z]$')for item in cleaned_data:if pan_pattern.match(item):result["data"]["panNo"] = item
5 unmodified lines67891011125 unmodified linesdef process_results(results, img):label_indices = {"pan_num": 0, "name": 1, "father": 2, "dob": 3}confidence_threshold = 0.3input_image_format = img.format if img.format else "PNG"valid_formats = ["JPEG", "PNG", "BMP", "GIF", "TIFF"]input_image_format = input_image_format if input_image_format in valid_formats else "PNG"5 unmodified lines67891011125 unmodified linesdef process_results(results, img):label_indices = {"pan_num": 0, "name": 1, "father": 2, "dob": 3}confidence_threshold = 0.4input_image_format = img.format if img.format else "PNG"valid_formats = ["JPEG", "PNG", "BMP", "GIF", "TIFF"]input_image_format = input_image_format if input_image_format in valid_formats else "PNG"
app/__init__.py+1-1
app/routes/panApi.py+3-1
app/services/panServices/panDataExtractor.py+5-4
app/services/panServices/panOcr.py+1-1