Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
# Load YOLOv5 model
|
| 6 |
+
model = YOLO(weights='HandSignDetector.pt') # Replace with the path to your best.pt model
|
| 7 |
+
|
| 8 |
+
# Set up Streamlit
|
| 9 |
+
st.title("YOLOv5 Object Detection with Streamlit")
|
| 10 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 11 |
+
|
| 12 |
+
if uploaded_file is not None:
|
| 13 |
+
# Read the uploaded image
|
| 14 |
+
image = Image.open(uploaded_file)
|
| 15 |
+
|
| 16 |
+
# Inference
|
| 17 |
+
results = model(image)
|
| 18 |
+
|
| 19 |
+
# Display the image with bounding boxes
|
| 20 |
+
st.image(image, channels="RGB", caption="Object Detection Result", use_column_width=True)
|
| 21 |
+
|
| 22 |
+
# Display probability and class for each box
|
| 23 |
+
for det in results.xyxy[0]:
|
| 24 |
+
label = int(det[5])
|
| 25 |
+
score = float(det[4])
|
| 26 |
+
box = det[:4].tolist()
|
| 27 |
+
|
| 28 |
+
# Draw box on the image
|
| 29 |
+
st.image(model.plot([image], boxes=[box], labels=[label], confidences=[score])[0],
|
| 30 |
+
channels="RGB", caption=f"Class {label} - Confidence: {score:.2f}", use_column_width=True)
|