Spaces:
Sleeping
Sleeping
File size: 1,440 Bytes
3c7c1aa | 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 numpy as np
import pickle
import cv2
# -------------------------------
# Page Config
# -------------------------------
st.set_page_config(page_title="π Car Brand Logo Classifier")
st.title("π Car Brand Logo Classifier")
# -------------------------------
# Load the full pipeline (Scaler + PCA + Classifier)
# -------------------------------
with open("car_logo_pipeline.pkl", "rb") as f:
pipeline = pickle.load(f)
# -------------------------------
# File Uploader
# -------------------------------
uploaded_file = st.file_uploader("Upload a car logo image", type=["jpg", "jpeg", "png"])
if uploaded_file:
# Read uploaded file directly into OpenCV format (BGR, uint8) just like training
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
img_array = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
# Display image in Streamlit (convert to RGB for display only)
st.image(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB), caption="Uploaded Logo", use_column_width=True)
# Resize to match training preprocessing
resized_img = cv2.resize(img_array, (300, 300))
# Flatten for model input
flat_img = resized_img.flatten().reshape(1, -1)
# Predict button
if st.button("π Predict Brand"):
prediction = pipeline.predict(flat_img)[0]
st.markdown(f"## β
Predicted Brand: `{prediction}`") |