File size: 3,486 Bytes
7199111
 
8ecf185
7199111
 
 
 
 
8ecf185
1419912
65daba4
 
 
8ecf185
7199111
68a7922
8ecf185
 
 
 
 
 
 
7199111
8ecf185
 
7199111
 
 
 
3657998
 
8ecf185
 
 
 
 
 
 
 
 
 
7199111
ca8c9ca
7199111
 
 
 
3657998
7199111
 
 
3657998
7199111
 
3657998
7199111
 
3657998
7199111
 
17aa4ec
7199111
 
bbcce29
7199111
bbcce29
7199111
8510d34
7199111
 
 
bbcce29
7199111
 
 
9eb9696
7199111
cad92ea
ca8c9ca
cf6ad1c
0222d28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf6ad1c
 
0222d28
98b16e3
0304d96
 
 
7199111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbcce29
7199111
 
 
8ecf185
9d9428d
bbcce29
 
7199111
 
9eb9696
bbcce29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from flask import *
from PIL import Image

import face_recognition
import cv2
import numpy as np
import csv
from datetime import datetime

import matplotlib.pyplot as plt
# from matplotlib import pyplot as plt # this lets you draw inline pictures in the notebooks
# import pylab # this allows you to control figure size 
# pylab.rcParams['figure.figsize'] = (10.0, 8.0) # this controls figure size in the notebook

import io
import gradio as gr







app = Flask(__name__)


# @app.route("/")
# def index():
#     #return 'hello'
#     return render_template("index.html")


####################################################
# app = Flask(__name__)

# app.config['SECRET_KEY'] = 'secret!'
# socket = SocketIO(app,async_mode="eventlet")

# @socket.on("connect")
# def test_connect():
#     print("Connected")
#     emit("my response", {"data": "Connected"})
########################################################    
@app.route('/att')
def attend():
    # Face recognition variables
    known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
    known_face_encodings = []

    # Load known face encodings
    sir_image = face_recognition.load_image_file("photos/sir.jpeg")
    sir_encoding = face_recognition.face_encodings(sir_image)[0]

    vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
    vikas_encoding = face_recognition.face_encodings(vikas_image)[0]

    lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
    lalit_encoding = face_recognition.face_encodings(lalit_image)[0]

    jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
    jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]

    maam_image = face_recognition.load_image_file("photos/maam.png")
    maam_encoding = face_recognition.face_encodings(maam_image)[0]

    known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]

    students = known_faces_names.copy()

    face_locations = []
    face_encodings = []
    face_names = []

    now = datetime.now()
    current_date = now.strftime("%Y-%m-%d")
    csv_file = open(f"{current_date}.csv", "a+", newline="")
    
    csv_writer = csv.writer(csv_file)

@app.route('/at')   
def webcam():
    # Open the webcam
    cap = cv2.VideoCapture(0)
    
    while True:
        # Read frames from the webcam
        ret, frame = cap.read()
        
        # Display the frames in a window
        cv2.imshow("Webcam", frame)
        
        # Break the loop when 'q' is pressed
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    # Release the webcam and close the window
    cap.release()
    cv2.destroyAllWindows()

iface = gr.Interface(fn=webcam, inputs=None, outputs=None, title="Webcam")
iface.launch(share=True)




   

@app.route('/table')
def show_table():
    # Get the current date
    current_date = datetime.now().strftime("%Y-%m-%d")
    # Read the CSV file to get attendance data
    attendance=[]
    try:
        with open(f"{current_date}.csv", newline="") as csv_file:
            csv_reader = csv.reader(csv_file)
            attendance = list(csv_reader)
    except FileNotFoundError:
        pass
    # Render the table.html template and pass the attendance data
    return render_template('attendance.html', attendance=attendance)

@app.route("/")
def home():
    return render_template('index.html')

   


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)