Restnet_app / app.py
Krish30's picture
Rename app1.py to app.py
43544a6 verified
Raw
History Blame Contribute Delete
1.4 kB
import streamlit as st
import streamlit.web.cli as stcli
import tensorflow as tf
import numpy as np
from PIL import Image
IMAGE_SIZE = 256
# Load the saved model
model = tf.keras.models.load_model('my_model.h5')
# Define class labels (adjust this according to your specific classes)
class_labels = ['Mild', 'Moderate', 'No_DR', 'Proliferate_DR', 'Severe']
def predict(image):
# Preprocess the image to the required size and scale
image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE))
image = np.expand_dims(image, axis=0) # Add batch dimension
# Make prediction
predictions = model.predict(image)
confidence = np.max(predictions)
predicted_class = class_labels[np.argmax(predictions)]
return predicted_class, float(confidence)
# Create the Streamlit interface
st.title("Early Diabetic Retinopathy Detection")
st.write("Upload an image and get the predicted class along with confidence score.")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image.', use_column_width=True)
st.write("")
st.write("Classifying...")
predicted_class, confidence = predict(image)
st.write(f"Predicted Class: {predicted_class}")
st.write(f"Confidence: {confidence:.2f}")