#import necessary libraries import streamlit as st 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 PIL ImageFile to image 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!") def main(): st.title('Breast Cancer Detection App') st.write("Created by: [Umair Akram](https://www.linkedin.com/in/m-umair01/)") h1 = "This App uses Deep Learning to predict whether you have Breast Cancer or not!" st.subheader(h1) st.write("The model is built using Convolutional Neural Network (CNN) in TensorFlow. Its code and other interesting projects are available on my [website](https://mumairab.github.io/)") h2 = "Enter the following values to know the status of your health" st.write(h2) loaded_img = st.file_uploader(label="Upload the Histopathological Image patch of breast", type=None, accept_multiple_files=False, key="Img_upload_key", label_visibility="visible") if loaded_img is not None: # Convert the file to TensorFlow image. loaded_img = np.asarray(bytearray(loaded_img.read()), dtype=np.uint8) img = load_img(loaded_img, target_size=(50,50)) if st.button(label='Show the Test Results'): prediction = detect_cancer(img) st.success(prediction) if __name__ == '__main__': main()