Spaces:
Sleeping
Sleeping
Download app.py from MohanaPriya200/image_processing_app: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/MohanaPriya200/image_processing_app/resolve/main/app.py
- Command line
-
hf download hf://spaces/MohanaPriya200/image_processing_app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MohanaPriya200/image_processing_app/resolve/main/app.py
1.56 kB
| import cv2 | |
| import mediapipe as mp | |
| import numpy as np | |
| import gradio as gr | |
| mp_face_mesh = mp.solutions.face_mesh | |
| face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=1, refine_landmarks=True) | |
| # Eye landmark indices | |
| LEFT_EYE = [33, 133] | |
| RIGHT_EYE = [362, 263] | |
| def calculate_focus_state(left_eye, right_eye): | |
| left_x, _ = left_eye | |
| right_x, _ = right_eye | |
| if 0.3 < left_x < 0.7 and 0.3 < right_x < 0.7: | |
| return "π’ Focused" | |
| elif left_x < 0.2 or right_x > 0.8: | |
| return "π‘ Distracted" | |
| else: | |
| return "π΄ Drowsy" | |
| def detect_productivity(image): | |
| image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
| results = face_mesh.process(image_rgb) | |
| h, w, _ = image.shape | |
| if results.multi_face_landmarks: | |
| for face_landmarks in results.multi_face_landmarks: | |
| landmarks = face_landmarks.landmark | |
| left_eye = (landmarks[LEFT_EYE[0]].x, landmarks[LEFT_EYE[0]].y) | |
| right_eye = (landmarks[RIGHT_EYE[0]].x, landmarks[RIGHT_EYE[0]].y) | |
| state = calculate_focus_state(left_eye, right_eye) | |
| return state | |
| return "Face not detected. Please try again." | |
| # Gradio UI | |
| interface = gr.Interface( | |
| fn=detect_productivity, | |
| inputs=gr.Image(type="numpy", label="Upload a Snapshot"), | |
| outputs=gr.Textbox(label="Productivity Status"), | |
| title="ποΈ VisionPing β Live Productivity Monitor", | |
| description="Take a snapshot. VisionPing will analyze your eye direction and predict your current productivity state." | |
| ) | |
| interface.launch() | |