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" )