cybernatedArt commited on
Commit
191f9fb
1 Parent(s): 9d3cbb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -45
app.py CHANGED
@@ -1,51 +1,36 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import tensorflow as tf
3
 
4
+ path_to_model = "model_2.h5"
 
5
 
6
+ model = tf.keras.models.load_model(path_to_model)
7
 
8
+ labels = ['Acne and Rosacea Photos',
9
+ 'Actinic Keratosis Basal Cell Carcinoma and other Malignant Lesions',
10
+ 'Atopic Dermatitis Photos', 'Bullous Disease Photos',
11
+ 'Cellulitis Impetigo and other Bacterial Infections',
12
+ 'Eczema Photos', 'Exanthems and Drug Eruptions', 'Hair Loss Photos Alopecia and other Hair Diseases',
13
+ 'Herpes HPV and other STDs Photos', 'Light Diseases and Disorders of Pigmentation',
14
+ 'Lupus and other Connective Tissue diseases',
15
+ 'Melanoma Skin Cancer Nevi and Moles', 'Nail Fungus and other Nail Disease',
16
+ 'Poison Ivy Photos and other Contact Dermatitis',
17
+ 'Psoriasis pictures Lichen Planus and related diseases', 'Scabies Lyme Disease and other Infestations and Bites',
18
+ 'Seborrheic Keratoses and other Benign Tumors', 'Systemic Disease',
19
+ 'Tinea Ringworm Candidiasis and other Fungal Infections',
20
+ 'Urticaria Hives', 'Vascular Tumors', 'Vasculitis Photos', 'Warts Molluscum and other Viral Infections']
21
 
22
  def classify_image(inp):
23
+ inp = inp.reshape((-1, 256, 256, 3))
24
+ prediction = model.predict(inp).flatten()
25
+ confidences = {labels[i]: float(prediction[i]) for i in range(23)}
26
+ return confidences
27
+
28
+
29
+ gr.Interface(fn=classify_image,
30
+ inputs=gr.inputs.Image(shape=(256, 256)),
31
+ outputs=gr.outputs.Label(num_top_classes=3),
32
+ examples=["123.jpg", "distal-subungual-onychomycosis-86.jpg"]).launch()
33
+
34
+
35
+
36
+