Spaces:
Build error
Build error
| import streamlit as st | |
| from PIL import Image | |
| import numpy as np | |
| import tensorflow as tf | |
| # Load the pre-trained model | |
| model_path = 'cnn_tumor.h5' | |
| model = tf.keras.models.load_model(model_path) | |
| def make_prediction(img, model): | |
| img = img.resize((128, 128)) | |
| img = np.array(img) / 255.0 # Normalize the image | |
| input_img = np.expand_dims(img, axis=0) | |
| res = model.predict(input_img) | |
| return res | |
| # Function to load the CSS file and apply it | |
| def local_css(file_name): | |
| with open(file_name) as f: | |
| st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) | |
| # Set page config | |
| st.set_page_config(page_title='Tumor Detection App', layout='centered') | |
| # Load the custom CSS file | |
| local_css("style.css") | |
| # Add a title with emojis inside the glass div | |
| st.markdown(""" | |
| <div class="glass"> | |
| <h1>Tumor Detection App ๐ง ๐</h1> | |
| <p>Upload a brain scan image to detect the presence of a tumor.</p> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| st.sidebar.header('Upload Your Image') | |
| uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| # Load the image | |
| image = Image.open(uploaded_file) | |
| # Center the uploaded image using Streamlit's columns | |
| col1, col2, col3 = st.columns([1, 2, 1]) | |
| with col2: | |
| st.image(image, caption='Uploaded Image', use_column_width=True) | |
| # Make a prediction | |
| with st.spinner('Making prediction...'): | |
| result = make_prediction(image, model) | |
| # Display the result with a glass effect | |
| result_message = "Tumor Detected" if result > 0.5 else "No Tumor Detected" | |
| st.markdown(f""" | |
| <div class="glass"> | |
| <h2>{result_message}</h2> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| else: | |
| st.markdown("<p></p>", unsafe_allow_html=True) | |