Spaces:
Runtime error
Runtime error
Shafeek Saleem commited on
Commit ·
14979bd
1
Parent(s): 641a529
added face detection
Browse filesFiles changed (2)
- .sessions/.gitkeepAdded
- app.py+26-13
1 unmodified line2345678910111213141516171819202122236 unmodified lines30313233343536371 unmodified linefrom PIL import Imageimport face_recognitionst.title("Face Detection")# Load the jpg file into a numpy arrayinput_image = st.file_uploader("Upload a candidate image",type=['jpg','png','jpeg'],accept_multiple_files=False)if input_image is not None:image = face_recognition.load_image_file(input_image)st.image(image)# Find all the faces in the image using the default HOG-based model.# This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.# See also: find_faces_in_picture_cnn.pyface_locations = face_recognition.face_locations(image)data_base = []st.write("I found {} face(s) in this photograph.".format(len(face_locations)))cols= st.columns(len(face_locations))for i in range(len(face_locations)):col = cols[i]face = face_locations[i]6 unmodified linesface_image = image[top:bottom, left:right]pil_image = Image.fromarray(face_image)st.image(pil_image)face_name = st.text_input('Specify name', "This is a placeholder")st.write(face_name)data_base.append(face_name)else:st.write("Please upload an image to proceed.")1 unmodified line2345678910111213141516171819202122232425262728293031326 unmodified lines3940414243444546474849501 unmodified linefrom PIL import Imageimport face_recognitionimport streamlit as stfrom PIL import Imageimport face_recognitionst.header("Face Detection")st.write("Now it's time to collect the pictures we need to create our known-faces data base for our face recognition model. ""But remember, we should always ask for permission before taking someone's picture. We can use a smartphone or a digital camera to capture pictures, and it's important to take pictures of different people. This will help our application to have a good known-faces database!")img_dir = os.path.join(".sessions", "known_faces")os.makedirs(img_dir, exist_ok=True)picture = st.file_uploader("Upload a candidate image",type=['jpg','png','jpeg'],accept_multiple_files=False)if picture:image = face_recognition.load_image_file(picture)st.image(image)# Find all the faces in the image using the default HOG-based model.# This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.# See also: find_faces_in_picture_cnn.pyface_locations = face_recognition.face_locations(image)st.write("Algorithm found {} face(s) in this photograph.".format(len(face_locations)))cols = st.columns(len(face_locations))for i in range(len(face_locations)):col = cols[i]face = face_locations[i]6 unmodified linesface_image = image[top:bottom, left:right]pil_image = Image.fromarray(face_image)st.image(pil_image)face_name = st.text_input('Specify name', "This is a placeholder", key=str(i))if st.button("Save", key=str(i)):img_name = str(uuid.uuid4()) + f"{face_name}" + ".jpg"img_path = os.path.join(img_dir, img_name)with open(img_path, "wb") as f:f.write(pil_image)st.success("Face added successfully!")else:st.write("Please upload an image to proceed.")
.sessions/.gitkeepAdded
app.py+26-13