Srikanthgoud7's picture
Update app.py
4e84bac verified
Raw
History Blame Contribute Delete
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"
)