Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,25 +8,35 @@ import csv
|
|
8 |
from datetime import datetime
|
9 |
|
10 |
############################################
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
# import streamlit as st
|
17 |
-
# bytes_data=None
|
18 |
from flask_socketio import SocketIO,emit
|
19 |
import base64
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
24 |
|
25 |
|
|
|
26 |
|
27 |
-
|
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 |
-
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
#
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
#
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
#
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
#
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
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 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
@app.route("/")
|
185 |
-
def home():
|
186 |
-
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
-
if __name__ == "__main__":
|
192 |
-
|
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 |
|