|
import streamlit as st |
|
import joblib |
|
import numpy as np |
|
from sklearn.neighbors import KNeighborsClassifier |
|
from tensorflow.keras.preprocessing import image |
|
import os |
|
from PIL import Image |
|
|
|
|
|
knn = joblib.load('knn_model.pk1') |
|
class_names = joblib.load('class_names.pk1') |
|
|
|
|
|
st.title("Animal Classification Using KNN Model") |
|
|
|
|
|
st.write("Upload an image of an animal and the model will predict which animal it is.") |
|
|
|
|
|
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_image is not None: |
|
|
|
img = Image.open(uploaded_image) |
|
st.image(img, caption='Uploaded Image.', use_column_width=True) |
|
|
|
|
|
img = img.resize((64, 64)) |
|
img_array = np.array(img) |
|
img_array = img_array.flatten().reshape(1, -1) |
|
|
|
|
|
prediction = knn.predict(img_array) |
|
predicted_class = class_names[prediction[0]] |
|
|
|
|
|
st.write(f"Prediction: {predicted_class}") |
|
|
|
|