Mehulgarg commited on
Commit
2ab615e
1 Parent(s): 54a6059

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py CHANGED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from keras.models import load_model
2
+ from PIL import Image
3
+ import numpy as np
4
+ import cv2
5
+ import requests
6
+
7
+ import face_recognition
8
+ import os
9
+ from datetime import datetime
10
+
11
+ #the following are to do with this interactive notebook code
12
+ from matplotlib import pyplot as plt # this lets you draw inline pictures in the notebooks
13
+ import pylab # this allows you to control figure size
14
+ pylab.rcParams['figure.figsize'] = (10.0, 8.0) # this controls figure size in the notebook
15
+
16
+ import io
17
+ import streamlit as st
18
+ bytes_data=None
19
+
20
+ Images = []
21
+ classnames = []
22
+ myList = os.listdir()
23
+ #st.write(myList)
24
+ for cls in myList:
25
+ if os.path.splitext(cls)[1] == ".jpg" :
26
+ curImg = cv2.imread(f'{cls}')
27
+ Images.append(curImg)
28
+ classnames.append(os.path.splitext(cls)[0])
29
+ st.write(classnames)
30
+
31
+ def findEncodings(Images):
32
+ encodeList = []
33
+ for img in Images:
34
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
35
+ encode = face_recognition.face_encodings(img)[0]
36
+ encodeList.append(encode)
37
+ return encodeList
38
+
39
+
40
+ encodeListknown = findEncodings(Images)
41
+ st.write('Encoding Complete')
42
+
43
+ img_file_buffer=st.camera_input("Take a picture")
44
+ if img_file_buffer is not None:
45
+
46
+ test_image = Image.open(img_file_buffer)
47
+ st.image(test_image, use_column_width=True)
48
+
49
+ image = np.asarray(test_image)
50
+
51
+ #########################
52
+ imgS = cv2.resize(image,(0,0),None,0.25,0.25)
53
+ imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
54
+ facesCurFrame = face_recognition.face_locations(imgS)
55
+ encodesCurFrame = face_recognition.face_encodings(imgS,facesCurFrame)
56
+
57
+ for encodeFace,faceLoc in zip(encodesCurFrame,facesCurFrame):
58
+ matches = face_recognition.compare_faces(encodeListknown,encodeFace)
59
+ faceDis = face_recognition.face_distance(encodeListknown,encodeFace)
60
+ #print(faceDis)
61
+ matchIndex = np.argmin(faceDis)
62
+
63
+ if matches[matchIndex]:
64
+ name = classnames[matchIndex].upper()
65
+ st.write(name)
66
+ y1, x2, y2, x1 = faceLoc
67
+ y1, x2, y2, x1 = y1*4,x2*4,y2*4,x1*4
68
+ cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
69
+ cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
70
+ cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
71
+
72
+ ##############
73
+ url = "https://rgiattendance.000webhostapp.com"
74
+ url1 = "/update.php"
75
+ data1 = {'name':name }
76
+ response = requests.post(url+url1, data=data1)
77
+
78
+ if response.status_code == 200 :
79
+ st.write(" data updated on : " + url)
80
+ else : st.write("data not updated ")
81
+
82
+ ##############################
83
+ st.image(image)
84
+ if bytes_data is None:
85
+ st.stop()
86
+
87
+