Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
import os
|
6 |
+
import uuid
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
# Load the trained model
|
10 |
+
model = tf.keras.models.load_model('oct_classification_final_model_lg.keras')
|
11 |
+
|
12 |
+
# Define the class labels
|
13 |
+
class_labels = ['CNV', 'DME', 'DRUSEN', 'NORMAL']
|
14 |
+
|
15 |
+
# App title and description
|
16 |
+
st.title("OCT Retinal Image Analyzer")
|
17 |
+
st.write("Created for MedDots Company")
|
18 |
+
|
19 |
+
# File uploader
|
20 |
+
uploaded_file = st.file_uploader("Choose an OCT image...", type=["jpg", "jpeg", "png"])
|
21 |
+
|
22 |
+
if uploaded_file is not None:
|
23 |
+
# Display image
|
24 |
+
image = Image.open(uploaded_file)
|
25 |
+
st.image(image, caption='Uploaded OCT Image', use_column_width=True)
|
26 |
+
|
27 |
+
# Preprocessing image for model
|
28 |
+
img = image.convert('RGB')
|
29 |
+
img = img.resize((224, 224))
|
30 |
+
img_array = np.array(img) / 255.0
|
31 |
+
img_array = np.expand_dims(img_array, axis=0)
|
32 |
+
|
33 |
+
# User input for patient data
|
34 |
+
age = st.number_input("Age", min_value=0, max_value=120, value=30)
|
35 |
+
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
36 |
+
hba1c = st.number_input("HbA1c", min_value=0.0, max_value=20.0, value=5.5, step=0.1)
|
37 |
+
duration_dm = st.number_input("Duration of Diabetes Mellitus (years)", min_value=0, max_value=80, value=5)
|
38 |
+
type_dm = st.selectbox("Type of Diabetes Mellitus", ["Type 1", "Type 2"])
|
39 |
+
eye_side = st.selectbox("Eye Side", ["Left", "Right"])
|
40 |
+
ivr_injections = st.number_input("Number of IVR Injections", min_value=0, max_value=50, value=0)
|
41 |
+
initial_iop = st.number_input("Initial IOP", min_value=0.0, max_value=50.0, value=15.0, step=0.1)
|
42 |
+
initial_logmar = st.number_input("Initial LogMAR", min_value=0.0, max_value=2.0, value=0.0, step=0.01)
|
43 |
+
type_dr = st.selectbox("Type of Diabetic Retinopathy", ["Severe NPDR", "PDR", "PDR s/p PRP"])
|
44 |
+
|
45 |
+
if st.button("Analyze Image"):
|
46 |
+
# Make prediction
|
47 |
+
prediction = model.predict(img_array)
|
48 |
+
predicted_class = class_labels[np.argmax(prediction)]
|
49 |
+
confidence = float(np.max(prediction))
|
50 |
+
|
51 |
+
# Display the result
|
52 |
+
st.subheader(f"Diagnosis: {predicted_class}")
|
53 |
+
st.write(f"Confidence: {confidence * 100:.2f}%")
|
54 |
+
|
55 |
+
# Display patient data summary
|
56 |
+
st.write("### Patient Data:")
|
57 |
+
st.write(f"Age: {age}")
|
58 |
+
st.write(f"Gender: {gender}")
|
59 |
+
st.write(f"HbA1c: {hba1c}")
|
60 |
+
st.write(f"Duration of DM: {duration_dm} years")
|
61 |
+
st.write(f"Type of DM: {type_dm}")
|
62 |
+
st.write(f"Eye Side: {eye_side}")
|
63 |
+
st.write(f"Number of IVR Injections: {ivr_injections}")
|
64 |
+
st.write(f"Initial IOP: {initial_iop}")
|
65 |
+
st.write(f"Initial LogMAR: {initial_logmar}")
|
66 |
+
st.write(f"Type of DR: {type_dr}")
|
67 |
+
|
68 |
+
# Provide a recommendation based on the diagnosis
|
69 |
+
st.write("### Recommendation:")
|
70 |
+
recommendation = {
|
71 |
+
"CNV": "Recommended follow-up with retina specialist for potential anti-VEGF therapy.",
|
72 |
+
"DME": "Suggested treatment includes laser photocoagulation or intravitreal injections.",
|
73 |
+
"DRUSEN": "Regular monitoring advised. Consider lifestyle modifications and AREDS supplements.",
|
74 |
+
"NORMAL": "No immediate action required. Continue regular eye check-ups."
|
75 |
+
}.get(predicted_class, "Please consult with an ophthalmologist for personalized advice.")
|
76 |
+
st.write(recommendation)
|