DHEIVER commited on
Commit
101ec35
·
1 Parent(s): 13124d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -4,9 +4,14 @@ import tensorflow as tf
4
 
5
  models = [ {"name": "my_model_2.h5", "size": 512}, {"name": "my_model.h5", "size": 224},]
6
 
7
- def classify_image(image, model_name):
 
 
8
  model_config = next(m for m in models if m["name"] == model_name)
9
  model = tf.keras.models.load_model(model_name)
 
 
 
10
  input_image = np.expand_dims(image, axis=0)
11
  prediction = model.predict(input_image).flatten()
12
  if len(prediction) > 1:
@@ -21,6 +26,7 @@ def classify_image(image, model_name):
21
  label = "Not glaucoma"
22
  return label, probability
23
 
 
24
  inputs = [
25
  gr.inputs.Image(shape=(224, 224), label="Eye image"),
26
  gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
 
4
 
5
  models = [ {"name": "my_model_2.h5", "size": 512}, {"name": "my_model.h5", "size": 224},]
6
 
7
+ from PIL import Image
8
+
9
+ def classify_image(image_path, model_name):
10
  model_config = next(m for m in models if m["name"] == model_name)
11
  model = tf.keras.models.load_model(model_name)
12
+ image = Image.open(image_path).convert("RGB")
13
+ image = image.resize((model_config["size"], model_config["size"]))
14
+ image = np.array(image) / 255.0
15
  input_image = np.expand_dims(image, axis=0)
16
  prediction = model.predict(input_image).flatten()
17
  if len(prediction) > 1:
 
26
  label = "Not glaucoma"
27
  return label, probability
28
 
29
+
30
  inputs = [
31
  gr.inputs.Image(shape=(224, 224), label="Eye image"),
32
  gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),