| import streamlit as st
|
| from PIL import Image
|
| from ultralytics import YOLO
|
| import cv2
|
| import numpy as np
|
| import matplotlib.pyplot as plt
|
|
|
|
|
| MODEL_PATH = 'models/best.pt'
|
| model = YOLO(MODEL_PATH)
|
|
|
|
|
| st.title("BCCD Detection App")
|
| st.write("Upload an image to detect blood cells")
|
|
|
|
|
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
| if uploaded_file is not None:
|
|
|
| image = Image.open(uploaded_file)
|
|
|
|
|
| st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
| image_cv = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
|
|
|
|
| results = model(image_cv)
|
|
|
|
|
| annotated_image = results[0].plot()
|
|
|
|
|
| annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
|
|
|
|
| st.image(annotated_image, caption="Detected Objects", use_column_width=True)
|
|
|
|
|
| st.write("### Prediction Results:")
|
| for box in results[0].boxes:
|
| class_id = int(box.cls[0])
|
| confidence = float(box.conf[0])
|
| x1, y1, x2, y2 = map(int, box.xyxy[0])
|
|
|
| st.write(f"- **Class:** {model.names[class_id]}")
|
| st.write(f"- **Confidence:** {confidence:.2f}")
|
| st.write(f"- **Bounding Box:** ({x1}, {y1}), ({x2}, {y2})")
|
| st.write("---")
|
|
|
|
|
| st.write("Developed by [Your Name]")
|
|
|