Spaces:
Runtime error
Runtime error
Shafeek Saleem
commited on
Commit
·
c372b9c
1
Parent(s):
b9b29a1
bug fixed images
Browse files
pages/2_Face Detection and Creating Database.py
CHANGED
|
@@ -56,7 +56,7 @@ def step2_page():
|
|
| 56 |
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!
|
| 57 |
"""
|
| 58 |
)
|
| 59 |
-
st.
|
| 60 |
face_name = st.text_input('Specify name to save it in the known-face database', "This is a placeholder", key="name")
|
| 61 |
input_type = st.radio("Select the Input Type", ["Image", "Camera"])
|
| 62 |
|
|
@@ -96,13 +96,16 @@ def step2_page():
|
|
| 96 |
face_name = st.text_input('Who is this?',
|
| 97 |
"This is a placeholder", key="text_" + str(i))
|
| 98 |
if st.button("Save", key="button_" + str(i)):
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
if os.path.exists(img_path):
|
| 102 |
-
st.error("Face already added!")
|
| 103 |
else:
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
else:
|
| 108 |
st.info("Your face is identified successfully!")
|
|
@@ -116,30 +119,28 @@ def step2_page():
|
|
| 116 |
st.image(pil_image, use_column_width="auto")
|
| 117 |
st.write(face_name)
|
| 118 |
if st.button("Save", key="button"):
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
if os.path.exists(img_path):
|
| 122 |
-
st.error("Face already added!")
|
| 123 |
else:
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
|
| 128 |
-
st.
|
| 129 |
images = os.listdir(img_dir)
|
| 130 |
if len(images) <= 0:
|
| 131 |
-
st.
|
| 132 |
else:
|
| 133 |
cols = st.columns(len(images))
|
| 134 |
-
for i in
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
with col:
|
| 139 |
-
face = face_recognition.load_image_file(images[i])
|
| 140 |
-
face_name = images[i].split("_")[1]
|
| 141 |
-
st.image(face, use_column_width="auto")
|
| 142 |
-
st.write(face_name)
|
| 143 |
|
| 144 |
if st.button("Clear All"):
|
| 145 |
for img in images:
|
|
|
|
| 56 |
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!
|
| 57 |
"""
|
| 58 |
)
|
| 59 |
+
st.subheader("Who is taking the picture?")
|
| 60 |
face_name = st.text_input('Specify name to save it in the known-face database', "This is a placeholder", key="name")
|
| 61 |
input_type = st.radio("Select the Input Type", ["Image", "Camera"])
|
| 62 |
|
|
|
|
| 96 |
face_name = st.text_input('Who is this?',
|
| 97 |
"This is a placeholder", key="text_" + str(i))
|
| 98 |
if st.button("Save", key="button_" + str(i)):
|
| 99 |
+
if face_name == "This is a placeholder":
|
| 100 |
+
st.error("Please provide a name for the face!")
|
|
|
|
|
|
|
| 101 |
else:
|
| 102 |
+
img_name = str(uuid.uuid4()) + f"_{face_name}_{i}" + ".jpg"
|
| 103 |
+
img_path = os.path.join(img_dir, img_name)
|
| 104 |
+
if os.path.exists(img_path):
|
| 105 |
+
st.error("Face already added!")
|
| 106 |
+
else:
|
| 107 |
+
pil_image.save(img_path)
|
| 108 |
+
st.success("Face added successfully!")
|
| 109 |
|
| 110 |
else:
|
| 111 |
st.info("Your face is identified successfully!")
|
|
|
|
| 119 |
st.image(pil_image, use_column_width="auto")
|
| 120 |
st.write(face_name)
|
| 121 |
if st.button("Save", key="button"):
|
| 122 |
+
if face_name == "This is a placeholder":
|
| 123 |
+
st.error("Please provide a name for the face!")
|
|
|
|
|
|
|
| 124 |
else:
|
| 125 |
+
img_name = str(uuid.uuid4()) + f"_{face_name}_0" + ".jpg"
|
| 126 |
+
img_path = os.path.join(img_dir, img_name)
|
| 127 |
+
if os.path.exists(img_path):
|
| 128 |
+
st.error("Face already added!")
|
| 129 |
+
else:
|
| 130 |
+
pil_image.save(img_path)
|
| 131 |
+
st.success("Face added successfully!")
|
| 132 |
|
| 133 |
|
| 134 |
+
st.subheader("Let's see your saved faces in your known-face database.")
|
| 135 |
images = os.listdir(img_dir)
|
| 136 |
if len(images) <= 0:
|
| 137 |
+
st.error("No faces have been added yet.")
|
| 138 |
else:
|
| 139 |
cols = st.columns(len(images))
|
| 140 |
+
for i, img in enumerate(images):
|
| 141 |
+
face_name = img.split("_")[1]
|
| 142 |
+
cols[i].image(os.path.join(img_dir, img), use_column_width="auto")
|
| 143 |
+
cols[i].write(face_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
if st.button("Clear All"):
|
| 146 |
for img in images:
|