Vikas01 commited on
Commit
4108613
1 Parent(s): 99bddba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -132
app.py CHANGED
@@ -8,25 +8,35 @@ import csv
8
  from datetime import datetime
9
 
10
  ############################################
11
- # import matplotlib.pyplot as plt
12
- # import pylab # this allows you to control figure size
13
- # pylab.rcParams['figure.figsize'] = (10.0, 8.0) # this controls figure size in the notebook
14
 
15
- # import io
16
- # import streamlit as st
17
- # bytes_data=None
18
  from flask_socketio import SocketIO,emit
19
  import base64
20
- ##################################################3
21
-
22
- # import gradio as gr
 
 
23
 
24
 
25
 
 
26
 
27
- app = Flask(__name__)
28
  app.config['SECRET_KEY'] = 'secret!'
29
  socket = SocketIO(app,async_mode="eventlet")
 
 
 
 
 
 
 
 
 
30
 
31
  def base64_to_image(base64_string):
32
  # Extract the base64 encoded binary data from the input string
@@ -59,136 +69,74 @@ def receive_image(image):
59
  class_name = class_names[index]
60
  confidence_score = prediction[0][index]
61
  emit("result",{"name":str(class_name),"score":str(confidence_score)})
62
- # flag1 = True
63
-
64
- # @app.route('/at')
65
- # def testme():
66
- # global flag1
67
- # # return "i am in testme"
68
- # while flag1 is True:
69
-
70
- # img_file_buffer=st.camera_input("Take a picture")
71
- # if img_file_buffer is not None:
72
- # test_image = Image.open(img_file_buffer)
73
- # st.image(test_image, use_column_width=True)
74
- # if bytes_data is None:
75
- # flag1 = False
76
- # st.stop()
77
-
78
- # def attend():
79
- # # Face recognition variables
80
- # known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
81
- # known_face_encodings = []
82
-
83
- # # Load known face encodings
84
- # sir_image = face_recognition.load_image_file("photos/sir.jpeg")
85
- # sir_encoding = face_recognition.face_encodings(sir_image)[0]
86
-
87
- # vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
88
- # vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
89
-
90
- # lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
91
- # lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
92
-
93
- # jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
94
- # jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
95
-
96
- # maam_image = face_recognition.load_image_file("photos/maam.png")
97
- # maam_encoding = face_recognition.face_encodings(maam_image)[0]
98
-
99
- # known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
100
-
101
- # students = known_faces_names.copy()
102
-
103
- # face_locations = []
104
- # face_encodings = []
105
- # face_names = []
106
-
107
- # now = datetime.now()
108
- # current_date = now.strftime("%Y-%m-%d")
109
- # csv_file = open(f"{current_date}.csv", "a+", newline="")
110
 
111
- # csv_writer = csv.writer(csv_file)
112
-
113
- # # Function to run face recognition
114
- # def run_face_recognition():
115
- # video_capture = cv2.VideoCapture(0)
116
- # s = True
117
-
118
- # existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
119
-
120
-
121
- # while s:
122
- # _, frame = video_capture.read()
123
- # small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
124
- # rgb_small_frame = small_frame[:, :, ::-1]
125
-
126
- # face_locations = face_recognition.face_locations(rgb_small_frame)
127
- # face_encodings = face_recognition.face_encodings(small_frame, face_locations)
128
- # face_names = []
129
-
130
- # for face_encoding in face_encodings:
131
- # matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
132
- # name = ""
133
- # face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
134
- # best_match_index = np.argmin(face_distance)
135
- # if matches[best_match_index]:
136
- # name = known_faces_names[best_match_index]
137
-
138
- # face_names.append(name)
139
-
140
-
141
- # for name in face_names:
142
- # if name in known_faces_names and name in students and name not in existing_names:
143
- # students.remove(name)
144
- # print(students)
145
- # print(f"Attendance recorded for {name}")
146
- # current_time = now.strftime("%H-%M-%S")
147
- # csv_writer.writerow([name, current_time, "Present"])
148
- # existing_names.add(name) # Add the name to the set of existing names
149
-
150
- # s = False # Set s to False to exit the loop after recording attendance
151
- # break # Break the loop once attendance has been recorded for a name
152
-
153
- # cv2.imshow("Attendance System", frame)
154
- # if cv2.waitKey(1) & 0xFF == ord('q'):
155
- # break
156
-
157
- # video_capture.release()
158
- # cv2.destroyAllWindows()
159
- # csv_file.close()
160
-
161
- # # Call the function to run face recognition
162
- # run_face_recognition()
163
-
164
- # return redirect(url_for('show_table'))
165
 
166
 
 
 
 
 
167
 
168
  ###########################################################################
169
- @app.route('/table')
170
- def show_table():
171
- # Get the current date
172
- current_date = datetime.now().strftime("%Y-%m-%d")
173
- # Read the CSV file to get attendance data
174
- attendance=[]
175
- try:
176
- with open(f"{current_date}.csv", newline="") as csv_file:
177
- csv_reader = csv.reader(csv_file)
178
- attendance = list(csv_reader)
179
- except FileNotFoundError:
180
- pass
181
- # Render the table.html template and pass the attendance data
182
- return render_template('attendance.html', attendance=attendance)
183
-
184
- @app.route("/")
185
- def home():
186
- return render_template('index.html')
187
 
188
 
189
 
190
 
191
- if __name__ == "__main__":
192
- socket.run(app,host="0.0.0.0", port=7860)
193
 
194
 
 
8
  from datetime import datetime
9
 
10
  ############################################
11
+ from flask import Flask,render_template
12
+ import face_recognition
13
+ import sqlite3
14
 
15
+ #################
 
 
16
  from flask_socketio import SocketIO,emit
17
  import base64
18
+ import numpy as np
19
+ import cv2
20
+ import numpy as np
21
+ from keras.models import load_model
22
+ ##################
23
 
24
 
25
 
26
+ app = Flask (__name__ )
27
 
28
+ #################
29
  app.config['SECRET_KEY'] = 'secret!'
30
  socket = SocketIO(app,async_mode="eventlet")
31
+ #######################
32
+
33
+
34
+ ######################
35
+
36
+ # load model and labels
37
+ np.set_printoptions(suppress=True)
38
+ model = load_model(r"keras_model.h5", compile=False)
39
+ class_names = open(r"labels.txt", "r").readlines()
40
 
41
  def base64_to_image(base64_string):
42
  # Extract the base64 encoded binary data from the input string
 
69
  class_name = class_names[index]
70
  confidence_score = prediction[0][index]
71
  emit("result",{"name":str(class_name),"score":str(confidence_score)})
72
+ #######################
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ @app.route ("/")
75
+ def home():
76
+ return render_template("index.html")
77
+
78
+ @app.route ("/storedata" , methods =[ 'GET' ] )
79
+ def storedata():
80
+ # uname =request.form.get("uname")
81
+ # matching =request.form.get("matching")
82
+ # rtime =request.form.get("rtime")
83
+ name =request.args.get("class_name")
84
+ score =request.args.get("confidence_score")
85
+ # rtime =request.args.get("rtime")
86
+
87
+ con = sqlite3.connect("facedb") # connect database
88
+ con.row_factory = sqlite3.Row # create object of Row
89
+ cur = con.cursor() # create cursor object, which will hold records
90
+ # being fetched from database.
91
+ cur.execute( "insert into userdata (username , matching , recordingtime) values ('%s',%s,'%s')"%(uname,matching,rtime))
92
+ #cur.execute("select * from students where email=='%s' and pswd=='%s'"%(useremail,userpswd))
93
+ con.commit()
94
+ con.close()
95
+
96
+ return redirect(url_for( 'datafetch'))
97
+
98
+ @app.route ("/data" )
99
+ def datafetch():
100
+ # connect to Sqlite database and fetch data
101
+ con = sqlite3.connect("facedb") # connect sms database
102
+ con.row_factory = sqlite3.Row # create object of Row
103
+ cur = con.cursor() # create cursor object, which will hold records
104
+ # being fetched from database.
105
+ cur.execute( "select id, username, matching, recordingtime from userdata order by id desc limit 10") # execute a SQL query to get the data
106
+ rows = cur.fetchall() # all the data pulled from database is stored in rows object
107
+ con.close ()
108
+ return render_template ('data.html', data = rows)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
 
111
+
112
+
113
+ if __name__ == '__main__':
114
+ socket.run(app,host="0.0.0.0", port=7860)
115
 
116
  ###########################################################################
117
+ # @app.route('/table')
118
+ # def show_table():
119
+ # # Get the current date
120
+ # current_date = datetime.now().strftime("%Y-%m-%d")
121
+ # # Read the CSV file to get attendance data
122
+ # attendance=[]
123
+ # try:
124
+ # with open(f"{current_date}.csv", newline="") as csv_file:
125
+ # csv_reader = csv.reader(csv_file)
126
+ # attendance = list(csv_reader)
127
+ # except FileNotFoundError:
128
+ # pass
129
+ # # Render the table.html template and pass the attendance data
130
+ # return render_template('attendance.html', attendance=attendance)
131
+
132
+ # @app.route("/")
133
+ # def home():
134
+ # return render_template('index.html')
135
 
136
 
137
 
138
 
139
+ # if __name__ == "__main__":
140
+ # socket.run(app,host="0.0.0.0", port=7860)
141
 
142