File size: 1,077 Bytes
9412aff
e6a017b
9412aff
 
e6a017b
5cf0ba8
9412aff
 
 
 
 
e6a017b
5cf0ba8
 
e6a017b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
from pathlib import Path
from PIL import Image

import pathlib
import numpy as np
import torch
import streamlit as st
import cv2

#If you have linux (or deploying for linux) use:
pathlib.WindowsPath = pathlib.PosixPath

# Load YOLOv5 model
model = torch.hub.load('./yolov5', 'custom', path='./yolo/best.pt', source='local', force_reload=True)

st.title("YOLO Object Detection Web App")

# Upload image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Convert the file to an OpenCV image
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)
    st.write("Processing...")

    # Convert the image to a format compatible with YOLO
    image_np = np.array(image)
    image_cv = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)

    # Perform YOLO detection
    results = model(image_cv)

    # Render the results
    detected_image = np.squeeze(results.render())

    # Display result
    st.image(detected_image, caption="Detected Image", use_column_width=True)