-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
46 lines (39 loc) · 1.56 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
40
41
42
43
44
45
46
import streamlit as st
from yolo_model import load_model, detect_components
from utils import load_image
st.title("Object Detection")
@st.cache_resource
def get_model(coco=False):
if coco:
model_path = "yolov8l.pt"
else:
model_path = "yolov8l-oiv7.pt"
return load_model(model_path)
uploaded_file = st.file_uploader(
"Choose an image...", type=["jpg", "jpeg", "png", "webp"]
)
if uploaded_file is not None:
try:
image = load_image(uploaded_file)
st.image(
uploaded_file, caption="Uploaded Image.", use_column_width=False, width=500
)
if st.button("Analyze Image"):
with st.spinner("Analyzing..."):
model_coco = get_model(True)
detected_items_coco = detect_components(image, model_coco)
model_open = get_model(False)
detected_items_open = detect_components(image, model_open)
len_coco, len_open = len(detected_items_coco), len(detected_items_open)
if len_coco > len_open and len_coco > 0:
st.success("Detected components in the image:")
st.write(", ".join(detected_items_coco))
elif len_open > 0:
st.success("Detected components in the image:")
st.write(", ".join(detected_items_open))
else:
st.warning("No components detected.")
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.info("Please upload an image file to start the analysis.")