import streamlit as st import pickle import numpy as np from PIL import Image import matplotlib.pyplot as plt # ----------------------------- # Load trained model # ----------------------------- with open("/app/src/image_model.pkl", "rb") as f: model = pickle.load(f) # ----------------------------- # Page Config # ----------------------------- st.set_page_config(page_title="Panda vs Bear Classifier", layout="wide") # ----------------------------- # Sidebar Navigation # ----------------------------- st.sidebar.title("Navigation") menu = [ "Introduction", "Problem Statement", "Data Collection", "Feature Engineering", "Model Building", "Deployment" ] choice = st.sidebar.radio("Go to", menu, key="nav_choice") # ----------------------------- # Introduction # ----------------------------- if choice == "Introduction": st.title("Panda vs Bear Image Classification") st.write(""" Wildlife researchers collect thousands of images through camera traps to monitor endangered species like pandas and track other animals like bears. Manually reviewing each photo is **slow, repetitive, and error-prone**. This project was created to show how image classification can **automate animal identification**, helping conservation teams save time and focus on decision-making. """) # ----------------------------- # Problem Statement # ----------------------------- elif choice == "Problem Statement": st.title("Problem Statement") st.write(""" Key challenges in wildlife image monitoring: - Large volume of photos that require sorting - High chance of **human errors** during manual review - **Delays in reporting** which affect timely conservation efforts The goal of this project is to build a system that can **automatically classify images as panda or bear**, enabling faster and more consistent monitoring. """) # ----------------------------- # Data Collection # ----------------------------- elif choice == "Data Collection": st.title("Data Collection") st.write(""" - Collected labeled images of two categories: **Pandas** and **Bears** - Ensured balanced representation from both classes - Standardized all images to a common size and format - Split into training and testing sets for building and evaluation This created a structured and reliable dataset to train the system. """) # ----------------------------- # ----------------------------- # Feature Engineering # ----------------------------- elif choice == "Feature Engineering": st.title("Feature Engineering") st.write(""" To prepare the data for model development, several steps were performed: - Converted images into numerical arrays (pixels) - Standardized dimensions for all images - Extracted the most important patterns for learning - Created clean structured input ready for modeling These steps made the data usable for the classification system. """) # ----------------------------- # Model Building # ----------------------------- elif choice == "Model Building": st.title("Model Building") st.write(""" Using the prepared data, we built a classification system that can: - Learn patterns that distinguish pandas from bears - Identify the correct class of unseen images - Produce consistent predictions in real time The model was tested on new data to validate its performance before deployment as an interactive web application. """) # ----------------------------- # Deployment # ----------------------------- elif choice == "Deployment": st.title("Deployment") st.write("Upload an image to see if it is classified as a **Panda** or a **Bear**:") # --- Show Sample Images --- st.subheader("Sample Images") sample_images = [ ("/app/src/1.jpeg", "Panda"), ("/app/src/242.jpeg", "Bear") ] cols = st.columns(2) for col, (file_path, label) in zip(cols, sample_images): img = Image.open(file_path) col.image(img, caption=label, use_column_width=True) # --- Upload for Prediction --- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: image = Image.open(uploaded_file).convert("RGB") st.image(image, caption="Uploaded Image", use_column_width=True) # Preprocess image (resize -> flatten -> scale handled by pipeline) img_resized = image.resize((64, 64)) img_array = np.array(img_resized).flatten().reshape(1, -1) prediction = model.predict(img_array)[0] st.success(f"Predicted Class: **{prediction}**")