LovnishVerma commited on
Commit
ecf75ce
1 Parent(s): 3bb64c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -14
app.py CHANGED
@@ -4,8 +4,8 @@ import cv2
4
  import requests
5
  import face_recognition
6
  import os
7
- from datetime import datetime
8
  import streamlit as st
 
9
 
10
  # Set page title and description
11
  st.set_page_config(
@@ -20,8 +20,9 @@ st.markdown("This app recognizes faces in an image, verifies Aadhaar card detail
20
  # Load images for face recognition
21
  Images = []
22
  classnames = []
23
- directory = "photos"
24
 
 
25
  myList = os.listdir(directory)
26
 
27
  for cls in myList:
@@ -30,16 +31,8 @@ for cls in myList:
30
  curImg = cv2.imread(img_path)
31
  Images.append(curImg)
32
  classnames.append(os.path.splitext(cls)[0])
33
-
34
- def findEncodings(Images):
35
- encodeList = []
36
- for img in Images:
37
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
38
- encode = face_recognition.face_encodings(img)[0]
39
- encodeList.append(encode)
40
- return encodeList
41
-
42
- encodeListknown = findEncodings(Images)
43
 
44
  # Function to validate Aadhaar card number
45
  def validate_aadhaar(aadhaar):
@@ -47,6 +40,18 @@ def validate_aadhaar(aadhaar):
47
  # For simplicity, let's assume any 6-digit number is a valid Aadhaar card
48
  return len(aadhaar) == 6 and aadhaar.isdigit()
49
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Take picture using the camera and input Aadhaar card details
51
  img_file_buffer = st.camera_input("Take a picture")
52
  aadhaar_number = st.text_input("Enter Aadhaar Number:")
@@ -91,11 +96,20 @@ if img_file_buffer is not None:
91
  else:
92
  st.warning("Data not updated")
93
 
 
 
 
 
 
 
 
 
 
 
 
94
  # Apply styling with CSS
95
  st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
96
  st.image(image, use_column_width=True, output_format="PNG")
97
 
98
- if name == "Unknown":
99
- st.info("Face not detected. Please try again.")
100
  else:
101
  st.error("Invalid Aadhaar card number. Please enter a valid 6-digit Aadhaar number.")
 
4
  import requests
5
  import face_recognition
6
  import os
 
7
  import streamlit as st
8
+ import csv
9
 
10
  # Set page title and description
11
  st.set_page_config(
 
20
  # Load images for face recognition
21
  Images = []
22
  classnames = []
23
+ aadhar_numbers = [] # New list to store Aadhaar numbers
24
 
25
+ directory = "photos"
26
  myList = os.listdir(directory)
27
 
28
  for cls in myList:
 
31
  curImg = cv2.imread(img_path)
32
  Images.append(curImg)
33
  classnames.append(os.path.splitext(cls)[0])
34
+ # Assume Aadhaar number is part of the image filename (e.g., "123456_john.jpg")
35
+ aadhar_numbers.append(cls.split('_')[0])
 
 
 
 
 
 
 
 
36
 
37
  # Function to validate Aadhaar card number
38
  def validate_aadhaar(aadhaar):
 
40
  # For simplicity, let's assume any 6-digit number is a valid Aadhaar card
41
  return len(aadhaar) == 6 and aadhaar.isdigit()
42
 
43
+ # Function to read names and Aadhaar numbers from a CSV file
44
+ def read_csv(file_path):
45
+ data = []
46
+ with open(file_path, mode='r') as file:
47
+ reader = csv.reader(file)
48
+ for row in reader:
49
+ data.append(row)
50
+ return data
51
+
52
+ # Load names and Aadhaar numbers from CSV file
53
+ csv_data = read_csv('csv.csv') # Replace 'your_csv_file.csv' with the actual file path
54
+
55
  # Take picture using the camera and input Aadhaar card details
56
  img_file_buffer = st.camera_input("Take a picture")
57
  aadhaar_number = st.text_input("Enter Aadhaar Number:")
 
96
  else:
97
  st.warning("Data not updated")
98
 
99
+ # Display the name corresponding to the entered Aadhaar number
100
+ if name == "Unknown":
101
+ # Match Aadhaar number with the list
102
+ aadhar_index = aadhar_numbers.index(aadhaar_number) if aadhaar_number in aadhar_numbers else None
103
+ if aadhar_index is not None:
104
+ st.success(f"Match found: {csv_data[aadhar_index][0]}")
105
+ else:
106
+ st.warning("Face not detected, and Aadhaar number not found in the database.")
107
+ else:
108
+ st.warning("Aadhaar number is valid, but face recognition failed.")
109
+
110
  # Apply styling with CSS
111
  st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
112
  st.image(image, use_column_width=True, output_format="PNG")
113
 
 
 
114
  else:
115
  st.error("Invalid Aadhaar card number. Please enter a valid 6-digit Aadhaar number.")