Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from tensorflow.keras.models import load_model | |
from PIL import Image | |
import numpy as np | |
# Load the TensorFlow model | |
tf_model_path = 'modelo_treinado.h5' # Update with the path to your TensorFlow model | |
tf_model = load_model(tf_model_path) | |
# Class labels for the model | |
class_labels = ["Normal", "Cataract"] | |
# Define a function for prediction | |
def predict(image): | |
# Preprocess the input image (resize and normalize) | |
image = image.resize((224, 224)) # Adjust the size as needed | |
image = np.array(image) / 255.0 # Normalize pixel values | |
image = np.expand_dims(image, axis=0) # Add batch dimension | |
# Make a prediction using the loaded TensorFlow model | |
predictions = tf_model.predict(image) | |
# Get the predicted class label | |
predicted_label = class_labels[np.argmax(predictions)] | |
return predicted_label | |
# Create the Gradio interface | |
gr.Interface( | |
fn=predict, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Label(num_top_classes=2), | |
).launch() | |