Kdorlette commited on
Commit
de89825
·
1 Parent(s): 938dd1c

fixed input image bug

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -5,24 +5,28 @@ import face_recognition
5
  st.title("Face Detection")
6
 
7
  # Load the jpg file into a numpy array
8
- file_name = st.file_uploader("Upload a candidate image")
9
- image = face_recognition.load_image_file(file_name)
 
 
10
 
11
- # Find all the faces in the image using the default HOG-based model.
12
- # This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
13
- # See also: find_faces_in_picture_cnn.py
14
- face_locations = face_recognition.face_locations(image)
15
 
16
- st.write("I found {} face(s) in this photograph.".format(len(face_locations)))
17
 
18
- for face_location in face_locations:
19
 
 
 
 
20
 
21
- # Print the location of each face in this image
22
- top, right, bottom, left = face_location
23
- st.write("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
 
24
 
25
- # You can access the actual face itself like this:
26
- face_image = image[top:bottom, left:right]
27
- pil_image = Image.fromarray(face_image)
28
- st.write(pil_image)
 
5
  st.title("Face Detection")
6
 
7
  # Load the jpg file into a numpy array
8
+ input_image = st.file_uploader("Upload a candidate image",type=['jpg','png','jpeg'],accept_multiple_files=False)
9
+ if input_image is not None:
10
+ image = face_recognition.load_image_file(input_image)
11
+ st.image(image)
12
 
13
+ # Find all the faces in the image using the default HOG-based model.
14
+ # This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
15
+ # See also: find_faces_in_picture_cnn.py
16
+ face_locations = face_recognition.face_locations(image)
17
 
18
+ st.write("I found {} face(s) in this photograph.".format(len(face_locations)))
19
 
20
+ for face_location in face_locations:
21
 
22
+ # Print the location of each face in this image
23
+ top, right, bottom, left = face_location
24
+ st.write("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
25
 
26
+ # You can access the actual face itself like this:
27
+ face_image = image[top:bottom, left:right]
28
+ pil_image = Image.fromarray(face_image)
29
+ st.image(pil_image)
30
 
31
+ else:
32
+ st.write("Please upload an image to proceed.")