Spaces:
Sleeping
Sleeping
import streamlit as st | |
import tensorflow as tf | |
import cv2 | |
import numpy as np | |
from PIL import Image | |
# Load the trained model | |
model = tf.keras.models.load_model('braintumor.h5') | |
# Define labels for the classes | |
labels = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor'] | |
# Define a function to make predictions | |
def predict_tumor_type(image): | |
# Preprocess the image | |
img = cv2.resize(image, (150, 150)) | |
img_array = np.array(img) | |
img_array = img_array.reshape(1, 150, 150, 3) | |
# Make prediction | |
prediction = model.predict(img_array) | |
predicted_class = labels[np.argmax(prediction)] | |
confidence = np.max(prediction) | |
return predicted_class, confidence | |
# Streamlit UI | |
st.title("Brain Tumor Classification") | |
st.write("Upload an image for brain tumor classification.") | |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
if uploaded_image is not None: | |
# Display the uploaded image | |
image = Image.open(uploaded_image) | |
st.image(image, caption="Uploaded Image", use_column_width=True) | |
# Make prediction | |
prediction, confidence = predict_tumor_type(np.array(image)) | |
st.write("Prediction:", prediction) | |
st.write(f"Confidence: {confidence * 100:.2f}%") | |
st.write("DISCLAIMER:") | |
st.write("0 - glioma_tumor") | |
st.write("1 - meningioma_tumor") | |
st.write("2 - No_tumor") | |
st.write("3 - pituitary_tumor") | |