Spaces:
Sleeping
Sleeping
File size: 1,135 Bytes
adf2111 1a65837 8d504fb 8d9c7cb 6a96309 da33e50 2d907f6 1a65837 2d907f6 1a65837 2d907f6 1a65837 2d907f6 1a65837 2d907f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
import tensorflow as tf
import cv2
import numpy as np
# Load the TensorFlow model
tf_model_path = 'modelo_treinado.h5' # Update with the path to your TensorFlow model
tf_model = tf.keras.models.load_model(tf_model_path)
class_labels = ["Normal", "Cataract"]
# Define a Gradio interface
def classify_image(input_image):
# Preprocess the input image
input_image = cv2.resize(input_image, (224, 224)) # Resize the image to match the model's input size
input_image = np.expand_dims(input_image, axis=0) # Add batch dimension
input_image = input_image / 255.0 # Normalize pixel values (assuming input range [0, 255])
# Make predictions using the loaded model
predictions = tf_model.predict(input_image)
class_index = np.argmax(predictions, axis=1)[0]
predicted_class = class_labels[class_index]
return predicted_class
# Create a Gradio interface
input_image = gr.inputs.Image(shape=(224, 224, 3)) # Define the input image shape
output_label = gr.outputs.Label() # Define the output label
gr.Interface(fn=classify_image, inputs=input_image, outputs=output_label).launch()
|