Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -77,7 +77,7 @@ def get_face(img):
|
|
77 |
return img[y1:y2, x1:x2]
|
78 |
return None
|
79 |
|
80 |
-
def verify(image, model, person, validation_image=None):
|
81 |
|
82 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_image:
|
83 |
temp_image.write(image.read())
|
@@ -118,7 +118,7 @@ def verify(image, model, person, validation_image=None):
|
|
118 |
with torch.no_grad():
|
119 |
output = siamese(face, validation_face)
|
120 |
probability = output.item()
|
121 |
-
pred = 1.0 if probability >
|
122 |
|
123 |
if pred == 1:
|
124 |
st.write("Match")
|
@@ -150,16 +150,22 @@ def verify(image, model, person, validation_image=None):
|
|
150 |
|
151 |
def main():
|
152 |
st.title("Face Verification")
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
model = st.selectbox("Select Model", ["Siamese", "HOG-SVM"])
|
155 |
-
person = st.selectbox("Select Person",
|
156 |
if model == "Siamese":
|
157 |
uploaded_image = st.file_uploader("Upload Validation Image (Siamese)", type=["jpg", "png"])
|
158 |
enable = st.checkbox("Enable camera")
|
159 |
captured_image = st.camera_input("Take a picture", disabled=not enable)
|
160 |
|
161 |
if captured_image and model == "Siamese":
|
162 |
-
verify(captured_image, model, person, uploaded_image)
|
163 |
elif captured_image and model == "HOG-SVM":
|
164 |
verify(captured_image, model, person)
|
165 |
|
|
|
77 |
return img[y1:y2, x1:x2]
|
78 |
return None
|
79 |
|
80 |
+
def verify(image, model, person, validation_image=None, threshold=None):
|
81 |
|
82 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_image:
|
83 |
temp_image.write(image.read())
|
|
|
118 |
with torch.no_grad():
|
119 |
output = siamese(face, validation_face)
|
120 |
probability = output.item()
|
121 |
+
pred = 1.0 if probability > threshold else 0.0
|
122 |
|
123 |
if pred == 1:
|
124 |
st.write("Match")
|
|
|
150 |
|
151 |
def main():
|
152 |
st.title("Face Verification")
|
153 |
+
|
154 |
+
person_dict = {
|
155 |
+
"Theo": 0.542,
|
156 |
+
"Deverel": 0.5,
|
157 |
+
"Justin": 0.5
|
158 |
+
}
|
159 |
|
160 |
model = st.selectbox("Select Model", ["Siamese", "HOG-SVM"])
|
161 |
+
person = st.selectbox("Select Person", person_dict.keys())
|
162 |
if model == "Siamese":
|
163 |
uploaded_image = st.file_uploader("Upload Validation Image (Siamese)", type=["jpg", "png"])
|
164 |
enable = st.checkbox("Enable camera")
|
165 |
captured_image = st.camera_input("Take a picture", disabled=not enable)
|
166 |
|
167 |
if captured_image and model == "Siamese":
|
168 |
+
verify(captured_image, model, person, uploaded_image, person_dict.get(person))
|
169 |
elif captured_image and model == "HOG-SVM":
|
170 |
verify(captured_image, model, person)
|
171 |
|