File size: 1,551 Bytes
dc82029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import numpy as np
import face_recognition
from PIL import Image

# Simulated database of student details
students_db = {
    "student1": "Details for Student 1",
    "student2": "Details for Student 2",
}

def load_image(image_file):
    img = Image.open(image_file)
    return np.array(img)

def recognize_face(image):
    # Find all face locations and encodings in the image
    face_locations = face_recognition.face_locations(image)
    face_encodings = face_recognition.face_encodings(image, face_locations)

    recognized_students = []
    for face_encoding in face_encodings:
        # Compare with known faces (placeholder)
        # In a real app, you'd load known face encodings from the database
        # Here, it's just a mock example
        matches = [True]  # Replace this with actual matching logic
        if True in matches:
            recognized_students.append("student1")  # Replace with actual name

    return recognized_students

st.title("Student Face Recognition")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])
if uploaded_file is not None:
    # Load and display the image
    image = load_image(uploaded_file)
    st.image(image, caption='Uploaded Image.', use_column_width=True)
    
    # Recognize faces
    recognized_students = recognize_face(image)
    
    if recognized_students:
        for student in recognized_students:
            st.write(students_db.get(student, "Student not found"))
    else:
        st.write("No students recognized.")