import streamlit as st from PIL import Image import cv2 import numpy as np import cvlib as cv from cvlib.object_detection import draw_bbox # Streamlit UI st.title("Object Detection with YOLO") uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) if uploaded_image is not None: image = Image.open(uploaded_image) st.image(image, caption="Uploaded Image", use_column_width=True) if st.button("Detect Objects"): st.write("Detecting objects...") # Convert the uploaded image to a NumPy array image_np = np.array(image) # Use YOLOv3 for object detection bbox, label, conf = cv.detect_common_objects(image_np) # Draw bounding boxes on the image output_image = draw_bbox(image_np, bbox, label, conf) # Convert the NumPy array back to an image output_image = Image.fromarray(output_image) # Display the image with bounding boxes st.image(output_image, caption="Objects Detected", use_column_width=True) st.text("Upload an image and click the 'Detect Objects' button to see object detection results using YOLO.")