|
import os |
|
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' |
|
import streamlit as st |
|
from keras.models import load_model |
|
from keras.preprocessing.image import load_img, img_to_array |
|
from keras.applications.vgg19 import preprocess_input |
|
import numpy as np |
|
from transformers import pipeline |
|
|
|
|
|
model = load_model("/home/user/app/Tumour_Model(V19).h5") |
|
|
|
|
|
ref = {0: 'Glioma', 1: 'Meningioma', 2: 'No Tumor', 3: 'Pituitary'} |
|
|
|
|
|
def preprocess_image(image_path): |
|
img = load_img(image_path, target_size=(256, 256)) |
|
img_array = img_to_array(img) |
|
img_array = preprocess_input(img_array) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
return img_array |
|
|
|
|
|
def main(): |
|
st.title('Brain Tumor Classification') |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
image = preprocess_image(uploaded_file) |
|
|
|
|
|
predictions = model.predict(image) |
|
predicted_class = np.argmax(predictions) |
|
predicted_class_name = ref[predicted_class] |
|
probabilities = predictions.tolist()[0] |
|
|
|
|
|
st.success(f"Predicted class: {predicted_class_name}") |
|
st.write("Probabilities:") |
|
for i, prob in enumerate(probabilities): |
|
st.write(f"{ref[i]}: {prob}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|