-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (29 loc) · 1.23 KB
/
app.py
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
39
from PIL import Image
import streamlit as st
from ultralytics import YOLO
def load_model():
return YOLO("yolo11n.pt")
def query(image, model):
results = model(image)
result = results[0]
result.save(filename="result.jpg")
return "result.jpg", result
def main():
st.title("Live Object Finder using YOLO11")
model = load_model()
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file).convert("RGB")
st.image(image, caption="Uploaded Image", use_column_width=True)
if st.button("Detect Objects"):
with st.spinner("Detecting objects..."):
result_image, result = query(image, model)
st.image(result_image, caption="Image with Bounding Boxes", use_column_width=True)
st.write("Detected Objects with there possibility :")
for box in result.boxes:
class_id = int(box.cls[0])
class_name = result.names[class_id]
confidence = float(box.conf[0])*100
st.markdown(f"- **{class_name}**: {confidence:.2f}%")
if __name__ == "__main__":
main()