Spaces:
Runtime error
Runtime error
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.") | |