Veerammal commited on
Commit
dc82029
1 Parent(s): 68067e5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ import face_recognition
5
+ from PIL import Image
6
+
7
+ # Simulated database of student details
8
+ students_db = {
9
+ "student1": "Details for Student 1",
10
+ "student2": "Details for Student 2",
11
+ }
12
+
13
+ def load_image(image_file):
14
+ img = Image.open(image_file)
15
+ return np.array(img)
16
+
17
+ def recognize_face(image):
18
+ # Find all face locations and encodings in the image
19
+ face_locations = face_recognition.face_locations(image)
20
+ face_encodings = face_recognition.face_encodings(image, face_locations)
21
+
22
+ recognized_students = []
23
+ for face_encoding in face_encodings:
24
+ # Compare with known faces (placeholder)
25
+ # In a real app, you'd load known face encodings from the database
26
+ # Here, it's just a mock example
27
+ matches = [True] # Replace this with actual matching logic
28
+ if True in matches:
29
+ recognized_students.append("student1") # Replace with actual name
30
+
31
+ return recognized_students
32
+
33
+ st.title("Student Face Recognition")
34
+
35
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])
36
+ if uploaded_file is not None:
37
+ # Load and display the image
38
+ image = load_image(uploaded_file)
39
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
40
+
41
+ # Recognize faces
42
+ recognized_students = recognize_face(image)
43
+
44
+ if recognized_students:
45
+ for student in recognized_students:
46
+ st.write(students_db.get(student, "Student not found"))
47
+ else:
48
+ st.write("No students recognized.")