Spaces:
Runtime error
Runtime error
File size: 1,361 Bytes
9821f8b 4e8c9b0 9821f8b aed0572 9821f8b 4e8c9b0 9821f8b b0e3127 4e8c9b0 c29c4af aed0572 c29c4af 55af2c8 ba3419a c29c4af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#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() |