Spaces:
Runtime error
Runtime error
File size: 4,726 Bytes
8215b6d c19644a 8215b6d 1589177 8215b6d 1589177 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | 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}**")
|