import streamlit as st import cv2 import face_recognition import numpy as np import pandas as pd from datetime import datetime import os # পেজ সেটআপ st.set_page_config(page_title="গোটাতিকর ক্লাব ডিজিটাল হাজিরা", page_icon="🌙") st.title("🌙 আরবি শিক্ষা কোর্স - ডিজিটাল হাজিরা (Face ID)") # ছবি লোড করার ফাংশন @st.cache_resource def load_data(): path = 'students_images' known_encodings = [] known_names = [] if os.path.exists(path): for file in os.listdir(path): img = face_recognition.load_image_file(f"{path}/{file}") encoding = face_recognition.face_encodings(img) if len(encoding) > 0: known_encodings.append(encoding[0]) known_names.append(os.path.splitext(file)[0].upper()) return known_encodings, known_names encodeListKnown, classNames = load_data() # ক্যামেরা ইনপুট img_file = st.camera_input("হাজিরা দিতে ক্যামেরার দিকে তাকান") if img_file is not None: file_bytes = np.frombuffer(img_file.getvalue(), np.uint8) img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR) img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) faces_loc = face_recognition.face_locations(img_rgb) faces_enc = face_recognition.face_encodings(img_rgb, faces_loc) for enc, loc in zip(faces_enc, faces_loc): matches = face_recognition.compare_faces(encodeListKnown, enc) distance = face_recognition.face_distance(encodeListKnown, enc) match_idx = np.argmin(distance) if matches[match_idx]: name = classNames[match_idx] st.success(f"✅ হাজিরা সফল: {name}") # রিপোর্ট সেভ করা now = datetime.now().strftime('%d-%m-%Y %H:%M:%S') df = pd.DataFrame({'Name': [name], 'Time': [now]}) df.to_csv('attendance.csv', mode='a', index=False, header=not os.path.exists('attendance.csv')) else: st.error("❌ আপনাকে শনাক্ত করা যায়নি!")


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home