Spaces:
No application file
No application file
Upload 2 files
Browse filesFiles changed (2)
- Home.pyAdded+62
- prediction.pyAdded+28
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import joblib
import streamlit as st
from prediction import predict_single_image
knn_model = joblib.load('models/knn_model.joblib')
svm_model = joblib.load('models/svm_model.joblib')
random_forest_model = joblib.load('models/random_forest_model.joblib')
def show_error_popup(message):
st.error(message, icon="🚨")
st.set_page_config(layout="wide")
st.title('CASIA PALMPRINT DATASET')
st.markdown('By Yash Patel')
st.header('Add Palmprint Image')
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png", "jpeg"])
st.header("Available Models")
option = st.selectbox(
"Available Models",
("SVM", "KNN","Random Forest"),
)
predicted_label =""
col1, col2= st.columns(2)
if uploaded_file is not None:
with col1:
image_data = uploaded_file.read()
st.image(image_data, caption="Uploaded Image")
with col2:
if option=="SVM":
predicted_label = predict_single_image(svm_model,image_data)
elif option=="KNN":
predicted_label = predict_single_image(knn_model, image_data)
elif option=="Random Forest":
predicted_label = predict_single_image(random_forest_model, image_data)
else:
p = "Other Models are still under training due to overfitting"
print(predicted_label)
st.markdown("""
<style>
.big-font {
display: flex;
align-items:center;
justify-content: center;
font-size:50px !important;
color:green;
height: 50vh;
}
</style>
""", unsafe_allow_html=True)
st.markdown(f'<div class="big-font">{predicted_label}</div>', unsafe_allow_html=True)
else:
show_error_popup("Please Upload Image...")12345678910111213141516171819202122232425262728import cv2
import numpy as np
import tensorflow as tf
def preprocess_image(img):
"""Preprocess a single image for prediction."""
img = tf.image.decode_jpeg(img, channels=1)
img= tf.image.resize(img, (224, 224))
img_flattened = tf.reshape(img, (-1,))
# Convert to 2D array (expected input format for the model)
img_flattened = np.expand_dims(img_flattened, axis=0) # Shape: (1, features)
return img_flattened
def predict_single_image(model, image):
"""Predict the label of a single image."""
# Preprocess the image
processed_image = preprocess_image(image)
# Make prediction
prediction = model.predict(processed_image)
return prediction[0] # Return the predicted label
# Test the single imageHome.pyAdded+62
prediction.pyAdded+28