Update app.py
Browse files
app.py
CHANGED
|
@@ -25,14 +25,23 @@ model = tf.keras.models.load_model(
|
|
| 25 |
|
| 26 |
# 3.prediction function (predict())
|
| 27 |
|
| 28 |
-
def load_and_prep_imgg(
|
| 29 |
if not isinstance(filename, str):
|
| 30 |
raise ValueError("The filename must be a string representing the file path.")
|
| 31 |
-
img = tf.io.read_file(filename)
|
| 32 |
-
img = tf.io.decode_image(img, channels=3)
|
| 33 |
-
img = tf.image.resize(img, size=[img_shape, img_shape])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
if scale:
|
| 35 |
-
return img / 255
|
| 36 |
else:
|
| 37 |
return img
|
| 38 |
|
|
@@ -57,10 +66,9 @@ def predict(img) -> Tuple[Dict,float] :
|
|
| 57 |
|
| 58 |
### 4. Gradio app - our Gradio interface + launch command
|
| 59 |
|
| 60 |
-
title = '
|
| 61 |
-
description = 'Feature
|
| 62 |
-
article = '
|
| 63 |
-
|
| 64 |
# Create example list
|
| 65 |
|
| 66 |
example_list = [['examples/'+ example] for example in os.listdir('examples')]
|
|
|
|
| 25 |
|
| 26 |
# 3.prediction function (predict())
|
| 27 |
|
| 28 |
+
def load_and_prep_imgg(img : Image.Image, img_shape=224, scale=True):
|
| 29 |
if not isinstance(filename, str):
|
| 30 |
raise ValueError("The filename must be a string representing the file path.")
|
| 31 |
+
# img = tf.io.read_file(filename)
|
| 32 |
+
# img = tf.io.decode_image(img, channels=3)
|
| 33 |
+
# img = tf.image.resize(img, size=[img_shape, img_shape])
|
| 34 |
+
# if scale:
|
| 35 |
+
# return img / 255
|
| 36 |
+
# else:
|
| 37 |
+
# return img
|
| 38 |
+
img = img.resize((img_shape, img_shape))
|
| 39 |
+
img = np.array(img)
|
| 40 |
+
if img.shape[-1] == 1: # If the image is grayscale
|
| 41 |
+
img = np.stack([img] * 3, axis=-1)
|
| 42 |
+
img = tf.convert_to_tensor(img, dtype=tf.float32)
|
| 43 |
if scale:
|
| 44 |
+
return img / 255.0
|
| 45 |
else:
|
| 46 |
return img
|
| 47 |
|
|
|
|
| 66 |
|
| 67 |
### 4. Gradio app - our Gradio interface + launch command
|
| 68 |
|
| 69 |
+
title = 'Macular Disease Classification'
|
| 70 |
+
description = 'Feature Extraction VGG model to classify Macular Diseases by OCT'
|
| 71 |
+
article = 'Created with TensorFlow Model Deployment'
|
|
|
|
| 72 |
# Create example list
|
| 73 |
|
| 74 |
example_list = [['examples/'+ example] for example in os.listdir('examples')]
|