Spaces:
Build error
Build error
Alok Bhattarai
commited on
Commit
·
d5ed229
1
Parent(s):
f8f60c9
initial commit
Browse files- app.py +83 -0
- requirements.txt +6 -0
- training_notebook.ipynb +0 -0
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
import numpy as np
|
| 5 |
+
import cv2
|
| 6 |
+
import base64
|
| 7 |
+
|
| 8 |
+
def set_page_background(png_file):
|
| 9 |
+
@st.cache_data(show_spinner=False)
|
| 10 |
+
def get_base64_of_bin_file(bin_file):
|
| 11 |
+
with open(bin_file, 'rb') as f:
|
| 12 |
+
data = f.read()
|
| 13 |
+
return base64.b64encode(data).decode()
|
| 14 |
+
|
| 15 |
+
bin_str = get_base64_of_bin_file(png_file)
|
| 16 |
+
custom_css = f'''
|
| 17 |
+
<style>
|
| 18 |
+
.stApp {{
|
| 19 |
+
background-image: url("data:image/png;base64,{bin_str}");
|
| 20 |
+
background-size: cover;
|
| 21 |
+
background-repeat: no-repeat;
|
| 22 |
+
background-attachment: scroll;
|
| 23 |
+
}}
|
| 24 |
+
|
| 25 |
+
#MainMenu {{visibility: hidden;}}
|
| 26 |
+
footer {{visibility: hidden;}}
|
| 27 |
+
icon {{color: white;}}
|
| 28 |
+
nav-link {{--hover-color: grey; }}
|
| 29 |
+
nav-link-selected {{background-color: #4ABF7E;}}
|
| 30 |
+
</style>
|
| 31 |
+
'''
|
| 32 |
+
st.markdown(custom_css, unsafe_allow_html=True)
|
| 33 |
+
|
| 34 |
+
set_page_background("./technology-network-background-connection-cyber-space-ai-generative.jpg")
|
| 35 |
+
st.title("Stages of Alzheimer's Disease Prediction")
|
| 36 |
+
|
| 37 |
+
st.markdown("[Dataset Source](https://www.kaggle.com/datasets/tourist55/alzheimers-dataset-4-class-of-images)")
|
| 38 |
+
|
| 39 |
+
model = tf.keras.models.load_model('./model/model_1.h5')
|
| 40 |
+
model.load_weights('./model/best_model_custom_1.h5')
|
| 41 |
+
|
| 42 |
+
uploaded_file = st.file_uploader("Upload a brain MRI image here", type=["jpg", "png", "jpeg"], label_visibility="hidden")
|
| 43 |
+
predict_button = st.button("ㅤㅤPredictㅤㅤ")
|
| 44 |
+
|
| 45 |
+
if uploaded_file is not None:
|
| 46 |
+
file_bytes = BytesIO(uploaded_file.read())
|
| 47 |
+
st.image(file_bytes,use_column_width=True,clamp = True)
|
| 48 |
+
|
| 49 |
+
img = cv2.imdecode(np.frombuffer(file_bytes.read(), np.uint8), 0)
|
| 50 |
+
#img=np.array(file_bytes)
|
| 51 |
+
|
| 52 |
+
if len(img.shape) == 2:
|
| 53 |
+
img=cv2.cvtColor(img,cv2.COLOR_GRAY2RGB)
|
| 54 |
+
|
| 55 |
+
img=cv2.resize(img,(176, 176))
|
| 56 |
+
if img.max() > 1:
|
| 57 |
+
img = img / 255.0
|
| 58 |
+
|
| 59 |
+
img = np.expand_dims(img, axis=0)
|
| 60 |
+
pred=model.predict(img)
|
| 61 |
+
predict_val = np.argmax(pred, axis=1)
|
| 62 |
+
|
| 63 |
+
if predict_val == 0:
|
| 64 |
+
probability = pred[predict_val]
|
| 65 |
+
st.write(f"Mildly Demented with prediction probability of {probability}")
|
| 66 |
+
|
| 67 |
+
elif predict_val == 1:
|
| 68 |
+
probability = pred[predict_val]
|
| 69 |
+
st.write(f"Moderately Demented with prediction probability of {probability}")
|
| 70 |
+
|
| 71 |
+
elif predict_val == 2:
|
| 72 |
+
probability = pred[predict_val]
|
| 73 |
+
st.write(f"Not Demented with prediction probability of {probability}")
|
| 74 |
+
|
| 75 |
+
elif predict_val == 3:
|
| 76 |
+
probability = pred[predict_val]
|
| 77 |
+
st.write(f"Very Mildly Demented with prediction probability of {probability}")
|
| 78 |
+
|
| 79 |
+
else:
|
| 80 |
+
st.write("Error!")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==1.25.2
|
| 2 |
+
tensorflow
|
| 3 |
+
keras
|
| 4 |
+
opencv-python-headless==4.5.4.60
|
| 5 |
+
streamlit==1.26.0
|
| 6 |
+
streamlit_option_menu==0.3.6
|
training_notebook.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|