|
|
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') |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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), |
|
|
|
|
|
|
|
|
cache_examples = False, |
|
|
allow_flagging = 'never', |
|
|
) |
|
|
|
|
|
|
|
|
demo.launch(debug='True', share='True') |