LovnishVerma commited on
Commit
2611eb6
·
verified ·
1 Parent(s): 104eaa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -71,25 +71,28 @@ if option == "Home":
71
 
72
  elif option == "Register New Face":
73
  person_name = st.text_input("Enter the person's name")
74
- capture_mode = st.radio("Select input method", ["Use Camera", "Upload Image"])
75
 
76
  if person_name and st.button("Register Face"):
77
  person_dir = os.path.join(KNOWN_FACES_DIR, person_name)
78
  os.makedirs(person_dir, exist_ok=True)
 
79
  if capture_mode == "Use Camera":
80
  st.warning("Switch to a device with a camera for this option.")
81
- elif capture_mode == "Upload Image":
82
- uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
83
- if uploaded_file:
84
- img = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR)
85
- gray, faces = detect_faces(img)
86
- for (x, y, w, h) in faces:
87
- face_img = gray[y:y+h, x:x+w]
88
- resized_img = cv2.resize(face_img, IMG_SIZE)
89
- timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
90
- filepath = os.path.join(person_dir, f"{timestamp}.jpg")
91
- cv2.imwrite(filepath, resized_img)
92
- st.success("Face registered successfully!")
 
 
93
  label_map = train_recognizer()
94
 
95
  elif option == "Recognize Faces":
 
71
 
72
  elif option == "Register New Face":
73
  person_name = st.text_input("Enter the person's name")
74
+ capture_mode = st.radio("Select input method", ["Use Camera", "Upload Image(s)"])
75
 
76
  if person_name and st.button("Register Face"):
77
  person_dir = os.path.join(KNOWN_FACES_DIR, person_name)
78
  os.makedirs(person_dir, exist_ok=True)
79
+
80
  if capture_mode == "Use Camera":
81
  st.warning("Switch to a device with a camera for this option.")
82
+
83
+ elif capture_mode == "Upload Image(s)":
84
+ uploaded_files = st.file_uploader("Upload images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
85
+ if uploaded_files:
86
+ for uploaded_file in uploaded_files:
87
+ img = cv2.imdecode(np.frombuffer(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR)
88
+ gray, faces = detect_faces(img)
89
+ for (x, y, w, h) in faces:
90
+ face_img = gray[y:y+h, x:x+w]
91
+ resized_img = cv2.resize(face_img, IMG_SIZE)
92
+ timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
93
+ filepath = os.path.join(person_dir, f"{timestamp}.jpg")
94
+ cv2.imwrite(filepath, resized_img)
95
+ st.success(f"Faces registered successfully for {person_name}!")
96
  label_map = train_recognizer()
97
 
98
  elif option == "Recognize Faces":