Spaces:
Sleeping
Sleeping
File size: 980 Bytes
adf2111 2133a73 8d504fb 8d9c7cb 2133a73 da33e50 2133a73 da33e50 2133a73 8d9c7cb 2133a73 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 34 35 |
import gradio as gr
import tensorflow as tf
from PIL import Image
import numpy as np
# Carregar o modelo TensorFlow
model = tf.keras.models.load_model('modelo_treinado.h5')
# Definir as classes
class_labels = ["Normal", "Cataract"]
# Função de previsão
def predict(inp):
# Pré-processamento da imagem para adequá-la ao modelo TensorFlow
img = np.array(inp)
img = tf.image.resize(img, (224, 224))
img = img / 255.0 # Normalização, se necessário
img = tf.expand_dims(img, axis=0)
# Fazer previsão com o modelo TensorFlow
predictions = model.predict(img)
# Obter a classe com a maior probabilidade
predicted_class = class_labels[np.argmax(predictions)]
return {predicted_class: float(predictions[0, np.argmax(predictions)])}
# Criar a interface Gradio
demo = gr.Interface(fn=predict,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.outputs.Label(),
)
demo.launch()
|