yashpat85 commited on
Commit
c80d070
·
verified ·
1 Parent(s): d7aa9c9

Upload 2 files

Browse files
Files changed (2) hide show
  1. Home.py +62 -0
  2. prediction.py +28 -0
Home.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import streamlit as st
3
+ from prediction import predict_single_image
4
+
5
+ knn_model = joblib.load('models/knn_model.joblib')
6
+ svm_model = joblib.load('models/svm_model.joblib')
7
+ random_forest_model = joblib.load('models/random_forest_model.joblib')
8
+
9
+ def show_error_popup(message):
10
+ st.error(message, icon="🚨")
11
+
12
+ st.set_page_config(layout="wide")
13
+
14
+ st.title('CASIA PALMPRINT DATASET')
15
+ st.markdown('By Yash Patel')
16
+
17
+ st.header('Add Palmprint Image')
18
+
19
+ uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png", "jpeg"])
20
+
21
+ st.header("Available Models")
22
+ option = st.selectbox(
23
+ "Available Models",
24
+ ("SVM", "KNN","Random Forest"),
25
+ )
26
+
27
+ predicted_label =""
28
+ col1, col2= st.columns(2)
29
+
30
+ if uploaded_file is not None:
31
+ with col1:
32
+ image_data = uploaded_file.read()
33
+ st.image(image_data, caption="Uploaded Image")
34
+ with col2:
35
+ if option=="SVM":
36
+ predicted_label = predict_single_image(svm_model,image_data)
37
+ elif option=="KNN":
38
+ predicted_label = predict_single_image(knn_model, image_data)
39
+ elif option=="Random Forest":
40
+ predicted_label = predict_single_image(random_forest_model, image_data)
41
+ else:
42
+ p = "Other Models are still under training due to overfitting"
43
+
44
+ print(predicted_label)
45
+
46
+ st.markdown("""
47
+ <style>
48
+ .big-font {
49
+ display: flex;
50
+ align-items:center;
51
+ justify-content: center;
52
+ font-size:50px !important;
53
+ color:green;
54
+ height: 50vh;
55
+ }
56
+ </style>
57
+ """, unsafe_allow_html=True)
58
+
59
+ st.markdown(f'<div class="big-font">{predicted_label}</div>', unsafe_allow_html=True)
60
+
61
+ else:
62
+ show_error_popup("Please Upload Image...")
prediction.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import tensorflow as tf
4
+
5
+ def preprocess_image(img):
6
+ """Preprocess a single image for prediction."""
7
+ img = tf.image.decode_jpeg(img, channels=1)
8
+ img= tf.image.resize(img, (224, 224))
9
+ img_flattened = tf.reshape(img, (-1,))
10
+
11
+ # Convert to 2D array (expected input format for the model)
12
+ img_flattened = np.expand_dims(img_flattened, axis=0) # Shape: (1, features)
13
+
14
+ return img_flattened
15
+
16
+
17
+ def predict_single_image(model, image):
18
+ """Predict the label of a single image."""
19
+ # Preprocess the image
20
+ processed_image = preprocess_image(image)
21
+
22
+ # Make prediction
23
+ prediction = model.predict(processed_image)
24
+
25
+ return prediction[0] # Return the predicted label
26
+
27
+
28
+ # Test the single image