Srikanth0804's picture
Upload app.py
3c7c1aa verified
Raw History Blame Contribute Delete
1.44 kB
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}`")