import cv2 import mediapipe as mp import streamlit as st from streamlit_webrtc import VideoTransformerBase, webrtc_streamer import os from twilio.rest import Client account_sid = os.environ['TWILIO_ACCOUNT_SID'] auth_token = os.environ['TWILIO_AUTH_TOKEN'] client = Client(account_sid, auth_token) token = client.tokens.create() # Initialize mediapipe pose solution mp_pose = mp.solutions.pose mp_draw = mp.solutions.drawing_utils pose = mp_pose.Pose() # Load the background image background_img_path = 'stage.jpg' background_img = cv2.imread(background_img_path) # Initialize Streamlit app st.title("SwiftAi Avatar Dance") class PoseTransformer(VideoTransformerBase): def __init__(self): self.pose = mp_pose.Pose() def transform(self, frame): img = frame.to_ndarray(format="bgr24") # Resize the frame to fit the display window img = cv2.resize(img, (600, 400)) # Perform pose detection on the frame results = self.pose.process(img) # Resize the background image to match the size of the frame background_img_resized = cv2.resize(background_img, (600, 400)) # Draw extracted pose on the background image with green color mp_draw.draw_landmarks(background_img_resized, results.pose_landmarks, mp_pose.POSE_CONNECTIONS, mp_draw.DrawingSpec((0, 255, 0), 4, 4), mp_draw.DrawingSpec((0, 255, 0), 6, 6)) return background_img_resized webrtc_streamer(rtc_configuration={"iceServers": token.ice_servers},key="example", video_transformer_factory=PoseTransformer)