Spaces:
Build error
Build error
| import streamlit as st | |
| import tensorflow as tf | |
| from PIL import Image | |
| import os | |
| model = tf.keras.models.load_model('Brain_tumor/') | |
| st.write('Model is loaded successfully') | |
| TEMP_DIR = 'temp' | |
| if not os.path.exists(TEMP_DIR): | |
| os.makedirs(TEMP_DIR) | |
| class_names = ['glioma', 'meningioma', 'notumor', 'pituitary'] | |
| def load_and_prep_imgg(filename, img_shape=229, scale=True): | |
| img = tf.io.read_file(filename) | |
| img = tf.io.decode_image(img) | |
| img = tf.image.resize(img, size=[img_shape, img_shape]) | |
| if scale: | |
| return img / 255 | |
| else: | |
| return img | |
| st.title('Brain Tumor Classification Prediction using Xception ImageNet') | |
| uploaded_file = st.sidebar.file_uploader('Upload your Image', type=['jpg']) | |
| if uploaded_file: | |
| file_path = os.path.join(TEMP_DIR, uploaded_file.name) | |
| # Save the uploaded file to the temporary directory | |
| with open(file_path, "wb") as f: | |
| f.write(uploaded_file.getbuffer()) | |
| img = load_and_prep_imgg(file_path, scale=True) | |
| imgg = Image.open(file_path) | |
| st.image(imgg, caption="Uploaded Image") | |
| pred_img = model.predict(tf.expand_dims(img, axis=0)) | |
| pred_class = class_names[pred_img.argmax()] | |
| st.write(f"Predicted brain tumor is: {pred_class} with probability: {pred_img.max():.2f}") | |