Pratyush101 commited on
Commit
84c826d
·
verified ·
1 Parent(s): 54cabae

Update app.py

Browse files

correct the errors for virtual keyboard part 3

Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -18,23 +18,12 @@ import time
18
  # logger = logging.getLogger(_name_)
19
 
20
  # Streamlit settings
21
- st.set_page_config(page_title="Virtual Keyboard", layout="wide")
22
  st.title("Interactive Virtual Keyboard")
23
  st.subheader('''Turn on the webcam and use hand gestures to interact with the virtual keyboard.
24
  Use 'a' and 'd' from the keyboard to change the background.''')
25
 
26
 
27
-
28
- # # Logging setup
29
- # logger = logging.getLogger(__name__)
30
-
31
-
32
- # Streamlit settings
33
- st.set_page_config(page_title="Virtual Keyboard", layout="wide")
34
- st.title("Interactive Virtual Keyboard")
35
- st.subheader('''Turn on the webcam and use hand gestures to interact with the virtual keyboard.
36
- Use 'a' and 'd' from the keyboard to change the background.''')
37
-
38
  # Initialize modules
39
  detector = HandDetector(maxHands=1, detectionCon=0.8)
40
  segmentor = SelfiSegmentation()
@@ -45,7 +34,7 @@ keys = [["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
45
  ["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"]]
46
 
47
  class Button:
48
- def _init_(self, pos, text, size=[100, 100]):
49
  self.pos = pos
50
  self.size = size
51
  self.text = text
@@ -75,6 +64,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
75
  global indexImg, output_text
76
 
77
  img = frame.to_ndarray(format="bgr24")
 
78
 
79
  detections = []
80
  if hands:
@@ -87,7 +77,7 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
87
  detections.append(Detection(label=label, score=score, box=box))
88
  result_queue.put(detections)
89
  st.session_state["output_text"] = output_text
90
- return av.VideoFrame.from_ndarray(imgOut, format="bgr24")
91
 
92
  webrtc_streamer(
93
  key="virtual-keyboard",
 
18
  # logger = logging.getLogger(_name_)
19
 
20
  # Streamlit settings
21
+ st.set_page_config(page_title="Virtual Keyboard", page_icon="🏋️")
22
  st.title("Interactive Virtual Keyboard")
23
  st.subheader('''Turn on the webcam and use hand gestures to interact with the virtual keyboard.
24
  Use 'a' and 'd' from the keyboard to change the background.''')
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
27
  # Initialize modules
28
  detector = HandDetector(maxHands=1, detectionCon=0.8)
29
  segmentor = SelfiSegmentation()
 
34
  ["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"]]
35
 
36
  class Button:
37
+ def __init__(self, pos, text, size=[100, 100]):
38
  self.pos = pos
39
  self.size = size
40
  self.text = text
 
64
  global indexImg, output_text
65
 
66
  img = frame.to_ndarray(format="bgr24")
67
+ hands = detector.findHands(img, draw=False)
68
 
69
  detections = []
70
  if hands:
 
77
  detections.append(Detection(label=label, score=score, box=box))
78
  result_queue.put(detections)
79
  st.session_state["output_text"] = output_text
80
+ return av.VideoFrame.from_ndarray(img, format="bgr24")
81
 
82
  webrtc_streamer(
83
  key="virtual-keyboard",