MUmairAB's picture
Update app.py
d541852
raw
history blame
983 Bytes
#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!")
gr.Interface(fn=detect_cancer,
inputs=gr.Image(shape=(50, 50)),
outputs=gr.Label("The Test Result"),
examples=[0, 1]).launch()