ritikesh18's picture
Upload app.py
9603354 verified
Raw
History Blame Contribute Delete
1.16 kB
import streamlit as st
import numpy as np
import tensorflow as tf
from PIL import Image
# Load the trained model
@st.cache_resource
def load_model():
return tf.keras.models.load_model("signature_verification_model.h5")
model = load_model()
# Function to preprocess the image
def preprocess_image(image):
image = image.convert("L") # Convert to grayscale
image = image.resize((128, 128)) # Resize to match model input size
image = np.array(image) / 255.0 # Normalize
image = np.expand_dims(image, axis=0) # Add batch dimension
return image
# Streamlit UI
st.title("Signature Verification System")
uploaded_file = st.file_uploader("Upload a signature image", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Signature", use_column_width=True)
# Preprocess and predict
processed_img = preprocess_image(image)
prediction = model.predict(processed_img)
# Display result
if prediction[0, 1] > 0.5:
st.success("✅ Valid Signature")
else:
st.error("❌ Invalid Signature")