Spaces:
Running
Running
File size: 716 Bytes
f0305ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import streamlit as st
from ultralytics import YOLO
from PIL import Image
import numpy as np
st.title("Object Detection (YOLOv8)")
@st.cache_resource
def load_model():
return YOLO("models/best.pt")
model = load_model()
confidence = st.slider("Confidence Threshold", 0.1, 1.0, 0.25)
uploaded_file = st.file_uploader("Upload Image", type=["jpg","jpeg","png"])
if uploaded_file:
try:
image = Image.open(uploaded_file)
img_array = np.array(image)
results = model.predict(img_array, conf=confidence)
annotated = results[0].plot()
st.image(annotated, width="stretch")
except Exception as e:
st.error(f"Detection failed: {e}") |