Pratyush101's picture
Update app.py
94546d9 verified
raw
history blame
1.29 kB
import logging
import cv2
import numpy as np
import streamlit as st
from streamlit_webrtc import WebRtcMode, webrtc_streamer
from cvzone.HandTrackingModule import HandDetector
from sample_utils.turn import get_ice_servers
logger = logging.getLogger(__name__)
st.title("Interactive Virtual Keyboard with Twilio Integration")
st.info("Use your webcam to interact with the virtual keyboard via hand gestures.")
detector = HandDetector(maxHands=1, detectionCon=0.8)
def video_frame_callback(frame):
img = frame.to_ndarray(format="bgr24")
hands, img = detector.findHands(img, flipType=False)
# Render hand detection results
if hands:
hand = hands[0]
bbox = hand["bbox"]
cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[0]+bbox[2], bbox[1]+bbox[3]), (255, 0, 0), 2)
return av.VideoFrame.from_ndarray(img, format="bgr24")
webrtc_ctx = webrtc_streamer(
key="keyboard-demo",
mode=WebRtcMode.SENDRECV,
rtc_configuration={"iceServers": get_ice_servers()},
video_frame_callback=video_frame_callback,
media_stream_constraints={"video": True, "audio": False},
)
st.markdown("### Instructions")
st.write(
"""
1. Turn on your webcam using the checkbox above.
2. Use hand gestures to interact with the virtual keyboard.
"""
)