File size: 958 Bytes
d5933b0 b89d38d | 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 | import streamlit as st
import pickle
import numpy as np
from PIL import Image
import cv2
# Load trained model
with open("rf_pipe.pkl", "rb") as f:
model = pickle.load(f)
st.set_page_config(page_title="Image Classification", layout="centered")
st.title("Image Classification on Blood Cells")
st.write("Upload an image to classify it ")
uploaded_file = st.file_uploader(
"Choose an image",
type=["jpg", "jpeg", "png"]
)
if uploaded_file is not None:
# Read image using PIL
image = Image.open(uploaded_file).convert("RGB")
# Show uploaded image
st.image(image, caption="Uploaded Image")
# Convert PIL image to OpenCV format
img = np.array(image)
img = cv2.resize(img, (64, 64))
# Flatten image (IMPORTANT for KNN)
img_flat = img.reshape(1, -1)
# Prediction
predicted_label = model.predict(img_flat)[0]
st.subheader("Prediction Result")
st.success(f"Predicted Class: {predicted_label}") |