|
import gradio as gr
|
|
from tensorflow import keras
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
|
|
model = keras.models.load_model('c:/Users/neeli/diabet_intern/retino_model.keras')
|
|
|
|
|
|
class_names = ['Healthy', 'Mild DR', 'Moderate DR', 'Proliferative DR', 'Severe DR']
|
|
|
|
|
|
def eye_care_recommendations(predicted_class):
|
|
recommendations = {
|
|
'Healthy': 'Your eyes seem healthy. Continue with regular eye check-ups and maintain a balanced diet.',
|
|
'Mild DR': 'Mild signs of diabetic retinopathy. Ensure strict blood sugar control and regular eye exams.',
|
|
'Moderate DR': 'Moderate diabetic retinopathy detected. Consult with an ophthalmologist for treatment options.',
|
|
'Proliferative DR': 'Advanced stage detected. Immediate medical attention is required to prevent further vision loss.',
|
|
'Severe DR': 'Severe diabetic retinopathy detected. Medical intervention is necessary. Please visit a doctor immediately.'
|
|
}
|
|
return recommendations.get(predicted_class, "No recommendation available.")
|
|
|
|
|
|
def predict(image):
|
|
|
|
image = image.resize((128, 128))
|
|
image = np.expand_dims(np.array(image), axis=0)
|
|
|
|
|
|
predictions = model.predict(image)
|
|
predicted_class_index = np.argmax(predictions, axis=1)[0]
|
|
predicted_class = class_names[predicted_class_index]
|
|
|
|
|
|
care_info = eye_care_recommendations(predicted_class)
|
|
|
|
|
|
return f"Predicted Condition: {predicted_class}", care_info
|
|
|
|
|
|
interface = gr.Interface(
|
|
fn=predict,
|
|
inputs=gr.Image(type="pil"),
|
|
outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Eye Care Recommendations")],
|
|
title="Diabetic Retinopathy Prediction",
|
|
description="Upload a retinal image, and the model will predict the stage of Diabetic Retinopathy. Eye care recommendations will be provided based on the prediction."
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
interface.launch()
|
|
|