jayasuriyaK
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
3 |
+
import streamlit as st
|
4 |
+
from keras.models import load_model
|
5 |
+
from keras.preprocessing.image import load_img, img_to_array
|
6 |
+
from keras.applications.vgg19 import preprocess_input
|
7 |
+
import numpy as np
|
8 |
+
from transformers import pipeline
|
9 |
+
|
10 |
+
# Load the Keras model
|
11 |
+
model = load_model("Tumour_model(V19).h5")
|
12 |
+
|
13 |
+
# Define the class reference dictionary
|
14 |
+
ref = {0: 'Glioma', 1: 'Meningioma', 2: 'No Tumor', 3: 'Pituitary'}
|
15 |
+
|
16 |
+
# Define function to preprocess the image
|
17 |
+
def preprocess_image(image_path):
|
18 |
+
img = load_img(image_path, target_size=(256, 256))
|
19 |
+
img_array = img_to_array(img)
|
20 |
+
img_array = preprocess_input(img_array)
|
21 |
+
img_array = np.expand_dims(img_array, axis=0)
|
22 |
+
return img_array
|
23 |
+
|
24 |
+
# Streamlit app
|
25 |
+
def main():
|
26 |
+
st.title('Brain Tumor Classification')
|
27 |
+
|
28 |
+
# Upload image
|
29 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
# Preprocess the image
|
33 |
+
image = preprocess_image(uploaded_file)
|
34 |
+
|
35 |
+
# Make prediction
|
36 |
+
predictions = model.predict(image)
|
37 |
+
predicted_class = np.argmax(predictions)
|
38 |
+
predicted_class_name = ref[predicted_class]
|
39 |
+
probabilities = predictions.tolist()[0]
|
40 |
+
|
41 |
+
# Display prediction
|
42 |
+
st.success(f"Predicted class: {predicted_class_name}")
|
43 |
+
st.write("Probabilities:")
|
44 |
+
for i, prob in enumerate(probabilities):
|
45 |
+
st.write(f"{ref[i]}: {prob}")
|
46 |
+
|
47 |
+
# Hugging Face component
|
48 |
+
st.title("Hugging Face Model")
|
49 |
+
model_name = "mrm8488/distill-bert-base-spanish-wwm-cased-finetuned-spa-squad2-es"
|
50 |
+
st.huggingface_component(model_name)
|
51 |
+
|
52 |
+
if __name__ == '__main__':
|
53 |
+
main()
|