saifsunny/Prostate_Cancer_Detection_using_Deep_Learning_Models
0
1import streamlit as st2import tensorflow as tf3from tensorflow.keras.preprocessing import image4import numpy as np5from sklearn.metrics import classification_report6 7# Load the models8model1 = tf.keras.models.load_model("densenet_model.h5")9model2 = tf.keras.models.load_model("inception_model.h5")10model3 = tf.keras.models.load_model("resnet_model.h5")11 12# Streamlit app13st.title("Cancer Prediction App")14 15# Upload image through Streamlit16uploaded_file = st.file_uploader("Choose an image...", type="jpg")17 18 19if uploaded_file is not None:20 # Read and preprocess the uploaded image21 img = image.load_img(uploaded_file, target_size=(224, 224))22 img_array = image.img_to_array(img)23 img_array = np.expand_dims(img_array, axis=0)24 img_array /= 255.0 # Normalize the image25 26 # Make a prediction with Model 127 prediction = model1.predict(img_array)28 predicted_class = np.argmax(prediction[0])29 prediction_accuracy = prediction[0][predicted_class]30 31 # Display the prediction result32 st.image(img, caption="Uploaded Image", use_column_width=True)33 34 if prediction_accuracy < 0.5:35 st.write("Prediction (using DenseNet): Not Cancerous")36 else:37 st.write("Prediction (using DenseNet): Cancerous")38 39 st.write(f"Chance of Cancer (using DenseNet): {prediction_accuracy*100}%")40 41 # Make a prediction with Model 242 prediction = model2.predict(img_array)43 predicted_class = np.argmax(prediction[0])44 prediction_accuracy = prediction[0][predicted_class]45 46 # Display the prediction result47 st.image(img, caption="Uploaded Image", use_column_width=True)48 49 if prediction_accuracy < 0.5:50 st.write("Prediction (using Inception V3): Not Cancerous")51 else:52 st.write("Prediction (using Inception V3): Cancerous")53 54 st.write(f"Chance of Cancer (using Inception V3): {prediction_accuracy*100}%")55 56# Make a prediction with Model 357 prediction = model3.predict(img_array)58 predicted_class = np.argmax(prediction[0])59 prediction_accuracy = prediction[0][predicted_class]60 61 # Display the prediction result62 st.image(img, caption="Uploaded Image", use_column_width=True)63 64 if prediction_accuracy <0.5:65 st.write("Prediction (using Resnet50): Not Cancerous")66 else:67 st.write("Prediction (using Resnet50): Cancerous")68 69 st.write(f"Chance of Cancer (using Resnet50): {prediction_accuracy*100}%")70 71 