Spaces:
Runtime error
Runtime error
cybernatedArt
commited on
Commit
·
199a42a
1
Parent(s):
511476f
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,51 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import tensorflow as tf
|
3 |
-
import numpy as np
|
4 |
import requests
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
image = image.reshape(-1, 256, 256, 3)
|
13 |
-
prediction = model.predict(image).flatten()
|
14 |
-
#return {class_names[i]: float(prediction[i]) for i in range(4)}
|
15 |
-
class_names = ['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']
|
16 |
-
return {class_names[i]: float(prediction[i]) for i in range(23)}
|
17 |
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
# initializing the output component
|
22 |
-
label = gr.outputs.Label(num_top_classes = 4)
|
23 |
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
import tensorflow as tf
|
3 |
+
from tensorflow import keras
|
4 |
+
from keras.models import Sequential, load_model
|
5 |
+
from tensorflow.keras.models import Sequential
|
6 |
+
from tensorflow.keras.layers import Activation, Dense, BatchNormalization, Conv2D, MaxPool2D, Dropout, Flatten
|
7 |
+
from tensorflow.keras.optimizers import Adam
|
8 |
+
from tensorflow.keras.metrics import categorical_crossentropy
|
9 |
+
from tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, array_to_img, img_to_array
|
10 |
+
from tensorflow.keras import datasets, layers, models
|
11 |
+
|
12 |
+
import pandas as pd
|
13 |
+
import numpy as np
|
14 |
+
|
15 |
+
import gradio as gr
|
16 |
+
|
17 |
+
load_file = 'model_2.h5'
|
18 |
+
model=load_model(load_file)
|
19 |
+
|
20 |
|
21 |
+
img_resize = keras.Sequential(
|
22 |
+
[
|
23 |
+
layers.experimental.preprocessing.Resizing(256, 256, interpolation='bilinear')
|
24 |
+
]
|
25 |
+
)
|
26 |
|
27 |
+
def classify_image(inp):
|
28 |
+
inp = img_resize(inp)
|
29 |
+
img_array = keras.preprocessing.image.img_to_array(inp)
|
30 |
+
img_array = tf.expand_dims(img_array, 0)
|
31 |
|
32 |
+
prediction = model.predict(img_array).flatten()
|
33 |
+
return {'Probability of Diabetic Retinopathy:': float(np.exp(prediction)/(1+np.exp(prediction)))} #{labels[i]: float(prediction[i]) for i in range(1)}
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
content_image_input = gr.inputs.Image(label="Content Image")
|
36 |
+
style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")
|
37 |
|
38 |
+
image = gr.inputs.Image(label = 'Image')
|
39 |
+
label = gr.outputs.Label(num_top_classes=3)
|
|
|
|
|
40 |
|
41 |
+
explanation = 'The first two sample images both have DR and the model confidently predicts it correctly. The next two images are examples without DR that the model confidently predicts correctly. The 5th image has DR, but the model guesses incorrectly. The 6th image does not have DR, but the model guesses incorrectly.'
|
42 |
|
43 |
+
gr.Interface(
|
44 |
+
fn=classify_image,
|
45 |
+
inputs= image,
|
46 |
+
title = 'Prediction of Diabetic Retinopathy (DR)',
|
47 |
+
description = 'Demo for predicting the probability of having Diabetic Retinopathy. This version is currently using a DenseNet Model.',
|
48 |
+
article = explanation,
|
49 |
+
outputs=label,
|
50 |
+
theme = "peach"
|
51 |
+
).launch()
|