| import streamlit as st |
| import cv2 |
| from ultralytics import YOLO |
| import tempfile |
| import os |
|
|
| |
| model = YOLO("yolo11x-pose.pt") |
|
|
| st.title("🕺 Pose Detection with YOLOv8") |
|
|
| |
| uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"]) |
|
|
| if uploaded_file is not None: |
| |
| 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()) |
|
|
| |
| results = model(file_path) |
|
|
| for r in results: |
| |
| annotated_frame = r.plot() |
|
|
| |
| annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB) |
|
|
| |
| st.image(annotated_frame, caption="Pose Detection Result", use_container_width=True) |
|
|
| |
| 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" |
| ) |
|
|