import gradio as gr import tensorflow as tf import requests 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"] def predict(inp): # Use the TensorFlow model to predict Normal or Cataract img_array = cv2.cvtColor(np.array(inp), cv2.COLOR_RGB2BGR) img_array = cv2.resize(img_array, (224, 224)) img_array = img_array / 255.0 img_array = np.expand_dims(img_array, axis=0) prediction_tf = tf_model.predict(img_array) label_index = np.argmax(prediction_tf) confidence_tf = float(prediction_tf[0, label_index]) return class_labels[label_index], confidence_tf demo = gr.Interface( fn=predict, inputs=gr.inputs.Image(type="pil"), outputs=["label", "number"], ) demo.launch()