simran40 commited on
Commit
cef1078
·
verified ·
1 Parent(s): d9a7132

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +46 -0
  2. requirements.txt +4 -0
  3. slide1.png +0 -0
  4. slide2.png +0 -0
  5. slide3.png +0 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2, os
3
+ import mediapipe as mp
4
+
5
+ mp_hands = mp.solutions.hands
6
+ hands = mp_hands.Hands(max_num_hands=1)
7
+
8
+ # ensure slides folder exists
9
+ if not os.path.exists("slides"):
10
+ os.makedirs("slides")
11
+
12
+ slides = sorted([f"slides/{img}" for img in os.listdir("slides")])
13
+ index = 0
14
+
15
+ def detect(frame):
16
+ global index, slides
17
+ slides = sorted([f"slides/{img}" for img in os.listdir("slides")])
18
+ if not slides:
19
+ import numpy as np
20
+ blank = np.zeros((600,800,3),dtype=np.uint8)
21
+ cv2.putText(blank, "Upload slide images in /slides", (50,300),
22
+ cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
23
+ return blank
24
+
25
+ h,w,c = frame.shape
26
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
27
+ result = hands.process(frame_rgb)
28
+
29
+ if result.multi_hand_landmarks:
30
+ lm = result.multi_hand_landmarks[0]
31
+ x = lm.landmark[mp_hands.HandLandmark.WRIST].x * w
32
+ if x < w*0.3:
33
+ index = max(0, index-1)
34
+ elif x > w*0.7:
35
+ index = min(len(slides)-1, index+1)
36
+
37
+ slide = cv2.imread(slides[index])
38
+ slide = cv2.cvtColor(slide, cv2.COLOR_BGR2RGB)
39
+ return slide
40
+
41
+ demo = gr.Interface(fn=detect,
42
+ inputs=gr.Image(source="webcam", streaming=True),
43
+ outputs="image",
44
+ live=True)
45
+
46
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ opencv-python-headless
3
+ mediapipe
4
+ numpy
slide1.png ADDED
slide2.png ADDED
slide3.png ADDED