File size: 865 Bytes
ac8eec4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from ultralytics import YOLO
from PIL import Image
import numpy as np

# Load the YOLO model directly from the root directory
model_path = "best.pt"  # Ensure this matches the exact name of your model file
model = YOLO(model_path)

# Streamlit app
st.title("YOLOv11 Object Detection")
st.write("Upload an image and let the model detect objects.")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file:
    # Read and display the image
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Perform prediction
    with st.spinner("Processing..."):
        results = model.predict(np.array(image))
    
    # Display results
    st.write("Detection Results:")
    st.image(results[0].plot(), caption="Detections", use_column_width=True)