Spaces:
Build error
Build error
| 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 | |
| # Load the Keras model | |
| model = load_model("/home/user/app/Tumour_Model(V19).h5") | |
| # Define the class reference dictionary | |
| ref = {0: 'Glioma', 1: 'Meningioma', 2: 'No Tumor', 3: 'Pituitary'} | |
| # Define function to preprocess the image | |
| 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 | |
| # Streamlit app | |
| def main(): | |
| st.title('Brain Tumor Classification') | |
| # Upload image | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| # Preprocess the image | |
| image = preprocess_image(uploaded_file) | |
| # Make prediction | |
| predictions = model.predict(image) | |
| predicted_class = np.argmax(predictions) | |
| predicted_class_name = ref[predicted_class] | |
| probabilities = predictions.tolist()[0] | |
| # Display prediction | |
| st.success(f"Predicted class: {predicted_class_name}") | |
| st.write("Probabilities:") | |
| for i, prob in enumerate(probabilities): | |
| st.write(f"{ref[i]}: {prob}") | |
| # Hugging Face component | |
| #st.title("Hugging Face Model") | |
| #model_name = "mrm8488/distill-bert-base-spanish-wwm-cased-finetuned-spa-squad2-es" | |
| #st.huggingface_component(model_name) | |
| if __name__ == '__main__': | |
| main() | |