import streamlit as st import cv2 import numpy as np from PIL import Image from transformers import pipeline # Function to load model from Hugging Face @st.cache(allow_output_mutation=True) def load_model(): return pipeline("pose-detection", device=0) # Adjust device as per your requirement # Function to detect yoga pose from image def detect_yoga_pose(image): # Convert PIL image to OpenCV format cv_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) # Your pose detection logic here # Replace the following line with your actual pose detection code return "Detected yoga pose: Warrior II" def main(): st.title("Yoga Pose Detection from Live Camera Feed") # Load the model model = load_model() # Accessing the webcam cap = cv2.VideoCapture(0) # Run the app while True: ret, frame = cap.read() # Display the webcam feed st.image(frame, channels="BGR") # Convert the OpenCV frame to PIL image frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) pil_image = Image.fromarray(frame) # Detect yoga pose from the image pose = detect_yoga_pose(pil_image) # Display the detected yoga pose st.write("Detected Yoga Pose:", pose) # Close the webcam feed if st.button("Stop"): break # Release the webcam and close Streamlit app cap.release() st.stop() if __name__ == "__main__": main()