AlvinSiang commited on
Commit
f45ecb2
·
verified ·
1 Parent(s): 97b187b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -1,5 +1,11 @@
1
  import gradio as gr
2
  from PIL import Image
 
 
 
 
 
 
3
 
4
  js = """
5
  function createGradioAnimation() {
@@ -48,15 +54,15 @@ with gr.Blocks(js=js,theme=gr.themes.Soft()) as demo:
48
  '''
49
  )
50
 
51
- from keras.models import load_model
52
- import tensorflow as tf
53
-
54
  class_names = ['cataracts', 'diabetic retinopathy', 'glaucoma', 'normal']
 
55
 
56
  def predict_input_image(img):
 
57
  img = img.reshape((-1, 224, 224, 3))
58
- img = tf.keras.applications.densenet121.preprocess_input(img)
59
-
60
  #image_tensor = tf.convert_to_tensor(img)
61
  # Resize the image to 224x224.
62
  #image_tensor = tf.image.resize(image_tensor, (224, 224))
@@ -67,8 +73,8 @@ with gr.Blocks(js=js,theme=gr.themes.Soft()) as demo:
67
  # Normalize the data.
68
  #image_tensor = image_tensor / 255.0
69
 
70
- model = load_model('densenet121_model.keras')
71
- prediction = model.predict(img)[0]
72
 
73
  predicted_class = {class_names[i]: float(prediction[i]) for i in range(4)}
74
  return predicted_class
 
1
  import gradio as gr
2
  from PIL import Image
3
+ import gradio as gr
4
+ from gradio import components
5
+ import tensorflow as tf
6
+ from keras.models import load_model
7
+ import numpy as np
8
+ import cv2
9
 
10
  js = """
11
  function createGradioAnimation() {
 
54
  '''
55
  )
56
 
57
+
 
 
58
  class_names = ['cataracts', 'diabetic retinopathy', 'glaucoma', 'normal']
59
+ model = load_model('densenet121_model.keras')
60
 
61
  def predict_input_image(img):
62
+ img = cv2.resize(img, (224, 224))
63
  img = img.reshape((-1, 224, 224, 3))
64
+ img = tf.keras.applications.densenet.preprocess_input(img)
65
+
66
  #image_tensor = tf.convert_to_tensor(img)
67
  # Resize the image to 224x224.
68
  #image_tensor = tf.image.resize(image_tensor, (224, 224))
 
73
  # Normalize the data.
74
  #image_tensor = image_tensor / 255.0
75
 
76
+
77
+ prediction = model.predict(img).flatten()
78
 
79
  predicted_class = {class_names[i]: float(prediction[i]) for i in range(4)}
80
  return predicted_class