Spaces:
Sleeping
Sleeping
Download app.py from Srikanth0804/Logo_Classification: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/Srikanth0804/Logo_Classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/Srikanth0804/Logo_Classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Srikanth0804/Logo_Classification/resolve/main/app.py
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}`") |