File size: 1,109 Bytes
6312f5a |
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 |
import streamlit as st
from PIL import Image
import numpy as np
import tensorflow as tf
def load_model():
model = tf.keras.models.load_model('cnn_tumor2.h5')
return model
model = load_model()
def preprocess_image(image):
image = image.resize((128,128))
image = np.array(image) / 255.0
image = np.expand_dims(image, axis=0)
return image
def predict_tumor(image):
predictions = model.predict(image)
if predictions[0] > 0.5:
return "Tumorous"
else:
return "Non-tumorous"
with open("styles.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.title("Tumor Detection using CNN")
uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
resized_image = image.resize((300, 200))
st.image(resized_image, caption="Uploaded Image")
processed_image = preprocess_image(image)
result = predict_tumor(processed_image)
st.info(f"Prediction: {result}")
|