Srikanth0804 commited on
Commit
88d339e
·
verified ·
1 Parent(s): 0a4bdcc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # streamlit_yolo_pose.py
2
+
3
+ import streamlit as st
4
+ import cv2
5
+ import numpy as np
6
+ from ultralytics import YOLO
7
+ from PIL import Image
8
+
9
+ # -------------------------------
10
+ # Streamlit App Title
11
+ # -------------------------------
12
+ st.title("YOLOv8 Pose Detection App")
13
+
14
+ # -------------------------------
15
+ # Load YOLO Pose Model
16
+ # -------------------------------
17
+ @st.cache_resource
18
+ def load_model(model_name="yolov8n-pose.pt"):
19
+ return YOLO(model_name)
20
+
21
+ model = load_model()
22
+
23
+ # -------------------------------
24
+ # Upload Image
25
+ # -------------------------------
26
+ uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
27
+
28
+ if uploaded_file is not None:
29
+ # Load uploaded image
30
+ image = Image.open(uploaded_file).convert("RGB")
31
+ img_array = np.array(image)
32
+
33
+ # Perform Inference
34
+ results = model(img_array)
35
+
36
+ # Annotated results with keypoints
37
+ annotated_img = results[0].plot()
38
+
39
+ # Get shape of annotated image
40
+ h, w, c = annotated_img.shape
41
+ st.write(f"**Annotated Image Shape:** {h} x {w} x {c}")
42
+
43
+ # Display Input and Output
44
+ col1, col2 = st.columns(2)
45
+ with col1:
46
+ st.image(image, caption="Original Image", use_column_width=True)
47
+ with col2:
48
+ st.image(annotated_img, caption="Pose Detected", use_column_width=True)
49
+
50
+ # Option to download the annotated image
51
+ result_bgr = cv2.cvtColor(annotated_img, cv2.COLOR_RGB2BGR)
52
+ cv2.imwrite("pose_output.jpg", result_bgr)
53
+ with open("pose_output.jpg", "rb") as f:
54
+ st.download_button("Download Pose Image", f, "pose_output.jpg")