LovnishVerma commited on
Commit
d5985cd
1 Parent(s): 78488d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -6,6 +6,7 @@ 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(
@@ -15,7 +16,7 @@ st.set_page_config(
15
  initial_sidebar_state="collapsed"
16
  )
17
  st.title("Attendance System Using Face Recognition 📷")
18
- st.markdown("This app recognizes faces in an image, verifies Aadhaar card details, and updates attendance records with the current timestamp & Location.")
19
 
20
  # Load images for face recognition
21
  Images = []
@@ -44,20 +45,26 @@ encodeListknown = findEncodings(Images)
44
  # Function to validate Aadhaar card number
45
  def validate_aadhaar(aadhaar):
46
  # Implement your Aadhaar card validation logic here
47
- # For simplicity, let's assume any 12-digit number is a valid Aadhaar card
48
- return len(aadhaar) == 12 and aadhaar.isdigit()
 
 
 
 
 
 
 
49
 
50
- # Take picture using the camera and input Aadhaar card details
51
- img_file_buffer = st.file_uploader("Upload an image", type=["jpg", "jpeg"])
52
- aadhaar_number = st.text_input("Enter Aadhaar Number:")
 
53
 
54
- # Face recognition code...
 
55
 
56
- if img_file_buffer is not None:
57
- # Validate Aadhaar card number
58
- if validate_aadhaar(aadhaar_number):
59
- test_image = Image.open(img_file_buffer)
60
- image = np.asarray(test_image)
61
 
62
  imgS = cv2.resize(image, (0, 0), None, 0.25, 0.25)
63
  imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
@@ -98,6 +105,5 @@ if img_file_buffer is not None:
98
 
99
  if name == "Unknown":
100
  st.info("Face not detected. Please try again.")
101
- else:
102
- st.error("Invalid Aadhaar card number. Please enter a valid 12-digit Aadhaar number.")
103
-
 
6
  import os
7
  from datetime import datetime
8
  import streamlit as st
9
+ from streamlit_webrtc import VideoTransformerBase, webrtc_streamer
10
 
11
  # Set page title and description
12
  st.set_page_config(
 
16
  initial_sidebar_state="collapsed"
17
  )
18
  st.title("Attendance System Using Face Recognition 📷")
19
+ st.markdown("This app recognizes faces in a live camera feed, verifies Aadhaar card details, and updates attendance records with the current timestamp & Location.")
20
 
21
  # Load images for face recognition
22
  Images = []
 
45
  # Function to validate Aadhaar card number
46
  def validate_aadhaar(aadhaar):
47
  # Implement your Aadhaar card validation logic here
48
+ # For simplicity, let's assume any 4-digit number is a valid Aadhaar card
49
+ return len(aadhaar) == 4 and aadhaar.isdigit()
50
+
51
+ # Create a Streamlit component to capture images from the camera
52
+ webrtc_ctx = webrtc_streamer(
53
+ key="example",
54
+ video_transformer_factory=None, # No need for video transformation for this example
55
+ async_transform=True
56
+ )
57
 
58
+ # Main Streamlit app logic
59
+ if webrtc_ctx.video_transformer:
60
+ st.sidebar.markdown("# Capture Image")
61
+ aadhaar_number = st.sidebar.text_input("Enter Aadhaar Number:")
62
 
63
+ # Use the camera feed to capture images
64
+ frame = webrtc_ctx.video_transformer.get_frame()
65
 
66
+ if frame is not None:
67
+ image = np.array(frame.to_image())
 
 
 
68
 
69
  imgS = cv2.resize(image, (0, 0), None, 0.25, 0.25)
70
  imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
 
105
 
106
  if name == "Unknown":
107
  st.info("Face not detected. Please try again.")
108
+ else:
109
+ st.warning("Webcam not available. Please make sure your camera is connected and accessible.")