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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -81
app.py CHANGED
@@ -1,87 +1,31 @@
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
-
 
1
+ import gradio as gr
2
+ from fastai import *
3
+ from fastai.vision.all import *
 
 
 
 
4
 
5
+ import pathlib
6
+ plt = platform.system()
7
+ if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
 
 
 
 
 
8
 
9
+ learn = load_learner('Pickle_SD_Model.pkl')
 
10
 
11
+ labels = learn.dls.vocab
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ set_label = gr.outputs.Textbox(label="Predicted Class")
 
 
14
 
15
+ set_prob = gr.outputs.Label(num_top_classes=4, label="Predicted Probability Per Class")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+
18
+ def predict(img):
19
+ img = PILImage.create(img)
20
+ pred,pred_idx,probs = learn.predict(img)
21
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
22
+
23
+ title = "Tomato Disease Classifier"
24
+ description = "Classify Tomato Disease from leaf"
25
+ interpretation='default'
26
+
27
+ enable_queue=True
28
+
29
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3),
30
+ examples_per_page = 2
31
+ ).launch(share=True)