breast-cancer / app.py
asdhell096's picture
Update app.py
ebaa0c4
import gradio as gr
import tensorflow as tf
import numpy as np
# Cargar modelo
model = tf.keras.models.load_model('./model.h5')
model.load_weights('./pesos.h5')
# Funci贸n de predicci贸n
def predict(img):
img = np.resize(img, (50, 50, 3))
img = img / 255.0 # Normalizar la imagen
img = img.reshape((1, 50, 50, 3))
prediction = model.predict(img)[0]
# Crear resultados HTML
idc_prob = prediction[1] * 100
no_idc_prob = prediction[0] * 100
results_html = f"""
<h3>Resultados de la Predicci贸n</h3>
<p>No IDC (No hay carcinoma ductal invasivo): {no_idc_prob:.2f}%</p>
<div style='background-color: lightgrey; border-radius: 5px;'>
<div style='height: 30px; width: {no_idc_prob}%; background-color: green; border-radius: 5px;'></div>
</div>
<p>IDC (Carcinoma ductal invasivo presente): {idc_prob:.2f}%</p>
<div style='background-color: lightgrey; border-radius: 5px;'>
<div style='height: 30px; width: {idc_prob}%; background-color: red; border-radius: 5px;'></div>
</div>
"""
return results_html
# Crear interfaz Gradio con descripci贸n
interface = gr.Interface(
fn=predict,
inputs=gr.Image(),
outputs=gr.HTML(),
live=True,
description="""
<h2>Detecci贸n de IDC (Carcinoma Ductal Invasivo)</h2>
<p>El IDC es el tipo m谩s com煤n de c谩ncer de mama, caracterizado por la invasi贸n de c茅lulas cancerosas
m谩s all谩 de los conductos mamarios hacia el tejido circundante. Utiliza esta herramienta para obtener una
predicci贸n r谩pida basada en la imagen proporcionada. Los resultados son aproximados y siempre es recomendable
consultar a un especialista para un diagn贸stico preciso.</p>
"""
)
interface.launch()