Spaces:
Build error
Build error
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| import cv2 | |
| new_model = tf.keras.models.load_model('best_model_mammography.h5') | |
| def classificar_imagem(file_name): | |
| img1 = cv2.imread(file_name.name.replace("\\", '/'), 0) | |
| img = cv2.resize(img1, (224, 224)) | |
| img = img.reshape(img.shape[0], img.shape[1], 1) | |
| pred = new_model.predict(np.array([img])) | |
| pred = np.round(pred, 1) | |
| if pred == 0: | |
| pred_label = "Benigno" | |
| else: | |
| pred_label = "Maligno" | |
| pred_score = f"{float(pred) * 100:.2f}%" | |
| return pred_label, pred_score | |
| imagem = gr.inputs.File(file_count=1, label="Imagem de mamografia") | |
| resultado_diagnostico = [gr.outputs.Textbox(label="Diagnóstico"), gr.outputs.Textbox(label="Confiança")] | |
| gr.Interface( | |
| fn=classificar_imagem, | |
| inputs=imagem, | |
| outputs=resultado_diagnostico, | |
| interpretation="default", | |
| live=True, | |
| theme="dark-peach", | |
| title="API BreastNet - Teste de diagnóstico de Câncer de Mama", | |
| description="Esta API é usada para determinar se o câncer de mama é benigno ou maligno." | |
| ).launch() | |