import streamlit as st import pandas as pd import ast import numpy as np from PIL import Image, ImageDraw, ImageFont df = pd.read_excel("sample_dfver3.xlsx") print(df) image_names = df['filename_gs'].unique().tolist() default_font = ImageFont.load_default() #@st.cache def process_image(image_name, confidence): rows = df[df['filename_gs'] == image_name] image_path = image_name image = Image.open(image_path) draw = ImageDraw.Draw(image) for _, row in rows.iterrows(): bbox_str = row['bbox'] bbox = ast.literal_eval(bbox_str) confidence_value = row['conf'] common_name = row['common_name'] x = round(float(bbox[0]) * image.width) y = round(float(bbox[1]) * image.height) w = round(float(bbox[2]) * image.width) h = round(float(bbox[3]) * image.height) if confidence_value >= float(confidence): draw.rectangle([(x, y), (x+w, y+h)], outline=(0, 255, 0), width=5) text = f"{common_name} : {confidence_value:.3f}" text_width, text_height = draw.textsize(text, font=default_font) text_x = x text_y = y - text_height - 10 bbox = (text_x, text_y, text_x + text_width, text_y + text_height) draw.rectangle(bbox, fill="red") draw.text((text_x, text_y), text, fill="#FFFFFF", font=default_font) return np.array(image) def main(): st.title("Bounding Box Visualization") st.sidebar.header("Settings") confidence = st.sidebar.slider("Confidence", min_value=0.0, max_value=1.0, step=0.01) image_name = st.sidebar.selectbox("Select an image", image_names) image = process_image(image_name, confidence) st.image(image, use_column_width=True) if __name__ == "__main__": main()