import streamlit as st
from PIL import Image
import numpy as np
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import tensorflow_hub as hub
hide_streamlit_style = """
"""
st.markdown(hide_streamlit_style, unsafe_allow_html = True)
st.title('SKIN DISEASE PREDICTION')
st.write("An automated system is proposed for the diagnosis of #23 common skin diseases by using data from clinical images and patient information.")
def main() :
file_uploaded = st.file_uploader('Choose an image...', type = 'jpg')
if file_uploaded is not None :
image = Image.open(file_uploaded)
st.write("Uploaded Image.")
figure = plt.figure()
plt.imshow(image)
plt.axis('off')
st.pyplot(figure)
result, confidence = predict_class(image)
st.write('Prediction : {}'.format(result))
st.write('Confidence : {}%'.format(confidence))
def predict_class(image) :
with st.spinner('Loading Model...'):
classifier_model = keras.models.load_model(r'model_2.h5', compile = False)
shape = ((256,256,3))
model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)]) # ye bhi kaam kar raha he
test_image = image.resize((256, 256))
test_image = keras.preprocessing.image.img_to_array(test_image)
test_image /= 256.0
test_image = np.expand_dims(test_image, axis = 0)
class_name = ['Acne and Rosacea Photos',
'Actinic Keratosis Basal Cell Carcinoma and other Malignant Lesions',
'Atopic Dermatitis Photos', 'Bullous Disease Photos', 'Cellulitis Impetigo and other Bacterial Infections',
'Eczema Photos', 'Exanthems and Drug Eruptions', 'Hair Loss Photos Alopecia and other Hair Diseases',
'Herpes HPV and other STDs Photos', 'Light Diseases and Disorders of Pigmentation', 'Lupus and other Connective Tissue diseases',
'Melanoma Skin Cancer Nevi and Moles', 'Nail Fungus and other Nail Disease', 'Poison Ivy Photos and other Contact Dermatitis',
'Psoriasis pictures Lichen Planus and related diseases', 'Scabies Lyme Disease and other Infestations and Bites',
'Seborrheic Keratoses and other Benign Tumors', 'Systemic Disease', 'Tinea Ringworm Candidiasis and other Fungal Infections',
'Urticaria Hives', 'Vascular Tumors', 'Vasculitis Photos', 'Warts Molluscum and other Viral Infections']
prediction = model.predict_generator(test_image)
confidence = round(100 * (np.max(prediction[0])), 2)
final_pred = class_name[np.argmax(prediction)]
return final_pred, confidence
footer = """
"""
st.markdown(footer, unsafe_allow_html = True)
if __name__ == "__main__":
main()