Download app.py from Srikanthgoud7/PoseDetectionusingYOLO: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/Srikanthgoud7/PoseDetectionusingYOLO/resolve/main/app.py
- Command line
-
hf download hf://spaces/Srikanthgoud7/PoseDetectionusingYOLO/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Srikanthgoud7/PoseDetectionusingYOLO/resolve/main/app.py
1.31 kB
| import streamlit as st | |
| import cv2 | |
| from ultralytics import YOLO | |
| import tempfile | |
| import os | |
| # Load YOLOv8 pose model | |
| model = YOLO("yolo11x-pose.pt") | |
| st.title("🕺 Pose Detection with YOLOv8") | |
| # File uploader | |
| uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| # Save uploaded file to a temp folder manually | |
| temp_dir = tempfile.gettempdir() | |
| file_path = os.path.join(temp_dir, uploaded_file.name) | |
| with open(file_path, "wb") as f: | |
| f.write(uploaded_file.read()) | |
| # Run inference | |
| results = model(file_path) | |
| for r in results: | |
| # Get annotated frame | |
| annotated_frame = r.plot() | |
| # Convert BGR → RGB for Streamlit | |
| annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB) | |
| # Show output | |
| st.image(annotated_frame, caption="Pose Detection Result", use_container_width=True) | |
| # Optional: save & download | |
| output_path = os.path.join(temp_dir, "pose_output.jpg") | |
| cv2.imwrite(output_path, r.plot()) | |
| with open(output_path, "rb") as file: | |
| st.download_button( | |
| label="Download Result", | |
| data=file, | |
| file_name="pose_detection.jpg", | |
| mime="image/jpeg" | |
| ) | |