Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Function to load model from Hugging Face
|
8 |
+
@st.cache(allow_output_mutation=True)
|
9 |
+
def load_model():
|
10 |
+
return pipeline("pose-detection", device=0) # Adjust device as per your requirement
|
11 |
+
|
12 |
+
# Function to detect yoga pose from image
|
13 |
+
def detect_yoga_pose(image):
|
14 |
+
# Convert PIL image to OpenCV format
|
15 |
+
cv_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
16 |
+
# Your pose detection logic here
|
17 |
+
# Replace the following line with your actual pose detection code
|
18 |
+
return "Detected yoga pose: Warrior II"
|
19 |
+
|
20 |
+
def main():
|
21 |
+
st.title("Yoga Pose Detection from Live Camera Feed")
|
22 |
+
|
23 |
+
# Load the model
|
24 |
+
model = load_model()
|
25 |
+
|
26 |
+
# Accessing the webcam
|
27 |
+
cap = cv2.VideoCapture(0)
|
28 |
+
|
29 |
+
# Run the app
|
30 |
+
while True:
|
31 |
+
ret, frame = cap.read()
|
32 |
+
|
33 |
+
# Display the webcam feed
|
34 |
+
st.image(frame, channels="BGR")
|
35 |
+
|
36 |
+
# Convert the OpenCV frame to PIL image
|
37 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
38 |
+
pil_image = Image.fromarray(frame)
|
39 |
+
|
40 |
+
# Detect yoga pose from the image
|
41 |
+
pose = detect_yoga_pose(pil_image)
|
42 |
+
|
43 |
+
# Display the detected yoga pose
|
44 |
+
st.write("Detected Yoga Pose:", pose)
|
45 |
+
|
46 |
+
# Close the webcam feed
|
47 |
+
if st.button("Stop"):
|
48 |
+
break
|
49 |
+
|
50 |
+
# Release the webcam and close Streamlit app
|
51 |
+
cap.release()
|
52 |
+
st.stop()
|
53 |
+
|
54 |
+
if __name__ == "__main__":
|
55 |
+
main()
|