SergioI1991 commited on
Commit
5343e38
verified
1 Parent(s): 256145e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
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 al inicio
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 predict(rx_image):
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 rx_image, resultado_texto
42
 
43
- # Interfaz Gradio
44
- iface = gr.Interface(
45
- fn=predict,
46
- inputs=gr.Image(type="numpy", label="Sube tu RX"),
47
- outputs=[gr.Image(type="numpy", label="RX procesada"), gr.Textbox(label="Resultado")],
48
- live=False
49
- )
 
 
 
 
 
50
 
51
- iface.launch()
 
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()