Spaces:
Build error
Build error
import numpy as np | |
import gradio as gr | |
import tensorflow as tf | |
models = [ {"name": "my_model_2.h5", "size": 512}, {"name": "my_model.h5", "size": 224},] | |
def classify_image(image, model_name): | |
model_config = next(m for m in models if m["name"] == model_name) | |
model = tf.keras.models.load_model(model_name) | |
input_image = np.expand_dims(image, axis=0) | |
prediction = model.predict(input_image).flatten() | |
if len(prediction) > 1: | |
probability = 100 * np.exp(prediction[0]) / (np.exp(prediction[0]) + np.exp(prediction[1])) | |
else: | |
probability = round(100. / (1 + np.exp(-prediction[0])), 2) | |
if probability > 45: | |
label = "Glaucoma" | |
elif probability > 25: | |
label = "Unclear" | |
else: | |
label = "Not glaucoma" | |
return label, probability | |
inputs = [ | |
gr.inputs.Image(shape=(224, 224), label="Eye image"), | |
gr.inputs.Dropdown(choices=[m["name"] for m in models], label="Model"), | |
] | |
outputs = [ | |
gr.outputs.Textbox(label="Predicted label"), | |
gr.outputs.Textbox(label="Probability of glaucoma (0-100)"), | |
] | |
gr.Interface(classify_image, inputs, outputs, examples=["001.jpg", "002.jpg", "225.jpg"]).launch() | |