Upload app1.py
Browse files
app1.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import streamlit.web.cli as stcli
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
IMAGE_SIZE = 256
|
| 8 |
+
|
| 9 |
+
# Load the saved model
|
| 10 |
+
model = tf.keras.models.load_model('my_model.h5')
|
| 11 |
+
|
| 12 |
+
# Define class labels (adjust this according to your specific classes)
|
| 13 |
+
class_labels = ['Mild', 'Moderate', 'No_DR', 'Proliferate_DR', 'Severe']
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def predict(image):
|
| 17 |
+
# Preprocess the image to the required size and scale
|
| 18 |
+
image = tf.image.resize(image, (IMAGE_SIZE, IMAGE_SIZE))
|
| 19 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 20 |
+
|
| 21 |
+
# Make prediction
|
| 22 |
+
predictions = model.predict(image)
|
| 23 |
+
confidence = np.max(predictions)
|
| 24 |
+
predicted_class = class_labels[np.argmax(predictions)]
|
| 25 |
+
|
| 26 |
+
return predicted_class, float(confidence)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Create the Streamlit interface
|
| 30 |
+
st.title("Early Diabetic Retinopathy Detection")
|
| 31 |
+
st.write("Upload an image and get the predicted class along with confidence score.")
|
| 32 |
+
|
| 33 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 34 |
+
|
| 35 |
+
if uploaded_file is not None:
|
| 36 |
+
image = Image.open(uploaded_file)
|
| 37 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 38 |
+
st.write("")
|
| 39 |
+
st.write("Classifying...")
|
| 40 |
+
|
| 41 |
+
predicted_class, confidence = predict(image)
|
| 42 |
+
|
| 43 |
+
st.write(f"Predicted Class: {predicted_class}")
|
| 44 |
+
st.write(f"Confidence: {confidence:.2f}")
|