cybernatedArt commited on
Commit
d1371b6
·
1 Parent(s): d7119c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -35
app.py CHANGED
@@ -1,41 +1,87 @@
1
- from fastai.vision.all import *
2
- import gradio as gr
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
4
 
5
- # Cargamos el learner
6
- learn = load_learner('Pickle_SD_Model.pkl')
7
 
8
- # Definimos las etiquetas de nuestro modelo
9
- labels = learn.dls.vocab
 
 
 
 
 
 
 
 
 
 
10
 
 
 
 
11
 
12
- # Definimos una función que se encarga de llevar a cabo las predicciones
13
- def predict(img):
14
- img = PILImage.create(img)
15
- pred,pred_idx,probs = learn.predict(img)
16
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
17
-
18
-
19
- # launching the interface
20
-
21
- title = "SKIN DISEASE PREDICTION"
22
- description ="An automated system is proposed for the diagnosis of #23 common skin diseases by using data from clinical images and patient information."
 
 
 
 
 
 
 
 
23
 
24
- examples = [
25
- ['123.jpg'],
26
- ['acne-closed-comedo-2.jpg'],
27
- ['cherry-angioma-16.jpg'],
28
- ['distal-subungual-onychomycosis-86.jpg'],
29
- ['malignant-melanoma-16.jpg'],
30
- ['tinea-primary-lesion-15.jpg']
31
- ]
32
-
33
- # launching the interface
34
- gr.Interface( fn=predict,
35
- inputs = gr.inputs.Image(shape=(256, 256)),
36
- outputs = gr.outputs.Label(num_top_classes=3),
37
- capture_session = True,
38
- title=title,
39
- description= description,
40
- examples = examples
41
- ).launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from tensorflow import keras
6
+ import matplotlib.pyplot as plt
7
+ import tensorflow_hub as hub
8
 
9
+ hide_streamlit_style = """
10
+ <style>
11
+ #MainMenu {visibility: hidden;}
12
+ footer {visibility: hidden;}
13
+ </style>
14
+ """
15
+
16
+ st.markdown(hide_streamlit_style, unsafe_allow_html = True)
17
 
18
+ st.title('SKIN DISEASE PREDICTION')
19
+ st.write("An automated system is proposed for the diagnosis of #23 common skin diseases by using data from clinical images and patient information.")
20
 
21
+ def main() :
22
+ file_uploaded = st.file_uploader('Choose an image...', type = 'jpg')
23
+ if file_uploaded is not None :
24
+ image = Image.open(file_uploaded)
25
+ st.write("Uploaded Image.")
26
+ figure = plt.figure()
27
+ plt.imshow(image)
28
+ plt.axis('off')
29
+ st.pyplot(figure)
30
+ result, confidence = predict_class(image)
31
+ st.write('Prediction : {}'.format(result))
32
+ st.write('Confidence : {}%'.format(confidence))
33
 
34
+ def predict_class(image) :
35
+ with st.spinner('Loading Model...'):
36
+ classifier_model = keras.models.load_model(r'model_2.h5', compile = False)
37
 
38
+ shape = ((256,256,3))
39
+ model = keras.Sequential([hub.KerasLayer(classifier_model, input_shape = shape)]) # ye bhi kaam kar raha he
40
+ test_image = image.resize((256, 256))
41
+ test_image = keras.preprocessing.image.img_to_array(test_image)
42
+ test_image /= 256.0
43
+ test_image = np.expand_dims(test_image, axis = 0)
44
+ class_name = ['Acne and Rosacea Photos',
45
+ 'Actinic Keratosis Basal Cell Carcinoma and other Malignant Lesions',
46
+ 'Atopic Dermatitis Photos', 'Bullous Disease Photos', 'Cellulitis Impetigo and other Bacterial Infections',
47
+ 'Eczema Photos', 'Exanthems and Drug Eruptions', 'Hair Loss Photos Alopecia and other Hair Diseases',
48
+ 'Herpes HPV and other STDs Photos', 'Light Diseases and Disorders of Pigmentation', 'Lupus and other Connective Tissue diseases',
49
+ 'Melanoma Skin Cancer Nevi and Moles', 'Nail Fungus and other Nail Disease', 'Poison Ivy Photos and other Contact Dermatitis',
50
+ 'Psoriasis pictures Lichen Planus and related diseases', 'Scabies Lyme Disease and other Infestations and Bites',
51
+ 'Seborrheic Keratoses and other Benign Tumors', 'Systemic Disease', 'Tinea Ringworm Candidiasis and other Fungal Infections',
52
+ 'Urticaria Hives', 'Vascular Tumors', 'Vasculitis Photos', 'Warts Molluscum and other Viral Infections']
53
+ prediction = model.predict_generator(test_image)
54
+ confidence = round(100 * (np.max(prediction[0])), 2)
55
+ final_pred = class_name[np.argmax(prediction)]
56
+ return final_pred, confidence
57
 
58
+ footer = """
59
+ <style>
60
+ a:link , a:visited{
61
+ color: white;
62
+ background-color: transparent;
63
+ text-decoration: None;
64
+ }
65
+ a:hover, a:active {
66
+ color: red;
67
+ background-color: transparent;
68
+ text-decoration: None;
69
+ }
70
+ .footer {
71
+ position: fixed;
72
+ left: 0;
73
+ bottom: 0;
74
+ width: 100%;
75
+ background-color: transparent;
76
+ color: black;
77
+ text-align: center;
78
+ }
79
+ <div class="footer">
80
+ <p align="center"> Developed with ❤ by Mato</p>
81
+ </div>
82
+ </style>
83
+ """
84
+ st.markdown(footer, unsafe_allow_html = True)
85
+ if __name__ == "__main__":
86
+ main()
87
+