AlvinSiang commited on
Commit
8cbcb31
·
verified ·
1 Parent(s): 0260630

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def predict_input_image(img):
2
+ image_tensor = tf.convert_to_tensor(img)
3
+ # Resize the image to 28x28.
4
+ image_tensor = tf.image.resize(image_tensor, (224, 224))
5
+ # Cast the data to float32.
6
+ image_tensor = tf.cast(image_tensor, tf.float32)
7
+ # Add a batch dimension.
8
+ image_tensor = tf.expand_dims(image_tensor, 0)
9
+ # Normalize the data.
10
+ image_tensor = image_tensor / 255.0
11
+
12
+ from keras.models import load_model
13
+ model = load_model('vgg16_model.h5')
14
+
15
+ prediction = model.predict(image_tensor)[0]
16
+
17
+ return {class_names[i]: float(prediction[i]) for i in range(4)}
18
+
19
+ import gradio as gr
20
+
21
+ demo = gr.Interface(fn = predict_input_image,
22
+ inputs = gr.Image(width = 224, height = 224),
23
+ outputs = gr.Label(num_top_classes = 4),
24
+ title = 'A Eye: Eye Disease Classifier',
25
+ description = 'This classifier is developed to classify cataracts, diabetic retinopathy, glaucoma and normal eyes through fundus images',
26
+ cache_examples = False,
27
+ allow_flagging = 'never',
28
+ )
29
+
30
+ demo.launch(debug='True')