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