Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
import cv2
|
| 5 |
+
|
| 6 |
+
# -------------------------------
|
| 7 |
+
# Page Config
|
| 8 |
+
# -------------------------------
|
| 9 |
+
st.set_page_config(page_title="π Car Brand Logo Classifier")
|
| 10 |
+
|
| 11 |
+
st.title("π Car Brand Logo Classifier")
|
| 12 |
+
|
| 13 |
+
# -------------------------------
|
| 14 |
+
# Load the full pipeline (Scaler + PCA + Classifier)
|
| 15 |
+
# -------------------------------
|
| 16 |
+
with open("car_logo_pipeline.pkl", "rb") as f:
|
| 17 |
+
pipeline = pickle.load(f)
|
| 18 |
+
|
| 19 |
+
# -------------------------------
|
| 20 |
+
# File Uploader
|
| 21 |
+
# -------------------------------
|
| 22 |
+
uploaded_file = st.file_uploader("Upload a car logo image", type=["jpg", "jpeg", "png"])
|
| 23 |
+
|
| 24 |
+
if uploaded_file:
|
| 25 |
+
# Read uploaded file directly into OpenCV format (BGR, uint8) just like training
|
| 26 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 27 |
+
img_array = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
| 28 |
+
|
| 29 |
+
# Display image in Streamlit (convert to RGB for display only)
|
| 30 |
+
st.image(cv2.cvtColor(img_array, cv2.COLOR_BGR2RGB), caption="Uploaded Logo", use_column_width=True)
|
| 31 |
+
|
| 32 |
+
# Resize to match training preprocessing
|
| 33 |
+
resized_img = cv2.resize(img_array, (300, 300))
|
| 34 |
+
|
| 35 |
+
# Flatten for model input
|
| 36 |
+
flat_img = resized_img.flatten().reshape(1, -1)
|
| 37 |
+
|
| 38 |
+
# Predict button
|
| 39 |
+
if st.button("π Predict Brand"):
|
| 40 |
+
prediction = pipeline.predict(flat_img)[0]
|
| 41 |
+
st.markdown(f"## β
Predicted Brand: `{prediction}`")
|