import streamlit as st import tensorflow as tf import numpy as np from PIL import Image import os import uuid from datetime import datetime # Load the trained model model = tf.keras.models.load_model('oct_classification_final_model_lg.keras') # Define the class labels class_labels = ['CNV', 'DME', 'DRUSEN', 'NORMAL'] # App title and description st.title("OCT Retinal Image Analyzer") st.write("Created for MedDots Company") # File uploader uploaded_file = st.file_uploader("Choose an OCT image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: # Display image image = Image.open(uploaded_file) st.image(image, caption='Uploaded OCT Image', use_column_width=True) # Preprocessing image for model img = image.convert('RGB') img = img.resize((224, 224)) img_array = np.array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) # User input for patient data age = st.number_input("Age", min_value=0, max_value=120, value=30) gender = st.selectbox("Gender", ["Male", "Female", "Other"]) hba1c = st.number_input("HbA1c", min_value=0.0, max_value=20.0, value=5.5, step=0.1) duration_dm = st.number_input("Duration of Diabetes Mellitus (years)", min_value=0, max_value=80, value=5) type_dm = st.selectbox("Type of Diabetes Mellitus", ["Type 1", "Type 2"]) eye_side = st.selectbox("Eye Side", ["Left", "Right"]) ivr_injections = st.number_input("Number of IVR Injections", min_value=0, max_value=50, value=0) initial_iop = st.number_input("Initial IOP", min_value=0.0, max_value=50.0, value=15.0, step=0.1) initial_logmar = st.number_input("Initial LogMAR", min_value=0.0, max_value=2.0, value=0.0, step=0.01) type_dr = st.selectbox("Type of Diabetic Retinopathy", ["Severe NPDR", "PDR", "PDR s/p PRP"]) if st.button("Analyze Image"): # Make prediction prediction = model.predict(img_array) predicted_class = class_labels[np.argmax(prediction)] confidence = float(np.max(prediction)) # Display the result st.subheader(f"Diagnosis: {predicted_class}") st.write(f"Confidence: {confidence * 100:.2f}%") # Display patient data summary st.write("### Patient Data:") st.write(f"Age: {age}") st.write(f"Gender: {gender}") st.write(f"HbA1c: {hba1c}") st.write(f"Duration of DM: {duration_dm} years") st.write(f"Type of DM: {type_dm}") st.write(f"Eye Side: {eye_side}") st.write(f"Number of IVR Injections: {ivr_injections}") st.write(f"Initial IOP: {initial_iop}") st.write(f"Initial LogMAR: {initial_logmar}") st.write(f"Type of DR: {type_dr}") # Provide a recommendation based on the diagnosis st.write("### Recommendation:") recommendation = { "CNV": "Recommended follow-up with retina specialist for potential anti-VEGF therapy.", "DME": "Suggested treatment includes laser photocoagulation or intravitreal injections.", "DRUSEN": "Regular monitoring advised. Consider lifestyle modifications and AREDS supplements.", "NORMAL": "No immediate action required. Continue regular eye check-ups." }.get(predicted_class, "Please consult with an ophthalmologist for personalized advice.") st.write(recommendation)