Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import cv2
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import tempfile
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Load YOLOv8 pose model
|
| 8 |
+
model = YOLO("yolo11x-pose.pt")
|
| 9 |
+
|
| 10 |
+
st.title("🕺 Pose Detection with YOLOv8")
|
| 11 |
+
|
| 12 |
+
# File uploader
|
| 13 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
|
| 14 |
+
|
| 15 |
+
if uploaded_file is not None:
|
| 16 |
+
# Save uploaded file to a temp folder manually
|
| 17 |
+
temp_dir = tempfile.gettempdir()
|
| 18 |
+
file_path = os.path.join(temp_dir, uploaded_file.name)
|
| 19 |
+
|
| 20 |
+
with open(file_path, "wb") as f:
|
| 21 |
+
f.write(uploaded_file.read())
|
| 22 |
+
|
| 23 |
+
# Run inference
|
| 24 |
+
results = model(file_path)
|
| 25 |
+
|
| 26 |
+
for r in results:
|
| 27 |
+
# Get annotated frame
|
| 28 |
+
annotated_frame = r.plot()
|
| 29 |
+
|
| 30 |
+
# Convert BGR → RGB for Streamlit
|
| 31 |
+
annotated_frame = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
|
| 32 |
+
|
| 33 |
+
# Show output
|
| 34 |
+
st.image(annotated_frame, caption="Pose Detection Result", use_column_width=True)
|
| 35 |
+
|
| 36 |
+
# Optional: save & download
|
| 37 |
+
output_path = os.path.join(temp_dir, "pose_output.jpg")
|
| 38 |
+
cv2.imwrite(output_path, r.plot())
|
| 39 |
+
with open(output_path, "rb") as file:
|
| 40 |
+
st.download_button(
|
| 41 |
+
label="Download Result",
|
| 42 |
+
data=file,
|
| 43 |
+
file_name="pose_detection.jpg",
|
| 44 |
+
mime="image/jpeg"
|
| 45 |
+
)
|