File size: 1,715 Bytes
c93969c
 
 
 
 
 
 
 
 
 
6fff063
c93969c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218ef8e
 
 
c93969c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()