Spaces:
Runtime error
Runtime error
Shafeek Saleem
commited on
Commit
·
eb30d87
1
Parent(s):
c372b9c
bug fixed images - path
Browse files
pages/2_Face Detection and Creating Database.py
CHANGED
@@ -58,6 +58,8 @@ def step2_page():
|
|
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 |
|
63 |
if input_type == "Camera":
|
@@ -95,11 +97,15 @@ def step2_page():
|
|
95 |
col.image(pil_image, use_column_width=True)
|
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 =
|
103 |
img_path = os.path.join(img_dir, img_name)
|
104 |
if os.path.exists(img_path):
|
105 |
st.error("Face already added!")
|
@@ -117,12 +123,14 @@ def step2_page():
|
|
117 |
face_image = image[top:bottom, left:right]
|
118 |
pil_image = Image.fromarray(face_image)
|
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 =
|
126 |
img_path = os.path.join(img_dir, img_name)
|
127 |
if os.path.exists(img_path):
|
128 |
st.error("Face already added!")
|
@@ -138,9 +146,9 @@ def step2_page():
|
|
138 |
else:
|
139 |
cols = st.columns(len(images))
|
140 |
for i, img in enumerate(images):
|
141 |
-
face_name = img.split("_")[
|
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:
|
|
|
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 |
+
ID = st.text_input('Image ID',
|
62 |
+
"This is a placeholder", key="int")
|
63 |
input_type = st.radio("Select the Input Type", ["Image", "Camera"])
|
64 |
|
65 |
if input_type == "Camera":
|
|
|
97 |
col.image(pil_image, use_column_width=True)
|
98 |
face_name = st.text_input('Who is this?',
|
99 |
"This is a placeholder", key="text_" + str(i))
|
100 |
+
ID = st.text_input('Image ID',
|
101 |
+
"This is a placeholder", key="int_" + str(i))
|
102 |
if st.button("Save", key="button_" + str(i)):
|
103 |
if face_name == "This is a placeholder":
|
104 |
st.error("Please provide a name for the face!")
|
105 |
+
elif ID == "This is a placeholder":
|
106 |
+
st.error("Please provide an ID!")
|
107 |
else:
|
108 |
+
img_name = f"{face_name}_{ID}" + ".jpg"
|
109 |
img_path = os.path.join(img_dir, img_name)
|
110 |
if os.path.exists(img_path):
|
111 |
st.error("Face already added!")
|
|
|
123 |
face_image = image[top:bottom, left:right]
|
124 |
pil_image = Image.fromarray(face_image)
|
125 |
st.image(pil_image, use_column_width="auto")
|
126 |
+
st.write(f"Name: {face_name}")
|
127 |
if st.button("Save", key="button"):
|
128 |
if face_name == "This is a placeholder":
|
129 |
st.error("Please provide a name for the face!")
|
130 |
+
elif ID == "This is a placeholder":
|
131 |
+
st.error("Please provide an ID!")
|
132 |
else:
|
133 |
+
img_name = f"{face_name}_{ID}" + ".jpg"
|
134 |
img_path = os.path.join(img_dir, img_name)
|
135 |
if os.path.exists(img_path):
|
136 |
st.error("Face already added!")
|
|
|
146 |
else:
|
147 |
cols = st.columns(len(images))
|
148 |
for i, img in enumerate(images):
|
149 |
+
face_name = img.split("_")[0]
|
150 |
cols[i].image(os.path.join(img_dir, img), use_column_width="auto")
|
151 |
+
cols[i].write(f"Name: {face_name}")
|
152 |
|
153 |
if st.button("Clear All"):
|
154 |
for img in images:
|
pages/3_Face Encodings.py
CHANGED
@@ -52,7 +52,7 @@ def step3_page():
|
|
52 |
st.subheader("Let's see your saved faces in your known-face database.")
|
53 |
cols = st.columns(len(images))
|
54 |
for i, img in enumerate(images):
|
55 |
-
face_name = img.split("_")[
|
56 |
cols[i].image(os.path.join(img_dir, img), use_column_width=True)
|
57 |
cols[i].write(face_name)
|
58 |
st.subheader("Lets create face encodings for the known-faces.")
|
@@ -64,7 +64,7 @@ def step3_page():
|
|
64 |
face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
|
65 |
my_face_encoding = face_recognition.face_encodings(face_image)
|
66 |
my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
|
67 |
-
np.save(os.path.join(face_encodings_dir, img.split("_")[
|
68 |
# face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
|
69 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
70 |
st.success("Face encoding completed successfully!")
|
|
|
52 |
st.subheader("Let's see your saved faces in your known-face database.")
|
53 |
cols = st.columns(len(images))
|
54 |
for i, img in enumerate(images):
|
55 |
+
face_name = img.split("_")[0]
|
56 |
cols[i].image(os.path.join(img_dir, img), use_column_width=True)
|
57 |
cols[i].write(face_name)
|
58 |
st.subheader("Lets create face encodings for the known-faces.")
|
|
|
64 |
face_image = face_recognition.load_image_file(os.path.join(img_dir, img))
|
65 |
my_face_encoding = face_recognition.face_encodings(face_image)
|
66 |
my_bar.progress(int((i + 1) / len(images) * 100), text="Generating face encodings...")
|
67 |
+
np.save(os.path.join(face_encodings_dir, img.split("_")[0]+".npy"), my_face_encoding)
|
68 |
# face_encodings_dict[img.split("_")[1]] = my_face_encoding.tolist()
|
69 |
my_bar.progress(100, text="Successfully encoded all the known faces!")
|
70 |
st.success("Face encoding completed successfully!")
|