File size: 4,210 Bytes
a4dac84 f45ecb2 52937ea a4dac84 c7c8a5b a4dac84 93faf00 74f29ef eb93bec dda2af6 949217b 8e6675f 98efa9a 2b1ba35 98efa9a 37ef6ed bedd789 e170919 37ef6ed 98efa9a f45ecb2 086e164 f45ecb2 96b97e3 086e164 f45ecb2 54e2cda f45ecb2 54e2cda 086e164 54e2cda 086e164 54e2cda 086e164 5e98302 086e164 5e98302 086e164 f45ecb2 97b187b 54e2cda 086e164 c7c8a5b 086e164 a94ecd6 c933be4 086e164 8cbcb31 9b884d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | import gradio as gr
from gradio import components
import tensorflow as tf
from keras.models import load_model
import numpy as np
import cv2
from PIL import Image, ImageOps
js = """
function createGradioAnimation() {
var container = document.createElement('div');
container.id = 'gradio-animation';
container.style.fontSize = '2em';
container.style.fontWeight = 'bold';
container.style.textAlign = 'center';
container.style.marginBottom = '20px';
var text = 'A-EYE: An Intelligent Eye Disease Classifier';
for (var i = 0; i < text.length; i++) {
(function(i){
setTimeout(function(){
var letter = document.createElement('span');
letter.style.opacity = '0';
letter.style.transition = 'opacity 0.5s';
letter.innerText = text[i];
container.appendChild(letter);
setTimeout(function() {
letter.style.opacity = '1';
}, 50);
}, i * 250);
})(i);
}
var gradioContainer = document.querySelector('.gradio-container');
gradioContainer.insertBefore(container, gradioContainer.firstChild);
return 'Animation created';
}
"""
image = Image.open('background1.png')
#Resize the image
resized_image = image.resize((150, 50), Image.LANCZOS)
background = image.resize((3000, 700))
with gr.Blocks(js=js,theme=gr.themes.Soft(), css=".gradio-container { max-width: 100%;}") as demo:
with gr.Row():
gr.Image(background, height = 280, interactive = False, show_download_button = False, show_share_button = False)
with gr.Row():
gr.Markdown(
'''
<div style="text-align: justify;">
A-EYE is an intelligent eye disease classifier designed for accurate eye disease classification using deep learning.
With its enhanced model, A-EYE analyzes fundus images to detect Cataracts, Diabetic Retinopathy, Glaucoma, or Normal conditions.
Users can easily upload a fundus image, and the system will process it to provide detailed classification results.
The results display probability percentages for each condition, ensuring transparency and confidence in the diagnosis.
The condition with the highest probability is assigned to the image, offering a reliable and efficient tool for eye health assessment.
A-EYE has the potential to assist ophthalmologists in providing first screening of suspected eye diseases.
</div>
'''
)
class_names = ['cataracts', 'diabetic retinopathy', 'glaucoma', 'normal']
model = load_model('densenet121_model.keras')
def predict_input_image(img):
img = cv2.resize(img, (224, 224))
img = img.reshape((-1, 224, 224, 3))
img = tf.keras.applications.densenet.preprocess_input(img)
#image_tensor = tf.convert_to_tensor(img)
# Resize the image to 224x224.
#image_tensor = tf.image.resize(image_tensor, (224, 224))
# Cast the data to float32.
#image_tensor = tf.cast(image_tensor, tf.float32)
# Add a batch dimension.
#image_tensor = tf.expand_dims(image_tensor, 0)
# Normalize the data.
#image_tensor = image_tensor / 255.0
prediction = model.predict(img).flatten()
predicted_class = {class_names[i]: float(prediction[i]) for i in range(4)}
return predicted_class
title=(
'''
<style>h1 {text-align: center;}</style>
<h1> A-EYE: An Intelligent Eye Disease Classifier </h1>
'''
)
gr.Interface(fn = predict_input_image,
inputs = gr.Image(width = 224, height = 224),
outputs = gr.Label(num_top_classes = 4),
#title = title,
#description = 'This classifier is developed to classify cataracts, diabetic retinopathy, glaucoma and normal eyes through fundus images',
cache_examples = False,
allow_flagging = 'never',
)
demo.launch(debug='True', share='True') |