Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
-
import
|
| 4 |
-
import cv2
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
return tf.keras.layers.Dropout(0.5)(x)
|
| 10 |
-
|
| 11 |
-
# Load the TensorFlow model while registering the custom layer
|
| 12 |
-
custom_objects = {'fixed_dropout': fixed_dropout}
|
| 13 |
-
tf_model_path = 'modelo_treinado.h5' # Update with the path to your TensorFlow model
|
| 14 |
-
tf_model = tf.keras.models.load_model(tf_model_path, custom_objects=custom_objects)
|
| 15 |
|
|
|
|
| 16 |
class_labels = ["Normal", "Cataract"]
|
| 17 |
|
|
|
|
| 18 |
def predict(inp):
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import tensorflow as tf
|
| 3 |
+
from PIL import Image
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
+
# Carregar o modelo TensorFlow
|
| 7 |
+
model = tf.keras.models.load_model('modelo_treinado.h5')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Definir as classes
|
| 10 |
class_labels = ["Normal", "Cataract"]
|
| 11 |
|
| 12 |
+
# Função de previsão
|
| 13 |
def predict(inp):
|
| 14 |
+
# Pré-processamento da imagem para adequá-la ao modelo TensorFlow
|
| 15 |
+
img = np.array(inp)
|
| 16 |
+
img = tf.image.resize(img, (224, 224))
|
| 17 |
+
img = img / 255.0 # Normalização, se necessário
|
| 18 |
+
img = tf.expand_dims(img, axis=0)
|
| 19 |
+
|
| 20 |
+
# Fazer previsão com o modelo TensorFlow
|
| 21 |
+
predictions = model.predict(img)
|
| 22 |
+
|
| 23 |
+
# Obter a classe com a maior probabilidade
|
| 24 |
+
predicted_class = class_labels[np.argmax(predictions)]
|
| 25 |
+
|
| 26 |
+
return {predicted_class: float(predictions[0, np.argmax(predictions)])}
|
| 27 |
+
|
| 28 |
+
# Criar a interface Gradio
|
| 29 |
+
demo = gr.Interface(fn=predict,
|
| 30 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 31 |
+
outputs=gr.outputs.Label(),
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
demo.launch()
|