File size: 2,399 Bytes
8f59f90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import streamlit as st
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
from sklearn.metrics import classification_report

# Load the models
model1 = tf.keras.models.load_model("densenet_model.h5")
model2 = tf.keras.models.load_model("inception_model.h5")
model3 = tf.keras.models.load_model("resnet_model.h5")

# Streamlit app
st.title("Cancer Prediction App")

# Upload image through Streamlit
uploaded_file = st.file_uploader("Choose an image...", type="jpg")


if uploaded_file is not None:
    # Read and preprocess the uploaded image
    img = image.load_img(uploaded_file, target_size=(224, 224))
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array /= 255.0  # Normalize the image

    # Make a prediction with Model 1
    prediction = model1.predict(img_array)
    predicted_class = np.argmax(prediction[0])
    prediction_accuracy = prediction[0][predicted_class]

    # Display the prediction result
    st.image(img, caption="Uploaded Image", use_column_width=True)

    if prediction_accuracy < 0.5:
        st.write("Prediction (using DenseNet): Not Cancerous")
    else:
        st.write("Prediction (using DenseNet): Cancerous")

    st.write(f"Chance of Cancer (using DenseNet): {prediction_accuracy*100}%")

    # Make a prediction with Model 2
    prediction = model2.predict(img_array)
    predicted_class = np.argmax(prediction[0])
    prediction_accuracy = prediction[0][predicted_class]

    # Display the prediction result
    st.image(img, caption="Uploaded Image", use_column_width=True)

    if prediction_accuracy < 0.5:
        st.write("Prediction (using Inception V3): Not Cancerous")
    else:
        st.write("Prediction (using Inception V3): Cancerous")

    st.write(f"Chance of Cancer (using Inception V3): {prediction_accuracy*100}%")

# Make a prediction with Model 3
    prediction = model3.predict(img_array)
    predicted_class = np.argmax(prediction[0])
    prediction_accuracy = prediction[0][predicted_class]

    # Display the prediction result
    st.image(img, caption="Uploaded Image", use_column_width=True)

    if prediction_accuracy <0.5:
        st.write("Prediction (using Resnet50): Not Cancerous")
    else:
        st.write("Prediction (using Resnet50): Cancerous")

    st.write(f"Chance of Cancer (using Resnet50): {prediction_accuracy*100}%")