|
|
|
|
|
import os |
|
|
os.environ["TOKENIZERS_PARALLELISM"] = "false" |
|
|
os.environ["EASYOCR_NO_PROGRESS"] = "1" |
|
|
|
|
|
|
|
|
import streamlit as st |
|
|
|
|
|
st.set_page_config( |
|
|
page_title="eKYC PAN Verification", |
|
|
layout="wide" |
|
|
) |
|
|
|
|
|
st.title("eKYC β PAN Card Verification System") |
|
|
|
|
|
|
|
|
import logging |
|
|
|
|
|
from preprocess import read_image, extract_id_card, save_image |
|
|
from ocr_engine import extract_text |
|
|
from postprocess import extract_information |
|
|
from face_verification import detect_and_extract_face, face_comparison, get_face_embeddings |
|
|
from db import init_db, insert_record, check_duplicate |
|
|
|
|
|
|
|
|
os.makedirs("logs", exist_ok=True) |
|
|
os.makedirs("data/intermediate", exist_ok=True) |
|
|
|
|
|
logging.basicConfig( |
|
|
filename="logs/ekyc.log", |
|
|
level=logging.INFO, |
|
|
format="[%(asctime)s: %(levelname)s]: %(message)s" |
|
|
) |
|
|
|
|
|
init_db() |
|
|
|
|
|
|
|
|
id_image = st.file_uploader( |
|
|
"Upload PAN Card Image", |
|
|
type=["jpg", "png", "jpeg"] |
|
|
) |
|
|
|
|
|
face_image = st.file_uploader( |
|
|
"Upload Face Image", |
|
|
type=["jpg", "png", "jpeg"] |
|
|
) |
|
|
|
|
|
|
|
|
if id_image and face_image: |
|
|
with st.spinner("Processing... Please wait"): |
|
|
try: |
|
|
face_img = read_image(face_image, is_uploaded=True) |
|
|
id_img = read_image(id_image, is_uploaded=True) |
|
|
|
|
|
roi, _ = extract_id_card(id_img) |
|
|
|
|
|
id_face_path = detect_and_extract_face(roi) |
|
|
uploaded_face_path = save_image( |
|
|
face_img, |
|
|
"uploaded_face.jpg", |
|
|
"data/intermediate" |
|
|
) |
|
|
|
|
|
if not face_comparison(uploaded_face_path, id_face_path): |
|
|
st.error("β Face verification failed") |
|
|
st.stop() |
|
|
|
|
|
extracted_text = extract_text(roi) |
|
|
info = extract_information(extracted_text) |
|
|
|
|
|
if check_duplicate(info["ID"]): |
|
|
st.warning("β User already exists") |
|
|
else: |
|
|
info["DOB"] = info["DOB"].strftime("%Y-%m-%d") |
|
|
info["Embedding"] = get_face_embeddings(uploaded_face_path) |
|
|
insert_record(info) |
|
|
st.success("β
User registered successfully") |
|
|
|
|
|
st.subheader("Extracted Information") |
|
|
st.json(info) |
|
|
|
|
|
except Exception as e: |
|
|
st.error(f"Error occurred: {e}") |
|
|
|