Face_Detection / interview_demo.py
roseyshi's picture
Upload 16 files
6f2dcbc verified
Raw
History Blame Contribute Delete
3.17 kB
# interview_demo.py - Streamlit app for interviews
import streamlit as st
import cv2
import tempfile
import numpy as np
from PIL import Image
def interview_demo_app():
st.set_page_config(page_title="Live Demo", layout="wide")
st.title("🎯 Live Demo - AI Attendance System")
st.info("""
**How to demonstrate:**
1. Click 'Start Camera' below
2. Show your face to the camera
3. See real-time detection and recognition
4. Watch attendance log update automatically
""")
# Sidebar with status
with st.sidebar:
st.header("πŸ”΄ System Status")
st.success("βœ… Camera Ready")
st.success("βœ… Model Loaded")
st.success("βœ… Database Connected")
st.header("πŸ“Š Session Stats")
if 'detections' not in st.session_state:
st.session_state.detections = []
st.metric("Faces Detected", len(st.session_state.detections))
# Camera feed
col1, col2 = st.columns([2, 1])
with col1:
st.subheader("πŸ“Ή Live Feed")
camera_placeholder = st.empty()
# Start camera button
if st.button("πŸš€ Start Camera", use_container_width=True):
cap = cv2.VideoCapture(0)
if not cap.isOpened():
st.error("⚠️ Could not access camera")
else:
# Process frames
frame_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
# Your detection code here
# For demo, just show frame with overlay
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = cv2.putText(frame, "🟒 Live Demo", (10, 30),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
camera_placeholder.image(frame, use_container_width=True)
# Simulate detections
if frame_count % 30 == 0:
st.session_state.detections.append({
'time': datetime.now(),
'name': 'Demo User'
})
frame_count += 1
with col2:
st.subheader("πŸ“‹ Live Attendance")
attendance_table = st.empty()
# Show attendance log
if st.session_state.detections:
df = pd.DataFrame(st.session_state.detections)
attendance_table.dataframe(df.tail(10))
else:
st.info("Waiting for detections...")
# Demo controls
col3, col4 = st.columns(2)
with col3:
if st.button("🧹 Clear Log", use_container_width=True):
st.session_state.detections = []
st.rerun()
with col4:
if st.button("πŸ“₯ Export Demo Data", use_container_width=True):
# Export functionality
st.success("βœ… Demo data exported!")
if __name__ == "__main__":
interview_demo_app()