Spaces:
Runtime error
Runtime error
| from flask import * | |
| from PIL import Image | |
| import face_recognition | |
| import cv2 | |
| import numpy as np | |
| import csv | |
| from datetime import datetime | |
| 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 streamlit as st | |
| 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"}) | |
| ######################################################## | |
| 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) | |
| def run_face_recognition(): | |
| bytes_data=None | |
| img_file_buffer=st.camera_input("Take a picture") | |
| if img_file_buffer is not None: | |
| st.write("data ") | |
| test_image=Image.open(img_file_buffer) | |
| st.image(test_image) | |
| if bytes_data is None: | |
| st.write("nothing") | |
| st.stop() | |
| # Call the function to run face recognition | |
| run_face_recognition() | |
| return redirect(url_for('show_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) | |
| def home(): | |
| return render_template('index.html') | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) | |