Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from tensorflow.keras.models import load_model | |
from tensorflow.keras.layers import Layer | |
# Define the custom 'FixedDropout' layer | |
class FixedDropout(Layer): | |
def __init__(self, rate, **kwargs): | |
super(FixedDropout, self).__init__(**kwargs) | |
self.rate = rate | |
def call(self, inputs, training=None): | |
if training is None: | |
training = K.learning_phase() | |
if training == 1: | |
return K.dropout(inputs, self.rate) | |
return inputs | |
# Register the custom layer in a custom object scope | |
custom_objects = {"FixedDropout": FixedDropout} | |
# Load the TensorFlow model with the custom object scope | |
tf_model_path = 'modelo_treinado.h5' # Update with the path to your model | |
tf_model = load_model(tf_model_path, custom_objects=custom_objects) | |
# Class labels for the model | |
class_labels = ["Normal", "Cataract"] | |
# Define a function for prediction | |
def predict(image): | |
# Your prediction code here... | |
# Create the Gradio interface | |
gr.Interface( | |
fn=predict, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Label(num_top_classes=2) | |
).launch() | |