Pratyush101 commited on
Commit
6a24bdf
·
verified ·
1 Parent(s): a078ac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -115,18 +115,19 @@ def video_frame_callback(frame: av.VideoFrame) -> av.VideoFrame:
115
  cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
116
  cv2.putText(img, button.text, (x + int(0.2 * bw), y + int(0.7 * bh)), cv2.FONT_HERSHEY_PLAIN, font_scale, (255, 255, 255), font_thickness)
117
 
118
- if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
119
- if time.time() - prev_key_time[0] > 2:
120
- prev_key_time[0] = time.time()
121
- if button.text != 'BS' and button.text != 'SPACE':
122
- output_text += button.text
123
- elif button.text == 'BS':
124
- output_text = output_text[:-1]
125
- else:
126
- output_text += ' '
 
 
127
 
128
  result_queue.put(detections)
129
- st.session_state["output_text"] = output_text
130
 
131
  return av.VideoFrame.from_ndarray(img, format="bgr24")
132
 
 
115
  cv2.rectangle(img, (x, y), (x + bw, y + bh), (0, 255, 160), -1)
116
  cv2.putText(img, button.text, (x + int(0.2 * bw), y + int(0.7 * bh)), cv2.FONT_HERSHEY_PLAIN, font_scale, (255, 255, 255), font_thickness)
117
 
118
+ # Handle button press
119
+ if (distance / np.sqrt(bbox[2] ** 2 + bbox[3] ** 2)) * 100 < click_threshold:
120
+ if time.time() - prev_key_time[0] > 2:
121
+ prev_key_time[0] = time.time()
122
+ if button.text != 'BS' and button.text != 'SPACE':
123
+ st.session_state["output_text"] += button.text # Append key to output text
124
+ cv2.rectangle(img, (0, 0), (10, 10), (0, 0, 0), -1) #it is a testing box
125
+ elif button.text == 'BS':
126
+ st.session_state["output_text"] = st.session_state["output_text"][:-1] # Remove last character
127
+ else:
128
+ st.session_state["output_text"] += ' ' # Add space
129
 
130
  result_queue.put(detections)
 
131
 
132
  return av.VideoFrame.from_ndarray(img, format="bgr24")
133