File size: 2,395 Bytes
4bc985b
f5dedb8
4bc985b
 
 
 
 
 
 
 
 
 
 
 
a2c0e83
 
4bc985b
 
 
 
 
a2c0e83
4bc985b
 
 
 
a2c0e83
f5dedb8
a2c0e83
4bc985b
 
 
 
 
a2c0e83
4bc985b
 
 
f5dedb8
4bc985b
a2c0e83
 
 
f5dedb8
4bc985b
a2c0e83
f5dedb8
a2c0e83
f5dedb8
4bc985b
 
 
f5dedb8
4bc985b
f5dedb8
a2c0e83
 
 
 
f5dedb8
 
4bc985b
 
 
 
f5dedb8
4bc985b
f5dedb8
 
 
 
4bc985b
f5dedb8
 
 
 
4bc985b
 
f5dedb8
 
a2c0e83
f5dedb8
4bc985b
 
a2c0e83
f5dedb8
4bc985b
a2c0e83
4bc985b
f5dedb8
a2c0e83
4bc985b
a2c0e83
 
 
 
 
 
 
 
f5dedb8
4bc985b
 
f5dedb8
 
 
 
a2c0e83
 
 
f5dedb8
a2c0e83
 
f5dedb8
 
 
 
 
 
 
a2c0e83
 
 
 
 
f5dedb8
4bc985b
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import streamlit as st
from PIL import Image, ImageDraw

from transformers import pipeline

st.set_page_config(
    page_title="Smart Vision Inspector",
    page_icon="👁️",
    layout="wide"
)

st.title("👁️ Smart Vision Inspector")

st.markdown("""
### AI-Powered Computer Vision Application

Upload an image and perform:

- Object Detection
- Image Analysis
- Bounding Box Visualization
- AI-Powered Insights
""")

@st.cache_resource
def load_detector():
    return pipeline(
        task="object-detection",
        model="hustvl/yolos-tiny"
    )

detector = load_detector()

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

if uploaded_file is not None:

    image = Image.open(uploaded_file).convert("RGB")

    st.subheader("Original Image")
    st.image(image, use_container_width=True)

    with st.spinner("Running Object Detection..."):
        detections = detector(image)

    draw = ImageDraw.Draw(image)

    object_counts = {}

    for detection in detections:

        score = float(detection["score"])

        if score < 0.5:
            continue

        label = detection["label"]

        object_counts[label] = (
            object_counts.get(label, 0) + 1
        )

        box = detection["box"]

        xmin = int(box["xmin"])
        ymin = int(box["ymin"])
        xmax = int(box["xmax"])
        ymax = int(box["ymax"])

        draw.rectangle(
            [(xmin, ymin), (xmax, ymax)],
            outline="red",
            width=3
        )

        draw.text(
            (xmin, ymin),
            f"{label} {score:.2f}",
            fill="red"
        )

    st.subheader("Detection Results")
    st.image(image, use_container_width=True)

    st.subheader("Detected Objects")

    if object_counts:
        st.json(object_counts)

        summary = []

        for label, count in object_counts.items():
            summary.append(
                f"{count} {label}"
            )

        st.success(
            "Detected: " + ", ".join(summary)
        )

    else:
        st.warning(
            "No objects detected."
        )

with st.sidebar:

    st.header("Skills Demonstrated")

    st.markdown("""
- Computer Vision
- Object Detection
- Image Processing
- Hugging Face Transformers
- Deep Learning
- Python
- Streamlit
    """)

    st.header("Model")

    st.write(
        "YOLOS Tiny"
    )