DHEIVER commited on
Commit
4456acb
·
1 Parent(s): 982fa65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -17
app.py CHANGED
@@ -1,23 +1,12 @@
 
1
  import gradio as gr
2
  import tensorflow as tf
3
- import numpy as np
4
 
5
- models = [
6
- {"name": "my_model_2.h5", "size": 512},
7
- {"name": "my_model.h5", "size": 224},
8
- ]
9
- def preprocess_image(image):
10
- temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
11
- temp_file.write(image.read())
12
- temp_file.close()
13
- return temp_file.name
14
 
15
- def classify_image(image_path, model_name):
16
  model_config = next(m for m in models if m["name"] == model_name)
17
  model = tf.keras.models.load_model(model_name)
18
- image = Image.open(image_path).convert("RGB")
19
- image = image.resize((model_config["size"], model_config["size"]))
20
- image = np.array(image) / 255.0
21
  input_image = np.expand_dims(image, axis=0)
22
  prediction = model.predict(input_image).flatten()
23
  if len(prediction) > 1:
@@ -36,7 +25,6 @@ inputs = [
36
  gr.inputs.Image(shape=(224, 224), label="Eye image"),
37
  gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
38
  ]
39
-
40
  outputs = [
41
  gr.outputs.Textbox(label="Predicted label"),
42
  gr.outputs.Textbox(label="Probability of glaucoma (0-100)"),
@@ -44,7 +32,7 @@ outputs = [
44
 
45
  examples = [
46
  [np.zeros((224, 224, 3)), "my_model.h5"],
47
- [np.ones((224, 224, 3)) * 255, "my_model_2.h5"],
48
  ]
49
 
50
- gr.Interface(classify_image, inputs, outputs, examples=examples).launch()
 
1
+ import numpy as np
2
  import gradio as gr
3
  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:
 
25
  gr.inputs.Image(shape=(224, 224), label="Eye image"),
26
  gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
27
  ]
 
28
  outputs = [
29
  gr.outputs.Textbox(label="Predicted label"),
30
  gr.outputs.Textbox(label="Probability of glaucoma (0-100)"),
 
32
 
33
  examples = [
34
  [np.zeros((224, 224, 3)), "my_model.h5"],
35
+ [np.ones((224, 224, 3)) * 255, "my_model_2.h5"]
36
  ]
37
 
38
+ gr.Interface(classify_image, inputs, outputs, examples=examples, title="Glaucoma Classification").launch()