Spaces:
Runtime error
Runtime error
MOHIT572000
commited on
Commit
•
5aa05a0
1
Parent(s):
0cee654
adding app.py
Browse files- .streamlit/config.toml +18 -0
- app.py +220 -0
- ensemble_model.h5 +3 -0
- requirement.txt +3 -0
- style/styles.css +33 -0
.streamlit/config.toml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
|
3 |
+
# Primary accent for interactive elements
|
4 |
+
primaryColor = '#E694FF'
|
5 |
+
|
6 |
+
# Background color for the main content area
|
7 |
+
backgroundColor = '#00172B'
|
8 |
+
|
9 |
+
# Background color for sidebar and most interactive widgets
|
10 |
+
secondaryBackgroundColor = '#0083B8'
|
11 |
+
|
12 |
+
# Color used for almost all text
|
13 |
+
textColor = '#FFFFFF'
|
14 |
+
|
15 |
+
# Font family for all text in the app, except code blocks
|
16 |
+
# Accepted values (serif | sans serif | monospace)
|
17 |
+
# Default: "sans serif"
|
18 |
+
font = "sans serif"
|
app.py
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from tensorflow.keras.models import load_model
|
2 |
+
import streamlit as st
|
3 |
+
import requests
|
4 |
+
from streamlit_lottie import st_lottie
|
5 |
+
import cv2
|
6 |
+
import numpy as np
|
7 |
+
from PIL import Image
|
8 |
+
# Load the ensemble model using tf.keras.models.load_model()
|
9 |
+
loaded_ensemble_model = load_model('ensemble_model.h5')
|
10 |
+
|
11 |
+
# st.markdown('<h1 style="color:red;">Ensemble Image classification model for Alzheimer</h1>', unsafe_allow_html=True)
|
12 |
+
# st.markdown('<h2 style="color:gray;">The image classification model classifies brain scan image into following categories:</h2>', unsafe_allow_html=True)
|
13 |
+
# st.markdown('<h3 style="color:gray;"> Moderate,Mild,Very Mild, NonDemented</h3>', unsafe_allow_html=True)
|
14 |
+
|
15 |
+
## Find more emojis here: https://www.webfx.com/tools/emoji-cheat-sheet/
|
16 |
+
# st.set_page_config(page_title="My Webpage", page_icon=":tada:", layout="wide")
|
17 |
+
|
18 |
+
|
19 |
+
def load_lottieurl(url):
|
20 |
+
r = requests.get(url)
|
21 |
+
if r.status_code != 200:
|
22 |
+
return None
|
23 |
+
return r.json()
|
24 |
+
|
25 |
+
|
26 |
+
# Use local CSS
|
27 |
+
def local_css(file_name):
|
28 |
+
with open(file_name) as f:
|
29 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
30 |
+
|
31 |
+
|
32 |
+
local_css("style/styles.css")
|
33 |
+
|
34 |
+
# ---- LOAD ASSETS ----
|
35 |
+
lottie_coding = load_lottieurl("https://lottie.host/6b8742e7-e4f5-4403-8bc0-1d5c2fae6e55/ah80z8X1Hu.json")
|
36 |
+
img_contact_form = Image.open("images/yt_contact_form.png")
|
37 |
+
img_lottie_animation = Image.open("images/yt_lottie_animation.png")
|
38 |
+
|
39 |
+
# ---- HEADER SECTION ----
|
40 |
+
with st.container():
|
41 |
+
st.subheader("Hi, Good Morning! :wave:")
|
42 |
+
st.title("Welcomme To Alzheimer Disease Detection Web App")
|
43 |
+
st.write(
|
44 |
+
"Alzheimer's disease is a progressive brain disorder that causes memory loss, cognitive decline, and changes in behavior."
|
45 |
+
)
|
46 |
+
st.write("[Learn More >](https://en.wikipedia.org/wiki/Alzheimer%27s_disease)")
|
47 |
+
|
48 |
+
# ---- WHAT I DO ----
|
49 |
+
with st.container():
|
50 |
+
st.write("---")
|
51 |
+
left_column, right_column = st.columns(2)
|
52 |
+
with left_column:
|
53 |
+
st.header("Description:")
|
54 |
+
st.write("##")
|
55 |
+
st.write(
|
56 |
+
"""
|
57 |
+
We have devided the alzheimers disease into four stages namely:
|
58 |
+
- Non-Demented: Individuals with no signs of dementia.
|
59 |
+
- Mild Demented: Individuals with mild cognitive impairment.
|
60 |
+
- Moderate Demented: Individuals with moderate cognitive impairment.
|
61 |
+
- Very Mild Demented: Individuals with very mild cognitive impairment."
|
62 |
+
We are aiming at providing the early detection of the disease using this web application, which will help the early diagnosis.
|
63 |
+
"""
|
64 |
+
)
|
65 |
+
# st.write("[aisa likh jo link ko specify kre](kuch bhi link daal de)")
|
66 |
+
with right_column:
|
67 |
+
st_lottie(lottie_coding, height=300, key="coding")
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
# # ---- PROJECTS ----
|
72 |
+
# with st.container():
|
73 |
+
# st.write("---")
|
74 |
+
# st.header("My Projects")
|
75 |
+
# st.write("##")
|
76 |
+
# image_column, text_column = st.columns((1, 2))
|
77 |
+
# with image_column:
|
78 |
+
# st.image(img_lottie_animation)
|
79 |
+
# with text_column:
|
80 |
+
# st.subheader("Integrate Lottie Animations Inside Your Streamlit App")
|
81 |
+
# st.write(
|
82 |
+
# """
|
83 |
+
# Learn how to use Lottie Files in Streamlit!
|
84 |
+
# Animations make our web app more engaging and fun, and Lottie Files are the easiest way to do it!
|
85 |
+
# In this tutorial, I'll show you exactly how to do it
|
86 |
+
# """
|
87 |
+
# )
|
88 |
+
# st.markdown("[Watch Video...](https://youtu.be/TXSOitGoINE)")
|
89 |
+
# with st.container():
|
90 |
+
# image_column, text_column = st.columns((1, 2))
|
91 |
+
# with image_column:
|
92 |
+
# st.image(img_contact_form)
|
93 |
+
# with text_column:
|
94 |
+
# st.subheader("How To Add A Contact Form To Your Streamlit App")
|
95 |
+
# st.write(
|
96 |
+
# """
|
97 |
+
# Want to add a contact form to your Streamlit website?
|
98 |
+
# In this video, I'm going to show you how to implement a contact form in your Streamlit app using the free service ‘Form Submit’.
|
99 |
+
# """
|
100 |
+
# )
|
101 |
+
# st.markdown("[Watch Video...](https://youtu.be/FOULV9Xij_8)")
|
102 |
+
|
103 |
+
|
104 |
+
#--- INPUT-OUTPUT ---
|
105 |
+
|
106 |
+
# upload= st.file_uploader('Insert image for classification', type=['png','jpg'])
|
107 |
+
# c1, c2= st.columns(2)
|
108 |
+
# if upload is not None:
|
109 |
+
# im= Image.open(upload)
|
110 |
+
# im = im.convert('RGB')
|
111 |
+
# img= np.asarray(im)
|
112 |
+
# image= cv2.resize(img,(150, 150))
|
113 |
+
# img_array = image.reshape(1,150,150,3)
|
114 |
+
# c1.header('Input Image')
|
115 |
+
# c1.image(im)
|
116 |
+
# loaded_ensemble_model = load_model('ensemble_model.h5')
|
117 |
+
|
118 |
+
# pred = loaded_ensemble_model.predict([img_array,img_array,img_array])
|
119 |
+
# labels = {0:'MildDemented',1:'ModerateDemented',2:'NonDemented',3:'VeryMildDemented'}
|
120 |
+
# c2.header('Output')
|
121 |
+
# c2.subheader('Predicted class :')
|
122 |
+
# c2.write(labels[pred.argmax()])
|
123 |
+
# c2.subheader('With :')
|
124 |
+
# c2.write(f'{int(pred.max()*100)}% assurity')
|
125 |
+
|
126 |
+
# === chat gpt ===
|
127 |
+
|
128 |
+
# ... (Previous code)
|
129 |
+
|
130 |
+
# --- INPUT-OUTPUT ---
|
131 |
+
# upload = st.file_uploader('Insert image for classification', type=['png', 'jpg'])
|
132 |
+
|
133 |
+
# if upload is not None:
|
134 |
+
# im = Image.open(upload)
|
135 |
+
# im = im.convert('RGB')
|
136 |
+
# img = np.asarray(im)
|
137 |
+
# image = cv2.resize(img, (150, 150))
|
138 |
+
# img_array = image.reshape(1, 150, 150, 3)
|
139 |
+
|
140 |
+
# st.header('Input Image')
|
141 |
+
# st.image(im, width=176, height=208, use_column_width=True) # Center the image
|
142 |
+
|
143 |
+
# loaded_ensemble_model = load_model('ensemble_model.h5')
|
144 |
+
# pred = loaded_ensemble_model.predict([img_array, img_array, img_array])
|
145 |
+
# labels = {0: 'MildDemented', 1: 'ModerateDemented', 2: 'NonDemented', 3: 'VeryMildDemented'}
|
146 |
+
|
147 |
+
# st.header('Output')
|
148 |
+
# col1, col2 = st.columns(2)
|
149 |
+
# with col1:
|
150 |
+
# st.subheader('Predicted class:')
|
151 |
+
# st.write(labels[pred.argmax()])
|
152 |
+
# with col2:
|
153 |
+
# st.subheader('With:')
|
154 |
+
# st.write(f'{int(pred.max() * 100)}% assurity')
|
155 |
+
# ... (Previous code)
|
156 |
+
|
157 |
+
|
158 |
+
|
159 |
+
# --- INPUT-OUTPUT ---
|
160 |
+
# upload = st.file_uploader('###### **Insert image for classification**', type=['png', 'jpg'])
|
161 |
+
|
162 |
+
st.header('Insert image for classification:')
|
163 |
+
|
164 |
+
upload = st.file_uploader('', type=['png', 'jpg'])
|
165 |
+
|
166 |
+
|
167 |
+
if upload is not None:
|
168 |
+
im = Image.open(upload)
|
169 |
+
im = im.convert('RGB')
|
170 |
+
img = np.asarray(im)
|
171 |
+
image = cv2.resize(img, (150, 150))
|
172 |
+
img_array = image.reshape(1, 150, 150, 3)
|
173 |
+
|
174 |
+
# Resize the image to 176x208 pixels
|
175 |
+
resized_im = im.resize((176, 208))
|
176 |
+
|
177 |
+
st.header('Input Image')
|
178 |
+
|
179 |
+
# Display the resized image
|
180 |
+
st.image(resized_im, use_column_width=False, width=176, caption='Uploaded Image')
|
181 |
+
|
182 |
+
loaded_ensemble_model = load_model('ensemble_model.h5')
|
183 |
+
pred = loaded_ensemble_model.predict([img_array, img_array, img_array])
|
184 |
+
labels = {0: 'MildDemented', 1: 'ModerateDemented', 2: 'NonDemented', 3: 'VeryMildDemented'}
|
185 |
+
|
186 |
+
st.header('Output')
|
187 |
+
col1, col2 = st.columns(2)
|
188 |
+
with col1:
|
189 |
+
st.subheader('Predicted class:')
|
190 |
+
st.write(labels[pred.argmax()])
|
191 |
+
with col2:
|
192 |
+
st.subheader('With:')
|
193 |
+
st.write(f'{int(pred.max() * 100)}% assurity')
|
194 |
+
|
195 |
+
|
196 |
+
|
197 |
+
|
198 |
+
|
199 |
+
|
200 |
+
# ---- CONTACT ----
|
201 |
+
with st.container():
|
202 |
+
st.write("---")
|
203 |
+
st.header("For any querries or suggestions!")
|
204 |
+
st.write("##")
|
205 |
+
|
206 |
+
# Documention: https://formsubmit.co/ !!! CHANGE EMAIL ADDRESS !!!
|
207 |
+
contact_form = """
|
208 |
+
<form action="https://formsubmit.co/sainimohit572000@gmail.com" method="POST">
|
209 |
+
<input type="hidden" name="_captcha" value="false">
|
210 |
+
<input type="text" name="name" placeholder="Your name" required>
|
211 |
+
<input type="email" name="email" placeholder="Your email" required>
|
212 |
+
<textarea name="message" placeholder="Your message here" required></textarea>
|
213 |
+
<button type="submit">Send</button>
|
214 |
+
</form>
|
215 |
+
"""
|
216 |
+
left_column, right_column = st.columns(2)
|
217 |
+
with left_column:
|
218 |
+
st.markdown(contact_form, unsafe_allow_html=True)
|
219 |
+
with right_column:
|
220 |
+
st.empty()
|
ensemble_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6b753fc568789b49bd0769ebc59c1ecdf31637274a1d33c915b43135d85a63e
|
3 |
+
size 441343312
|
requirement.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
opencv-python
|
3 |
+
streamlit_lottie
|
style/styles.css
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* CSS Snippet from W3schools: https://www.w3schools.com/howto/howto_css_contact_form.asp */
|
2 |
+
/* Style inputs with type="text", select elements and textareas */
|
3 |
+
input[type=message], input[type=email], input[type=text], textarea {
|
4 |
+
width: 100%; /* Full width */
|
5 |
+
padding: 12px; /* Some padding */
|
6 |
+
border: 1px solid #ccc; /* Gray border */
|
7 |
+
border-radius: 4px; /* Rounded borders */
|
8 |
+
box-sizing: border-box; /* Make sure that padding and width stays in place */
|
9 |
+
margin-top: 6px; /* Add a top margin */
|
10 |
+
margin-bottom: 16px; /* Bottom margin */
|
11 |
+
resize: vertical /* Allow the user to vertically resize the textarea (not horizontally) */
|
12 |
+
}
|
13 |
+
|
14 |
+
/* Style the submit button with a specific background color etc */
|
15 |
+
button[type=submit] {
|
16 |
+
background-color: #04AA6D;
|
17 |
+
color: white;
|
18 |
+
padding: 12px 20px;
|
19 |
+
border: none;
|
20 |
+
border-radius: 4px;
|
21 |
+
cursor: pointer;
|
22 |
+
}
|
23 |
+
|
24 |
+
/* When moving the mouse over the submit button, add a darker green color */
|
25 |
+
button[type=submit]:hover {
|
26 |
+
background-color: #45a049;
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
/* Hide Streamlit Branding */
|
31 |
+
#MainMenu {visibility: hidden;}
|
32 |
+
footer {visibility: hidden;}
|
33 |
+
header {visibility: hidden;}
|