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

face detection model added

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -1,22 +1,28 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
  from PIL import Image
 
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
6
 
7
- st.title("Hot Dog? Or Not?")
 
 
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
 
 
 
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
21
 
 
 
 
22
 
 
 
 
 
 
1
  import streamlit as st
 
2
  from PIL import Image
3
+ import face_recognition
4
 
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)