Spaces:
Build error
Build error
Upload 5 files
Browse files- X.npy +3 -0
- Y.npy +3 -0
- app.py +42 -0
- requirements.txt +0 -0
- run.py +48 -0
X.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:acb7df34faf4afc36da1e0452e949f0b5639cf308692054f6abec2782b7b4448
|
3 |
+
size 47232
|
Y.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ffb3aee1dadae6a8f2c1e812cecd917e099d358fc57914b522fda60872cd67f1
|
3 |
+
size 1232
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, send_file
|
2 |
+
# Import your attendance model and processing functions
|
3 |
+
from run import predict_and_show
|
4 |
+
|
5 |
+
app = Flask("Ogs")
|
6 |
+
|
7 |
+
|
8 |
+
@app.route('/')
|
9 |
+
def index():
|
10 |
+
return render_template('index.html')
|
11 |
+
|
12 |
+
|
13 |
+
@app.route('/upload', methods=['POST'])
|
14 |
+
def upload():
|
15 |
+
if 'file' not in request.files:
|
16 |
+
return "No file part"
|
17 |
+
|
18 |
+
file = request.files['file']
|
19 |
+
|
20 |
+
if file.filename == '':
|
21 |
+
return "No selected file"
|
22 |
+
|
23 |
+
file.save("image.jpeg")
|
24 |
+
# # Access file properties
|
25 |
+
# filename = file.filename
|
26 |
+
# content_type = file.content_type
|
27 |
+
# file_size = len(file.read())
|
28 |
+
|
29 |
+
# # Reset file cursor to the beginning after reading it
|
30 |
+
# file.seek(0)
|
31 |
+
|
32 |
+
# # Read the content of the uploaded image
|
33 |
+
# image_content = file.read()
|
34 |
+
|
35 |
+
# Process the image using your attendance model
|
36 |
+
predict_and_show("image.jpeg")
|
37 |
+
|
38 |
+
return send_file("attendance.csv", as_attachment=True)
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == '__main__':
|
42 |
+
app.run(debug=True)
|
requirements.txt
ADDED
Binary file (904 Bytes). View file
|
|
run.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import face_recognition
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image, ImageDraw
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
|
8 |
+
def predict_and_show(image_path):
|
9 |
+
X = np.load("X.npy")
|
10 |
+
Y = np.load("Y.npy")
|
11 |
+
|
12 |
+
attendance = []
|
13 |
+
image = face_recognition.load_image_file(image_path)
|
14 |
+
face_bounding_boxes = face_recognition.face_locations(image)
|
15 |
+
if len(face_bounding_boxes) == 0:
|
16 |
+
print("No face found in the image")
|
17 |
+
return
|
18 |
+
X_test = face_recognition.face_encodings(image, known_face_locations=face_bounding_boxes)
|
19 |
+
for i in range(len(X_test)):
|
20 |
+
distances = np.linalg.norm(np.array(X) - np.array(X_test[i]), axis=1)
|
21 |
+
min_distance = np.min(distances)
|
22 |
+
if min_distance > 0.55:
|
23 |
+
print("Unknown")
|
24 |
+
else:
|
25 |
+
print(Y[np.argmin(distances)], min_distance)
|
26 |
+
attendance.append(Y[np.argmin(distances)])
|
27 |
+
top, right, bottom, left = face_bounding_boxes[i]
|
28 |
+
face_image = image[top:bottom, left:right]
|
29 |
+
pil_image = Image.fromarray(face_image)
|
30 |
+
draw = ImageDraw.Draw(pil_image)
|
31 |
+
draw.text((0, 0), Y[np.argmin(distances)], (255, 255, 255))
|
32 |
+
#pil_image.show()
|
33 |
+
|
34 |
+
x = pd.DataFrame(attendance, columns=["Name"])
|
35 |
+
x.to_csv("attendance.csv", index=False)
|
36 |
+
return True
|
37 |
+
|
38 |
+
# predict_and_show()
|
39 |
+
|
40 |
+
# #ask for input string from user
|
41 |
+
# print("Enter the name of the image file")
|
42 |
+
# image_path = input()
|
43 |
+
|
44 |
+
# predict_and_show(image_path)
|
45 |
+
# #save the attendance list to a txt file
|
46 |
+
# with open("attendance.txt", "w") as file:
|
47 |
+
# for i in attendance:
|
48 |
+
# file.write(i + "\n")
|