Spaces:
Runtime error
Runtime error
#import necessary libraries | |
import gradio as gr | |
import tensorflow as tf | |
from tensorflow.keras.preprocessing.image import load_img, img_to_array | |
from huggingface_hub import from_pretrained_keras | |
import numpy as np | |
def detect_cancer(img): | |
#Load the model | |
model = from_pretrained_keras('MUmairAB/Breast_Cancer_Detector') | |
#Convert the NumPy image to tensor | |
img = tf.convert_to_tensor(img) | |
#Convert the single images to batch image | |
img = tf.expand_dims(img, axis=0) | |
#Make predictions | |
pred = model.predict(img) | |
#Convert the "numpy.ndarray" object to a simple numebr | |
prediction = round(float(pred)) | |
if prediction == 0: | |
return("Congratulation! you don't have breast cancer") | |
else: | |
return("Unfortunately! you have breast cancer. Kindly consult a doctor!") | |
#Define Gradio input components for reading image | |
input_img = gr.Image(shape=(50, 50)) | |
#Define Gradio output component | |
output = 'text' | |
#Create a Gradio user interface | |
interfac = gr.Interface(title="Breast Cancer Diagnosis\n(by Umair Akram)", | |
description="Enter the Histopathological image of the breast to predict the diagnosis.", | |
fn=detect_cancer, | |
inputs=input_img, | |
outputs=output) | |
#Define the main function | |
if __name__ == "__main__": | |
#Launch the Gradio interface | |
interfac.launch() |