Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 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 |
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)
|
|
@@ -26,19 +27,19 @@ def classify_image(image_path, model_name):
|
|
| 26 |
label = "Not glaucoma"
|
| 27 |
return label, probability
|
| 28 |
|
| 29 |
-
|
| 30 |
inputs = [
|
| 31 |
-
gr.inputs.Image(
|
| 32 |
gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
|
| 33 |
]
|
|
|
|
| 34 |
outputs = [
|
| 35 |
gr.outputs.Textbox(label="Predicted label"),
|
| 36 |
gr.outputs.Textbox(label="Probability of glaucoma (0-100)"),
|
| 37 |
]
|
| 38 |
|
| 39 |
examples = [
|
| 40 |
-
[
|
| 41 |
-
[
|
| 42 |
]
|
| 43 |
|
| 44 |
gr.Interface(classify_image, inputs, outputs, examples=examples).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image
|
| 2 |
+
import tempfile
|
| 3 |
+
|
| 4 |
+
def preprocess_image(image):
|
| 5 |
+
temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
|
| 6 |
+
temp_file.write(image.read())
|
| 7 |
+
temp_file.close()
|
| 8 |
+
return temp_file.name
|
| 9 |
|
| 10 |
def classify_image(image_path, model_name):
|
| 11 |
model_config = next(m for m in models if m["name"] == model_name)
|
|
|
|
| 27 |
label = "Not glaucoma"
|
| 28 |
return label, probability
|
| 29 |
|
|
|
|
| 30 |
inputs = [
|
| 31 |
+
gr.inputs.Image(label="Eye image"),
|
| 32 |
gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"),
|
| 33 |
]
|
| 34 |
+
|
| 35 |
outputs = [
|
| 36 |
gr.outputs.Textbox(label="Predicted label"),
|
| 37 |
gr.outputs.Textbox(label="Probability of glaucoma (0-100)"),
|
| 38 |
]
|
| 39 |
|
| 40 |
examples = [
|
| 41 |
+
[preprocess_image(open("example_image.jpg", "rb")), "my_model.h5"],
|
| 42 |
+
[preprocess_image(open("example_image_2.jpg", "rb")), "my_model_2.h5"]
|
| 43 |
]
|
| 44 |
|
| 45 |
gr.Interface(classify_image, inputs, outputs, examples=examples).launch()
|