simran40 commited on
Commit
2edf5a8
·
verified ·
1 Parent(s): 8ece63a

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +37 -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,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import mediapipe as mp
4
+ import numpy as np
5
+ import os
6
+
7
+ mp_hands = mp.solutions.hands
8
+ hands = mp_hands.Hands(max_num_hands=1)
9
+ slides = sorted([f"slides/{img}" for img in os.listdir("slides")])
10
+ index = 0
11
+
12
+ def detect(frame):
13
+ global index
14
+ h, w, c = frame.shape
15
+ frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
16
+ result = hands.process(frame_rgb)
17
+
18
+ if result.multi_hand_landmarks:
19
+ lm = result.multi_hand_landmarks[0]
20
+ x = lm.landmark[mp_hands.HandLandmark.WRIST].x * w
21
+ if x < w * 0.3:
22
+ index = max(0, index - 1)
23
+ elif x > w * 0.7:
24
+ index = min(len(slides)-1, index + 1)
25
+
26
+ slide = cv2.imread(slides[index])
27
+ slide = cv2.cvtColor(slide, cv2.COLOR_BGR2RGB)
28
+ return slide
29
+
30
+ demo = gr.Interface(
31
+ fn=detect,
32
+ live=True,
33
+ inputs=gr.Image(source="webcam", streaming=True),
34
+ outputs="image"
35
+ )
36
+
37
+ 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