Spaces:
Sleeping
Sleeping
File size: 903 Bytes
adf2111 8d9c7cb 8d504fb 8d9c7cb 8d504fb 8d9c7cb da33e50 8d9c7cb 8d504fb 8d9c7cb 8d504fb 8d9c7cb 8d504fb 8d9c7cb |
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 32 33 |
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()
|