|
import json |
|
from keras.models import load_model |
|
from keras.optimizers import Adam |
|
import gradio as gr |
|
import cv2 |
|
import numpy as np |
|
|
|
|
|
model = load_model('final_vgg1920epochs.h5', compile=False) |
|
|
|
|
|
model.compile(optimizer=Adam(learning_rate=0.001), loss='categorical_crossentropy', metrics=['accuracy']) |
|
|
|
|
|
with open('dat.json') as f: |
|
data = json.load(f) |
|
|
|
keys = list(data) |
|
|
|
def Predict(image): |
|
|
|
img = cv2.resize(image, (32, 32)) / 255.0 |
|
prediction = model.predict(img.reshape(1, 32, 32, 3)) |
|
|
|
|
|
predicted_class_index = prediction.argmax() |
|
predicted_class = keys[predicted_class_index] |
|
confidence_score = prediction[0][predicted_class_index] * 100 |
|
|
|
|
|
description = data[predicted_class]['description'] |
|
symptoms = data[predicted_class]['symptoms'] |
|
causes = data[predicted_class]['causes'] |
|
treatment = data[predicted_class]['treatement-1'] |
|
|
|
return ( |
|
predicted_class, |
|
description, |
|
symptoms, |
|
causes, |
|
treatment, |
|
f"{confidence_score:.2f}%" |
|
) |
|
|
|
demo = gr.Interface( |
|
fn=Predict, |
|
inputs=gr.Image(type="numpy"), |
|
outputs=[ |
|
gr.Textbox(label='Name Of Disease'), |
|
gr.Textbox(label='Description'), |
|
gr.Textbox(label='Symptoms'), |
|
gr.Textbox(label='Causes'), |
|
gr.Textbox(label='Treatment'), |
|
gr.Textbox(label='Confidence Score') |
|
], |
|
title="Skin Disease Classification", |
|
description='This Space predicts these diseases:\n \n1) Acne and Rosacea Photos. \n2) Actinic Keratosis, Basal Cell Carcinoma, and other Malignant Lesions.\n3) Eczema Photos. \n4) Melanoma Skin Cancer, Nevi, and Moles.\n5) Psoriasis pictures, Lichen Planus, and related diseases.\n6) Tinea, Ringworm, Candidiasis, and other Fungal Infections.\n7) Urticaria Hives.\n8) Nail Fungus and other Nail Diseases.\n' |
|
) |
|
|
|
demo.launch(debug=True) |
|
|