Update app.py
Browse files
app.py
CHANGED
|
@@ -6,17 +6,16 @@ IMG_SIZE = (224, 224)
|
|
| 6 |
MODEL_PATH = "dental_classifier_model.keras"
|
| 7 |
CLASS_NAMES = ['no_valido', 'valido']
|
| 8 |
|
| 9 |
-
# Cargar modelo una vez
|
| 10 |
model = tf.keras.models.load_model(MODEL_PATH)
|
| 11 |
|
| 12 |
def preprocess_image(img):
|
| 13 |
-
# Redimensionar y normalizar la imagen
|
| 14 |
img = tf.image.resize(img, IMG_SIZE)
|
| 15 |
img_array = tf.expand_dims(img, 0)
|
| 16 |
img_array = img_array / 255.0
|
| 17 |
return img_array
|
| 18 |
|
| 19 |
-
def
|
| 20 |
img_array = preprocess_image(rx_image)
|
| 21 |
preds = model.predict(img_array)
|
| 22 |
score = tf.nn.softmax(preds[0])
|
|
@@ -29,7 +28,6 @@ def predict(rx_image):
|
|
| 29 |
other_class = CLASS_NAMES[other_index]
|
| 30 |
other_confidence = score[other_index] * 100
|
| 31 |
|
| 32 |
-
# Crear texto de salida detallado
|
| 33 |
resultado_texto = (
|
| 34 |
f"--- Resultado de la Clasificaci贸n ---\n"
|
| 35 |
f"La imagen es: **{predicted_class.upper()}**\n"
|
|
@@ -38,14 +36,19 @@ def predict(rx_image):
|
|
| 38 |
f"------------------------------------"
|
| 39 |
)
|
| 40 |
|
| 41 |
-
return
|
| 42 |
|
| 43 |
-
# Interfaz
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
| 6 |
MODEL_PATH = "dental_classifier_model.keras"
|
| 7 |
CLASS_NAMES = ['no_valido', 'valido']
|
| 8 |
|
| 9 |
+
# Cargar modelo una vez
|
| 10 |
model = tf.keras.models.load_model(MODEL_PATH)
|
| 11 |
|
| 12 |
def preprocess_image(img):
|
|
|
|
| 13 |
img = tf.image.resize(img, IMG_SIZE)
|
| 14 |
img_array = tf.expand_dims(img, 0)
|
| 15 |
img_array = img_array / 255.0
|
| 16 |
return img_array
|
| 17 |
|
| 18 |
+
def predecir(rx_image):
|
| 19 |
img_array = preprocess_image(rx_image)
|
| 20 |
preds = model.predict(img_array)
|
| 21 |
score = tf.nn.softmax(preds[0])
|
|
|
|
| 28 |
other_class = CLASS_NAMES[other_index]
|
| 29 |
other_confidence = score[other_index] * 100
|
| 30 |
|
|
|
|
| 31 |
resultado_texto = (
|
| 32 |
f"--- Resultado de la Clasificaci贸n ---\n"
|
| 33 |
f"La imagen es: **{predicted_class.upper()}**\n"
|
|
|
|
| 36 |
f"------------------------------------"
|
| 37 |
)
|
| 38 |
|
| 39 |
+
return resultado_texto
|
| 40 |
|
| 41 |
+
# Interfaz est茅tica usando Blocks
|
| 42 |
+
with gr.Blocks(theme="default") as demo:
|
| 43 |
+
gr.Markdown("## Clasificador de Radiograf铆as Dentales 馃Ψ")
|
| 44 |
+
|
| 45 |
+
with gr.Row():
|
| 46 |
+
with gr.Column():
|
| 47 |
+
rx_input = gr.Image(type="numpy", label="Sube tu RX")
|
| 48 |
+
boton = gr.Button("Analizar")
|
| 49 |
+
with gr.Column():
|
| 50 |
+
resultado = gr.Textbox(label="Resultado", interactive=False)
|
| 51 |
+
|
| 52 |
+
boton.click(fn=predecir, inputs=rx_input, outputs=resultado)
|
| 53 |
|
| 54 |
+
demo.launch()
|