File size: 684 Bytes
bc69622 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import streamlit as st
from ultralytics import YOLO
import cv2
from PIL import Image
import numpy as np
model = YOLO('yolov8n.pt')
st.title("Object Detection using YOLOv8")
uploaded_file = st.file_uploader("Choose an image...", type=['jpg', 'png'])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
if st.button('Detect Objects'):
image_np = np.array(image)
results = model.predict(source=image_np, save=False)
for r in results:
im_array = r.plot() # Draw bounding boxes
st.image(im_array, caption='Detection Output', use_column_width=True)
|