smart-study 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ """Smart Study webcam monitor."""
2
+
3
+ from .study import study
4
+
5
+ __all__ = ["study"]
Binary file
Binary file
Binary file
Binary file
smart_study/study.py ADDED
@@ -0,0 +1,99 @@
1
+ """Run the webcam-based Smart Study distraction monitor."""
2
+
3
+ from importlib.resources import files
4
+
5
+
6
+ def study(camera_index: int = 0) -> None:
7
+ """Start monitoring with the selected camera; press Q in the window to stop."""
8
+ import cv2
9
+ import cvzone
10
+ import pygame
11
+ from cvzone.FaceMeshModule import FaceMeshDetector
12
+ from ultralytics import YOLO
13
+
14
+ assets = files("smart_study").joinpath("assets")
15
+ # importlib.resources paths are ordinary filesystem paths for a normal wheel install.
16
+ pygame.mixer.init()
17
+ alarm_sleep = pygame.mixer.Sound(str(assets.joinpath("alarm.mp3")))
18
+ alarm_facehide = pygame.mixer.Sound(str(assets.joinpath("faudio.mp3")))
19
+ alarm_phone = pygame.mixer.Sound(str(assets.joinpath("paudio.mp3")))
20
+ cap = cv2.VideoCapture(camera_index)
21
+ face_detector = FaceMeshDetector(maxFaces=1)
22
+ model_path = assets.joinpath("yolov8n.pt")
23
+ with model_path.open("rb") as model_file:
24
+ model_header = model_file.read(128)
25
+ if model_header.startswith(b"version https://git-lfs.github.com/spec/v1"):
26
+ raise RuntimeError("YOLO weights are a Git LFS pointer. Download the actual yolov8n.pt weights before installing the package.")
27
+ phone_detector = YOLO(str(model_path))
28
+ class_names = phone_detector.names
29
+
30
+ left_eye_top, left_eye_bottom = 159, 145
31
+ face_left, face_right = 130, 243
32
+ closed_frames = covered_frames = 0
33
+ current_playing = None
34
+ try:
35
+ while True:
36
+ success, img = cap.read()
37
+ if not success:
38
+ break
39
+
40
+ is_audio_busy = pygame.mixer.get_busy()
41
+ if not is_audio_busy:
42
+ current_playing = None
43
+
44
+ img, faces = face_detector.findFaceMesh(img, draw=False)
45
+ is_sleepy = is_face_covered = False
46
+ if faces:
47
+ covered_frames = 0
48
+ face = faces[0]
49
+ eye_dist, _ = face_detector.findDistance(face[left_eye_top], face[left_eye_bottom])
50
+ face_dist, _ = face_detector.findDistance(face[face_left], face[face_right])
51
+ ratio = (eye_dist / face_dist) * 100
52
+ closed_frames = closed_frames + 1 if ratio < 11.0 else 0
53
+ is_sleepy = closed_frames >= 15
54
+ cvzone.putTextRect(img, f"Eye Ratio: {int(ratio)}", (30, 40), scale=1, thickness=1)
55
+ else:
56
+ closed_frames = 0
57
+ covered_frames += 1
58
+ is_face_covered = covered_frames >= 20
59
+
60
+ phone_detected = False
61
+ for result in phone_detector.predict(img, stream=True, verbose=False):
62
+ for box in result.boxes:
63
+ cls_id, conf = int(box.cls[0]), float(box.conf[0])
64
+ if class_names[cls_id] == "cell phone" and conf > 0.5:
65
+ phone_detected = True
66
+ x1, y1, x2, y2 = map(int, box.xyxy[0])
67
+ cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 2)
68
+ cvzone.putTextRect(img, f"Phone detected! {int(conf * 100)}%", (x1, max(y1 - 10, 30)), scale=1, thickness=1, colorR=(255, 0, 255))
69
+
70
+ if is_face_covered:
71
+ message, color, alarm, state = "DONT COVER YOUR FACE!", (0, 0, 255), alarm_facehide, "facehide"
72
+ elif is_sleepy:
73
+ message, color, alarm, state = "WAKE UP & STUDY!", (0, 0, 255), alarm_sleep, "sleep"
74
+ elif phone_detected:
75
+ message, color, alarm, state = "PUT THE PHONE AWAY!", (0, 165, 255), alarm_phone, "phone"
76
+ else:
77
+ message = None
78
+
79
+ if message:
80
+ cvzone.putTextRect(img, message, (50, 100), scale=2, thickness=3, colorR=color)
81
+ if not is_audio_busy:
82
+ alarm.play(0)
83
+ current_playing = state
84
+ elif is_audio_busy:
85
+ previous = {
86
+ "facehide": ("DONT COVER YOUR FACE!", (0, 0, 255)),
87
+ "sleep": ("WAKE UP & STUDY!", (0, 0, 255)),
88
+ "phone": ("PUT THE PHONE AWAY!", (0, 165, 255)),
89
+ }.get(current_playing)
90
+ if previous:
91
+ cvzone.putTextRect(img, previous[0], (50, 100), scale=2, thickness=3, colorR=previous[1])
92
+
93
+ cv2.imshow("Smart Study Monitor", img)
94
+ if cv2.waitKey(1) & 0xFF == ord("q"):
95
+ break
96
+ finally:
97
+ cap.release()
98
+ cv2.destroyAllWindows()
99
+ pygame.mixer.quit()
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: smart-study
3
+ Version: 0.1.0
4
+ Summary: Webcam-based study distraction monitor
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: Programming Language :: Python :: 3.11
7
+ Classifier: Operating System :: Microsoft :: Windows
8
+ Classifier: Topic :: Education
9
+ Requires-Python: <3.13,>=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: opencv-python>=4.8
12
+ Requires-Dist: cvzone>=1.6
13
+ Requires-Dist: ultralytics>=8.0
14
+ Requires-Dist: pygame>=2.5
15
+ Requires-Dist: mediapipe>=0.10
16
+
17
+ # smart-study
18
+
19
+ Webcam-based study distraction monitor. It watches for prolonged eye closure, a missing/covered face, and cell phones, then displays a warning and plays an alert.
20
+
21
+ ## Install
22
+
23
+ Python 3.11 is recommended on Windows. The computer needs a webcam and audio output.
24
+
25
+ ```bash
26
+ python -m pip install smart-study
27
+ ```
28
+
29
+ ## Use as a Python module
30
+
31
+ ```python
32
+ from smart_study import study
33
+
34
+ study() # Uses camera 0; press Q in the video window to stop.
35
+ ```
36
+
37
+ Choose another camera by passing its index:
38
+
39
+ ```python
40
+ study(camera_index=1)
41
+ ```
42
+
43
+ Importing `smart_study` does not start the webcam. The monitor starts only when `study()` is called.
44
+
45
+ ## Run from a source checkout
46
+
47
+ ```bash
48
+ python -m pip install -e .
49
+ python app.py
50
+ ```
51
+
52
+ The distribution includes the YOLO model and alert audio assets. Installation is relatively large because the computer-vision dependencies include PyTorch through Ultralytics. Python versions below 3.13 are currently declared because MediaPipe and the selected dependency set may not be available together on newer Python versions.
53
+
54
+ ## Build and upload to PyPI
55
+
56
+ Update the version in `pyproject.toml` for each release, then:
57
+
58
+ ```bash
59
+ python -m pip install --upgrade build twine
60
+ python -m build
61
+ python -m twine check dist/*
62
+ python -m twine upload dist/*
63
+ ```
64
+
65
+ PyPI distribution name: `smart-study`
66
+ Python import name: `smart_study`
@@ -0,0 +1,10 @@
1
+ smart_study/__init__.py,sha256=16lCxFNgK6-YlcxYmc4wP4Otz7f-fNU89gpb_qxJ33U,81
2
+ smart_study/study.py,sha256=qH8x04jArqQx7hhuN5IdqAMEt1hyywoWCA-5PTP4wog,4501
3
+ smart_study/assets/alarm.mp3,sha256=9I8BZqARLbynCoM-1JGkCciBXywk4tvhEfFTUrXERco,189311
4
+ smart_study/assets/faudio.mp3,sha256=GLF_WzNfjzhssORQEMfr3VIfpuPxPZNiAWbF3wPQuGQ,74448
5
+ smart_study/assets/paudio.mp3,sha256=F3rF23noeZ9Xd9LRxPJ4BbUgEyjr1xYahdiGiG28qIo,331216
6
+ smart_study/assets/yolov8n.pt,sha256=9Zs9gz4v8y4ZS1u44I0hHcfFvfFEuQ0shBLEfM_IOzY,6549796
7
+ smart_study-0.1.0.dist-info/METADATA,sha256=hw4IMvmePiolHkqLtdfVhQTOg_zAO17IfQaqdwcRv4w,1934
8
+ smart_study-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
9
+ smart_study-0.1.0.dist-info/top_level.txt,sha256=0C4kl_9rLrEsUhD9XOmQD7mOBtB_ZQqJsQxOcrx_J-E,12
10
+ smart_study-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ smart_study