Spaces:
Sleeping
Sleeping
Commit
·
7eb98ad
1
Parent(s):
2c32298
Update app.py
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ def predict_braintumor(img):
|
|
53 |
img_processed = preprocess_image(img)
|
54 |
pred = braintumor_model.predict(img_processed)
|
55 |
confidence = pred[0][0]
|
56 |
-
return
|
57 |
|
58 |
def preprocess_imgs(set_name, img_size):
|
59 |
set_new = []
|
@@ -62,28 +62,30 @@ def preprocess_imgs(set_name, img_size):
|
|
62 |
set_new.append(preprocess_input(img))
|
63 |
return np.array(set_new)
|
64 |
|
65 |
-
# Streamlit components
|
66 |
uploaded_file = st.file_uploader("Choose an MRI image", type=["jpg", "jpeg"])
|
67 |
|
68 |
# Display Gradio interface
|
69 |
st.markdown("<h1 style='text-align: center;'>Gradio Interface</h1>", unsafe_allow_html=True)
|
70 |
-
st.markdown(
|
71 |
-
"<p style='text-align: center;'>This is an interactive interface powered by Gradio.</p>",
|
72 |
-
unsafe_allow_html=True
|
73 |
-
)
|
74 |
-
st.markdown("<hr>", unsafe_allow_html=True)
|
75 |
|
76 |
# Create a placeholder for the Gradio interface
|
77 |
gradio_placeholder = st.empty()
|
78 |
|
79 |
-
# Create a custom HTML block
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
# Gradio interface
|
83 |
iface = gr.Interface(
|
84 |
fn=predict_braintumor,
|
85 |
inputs="image",
|
86 |
-
outputs=
|
87 |
examples=[
|
88 |
["examples/1_no.jpeg"],
|
89 |
["examples/2_no.jpeg"],
|
@@ -95,8 +97,8 @@ iface = gr.Interface(
|
|
95 |
live=True
|
96 |
)
|
97 |
|
98 |
-
# Display Gradio interface
|
99 |
-
iface.launch(gradio_placeholder)
|
100 |
|
101 |
# Streamlit components below the Gradio interface
|
102 |
if uploaded_file is not None:
|
@@ -105,10 +107,10 @@ if uploaded_file is not None:
|
|
105 |
|
106 |
# Perform prediction when the "Predict" button is clicked
|
107 |
if st.button("Predict"):
|
108 |
-
|
109 |
-
pred = braintumor_model.predict(img_array)
|
110 |
-
confidence = pred[0][0]
|
111 |
-
result = "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
|
112 |
|
113 |
-
#
|
114 |
-
|
|
|
|
|
|
|
|
53 |
img_processed = preprocess_image(img)
|
54 |
pred = braintumor_model.predict(img_processed)
|
55 |
confidence = pred[0][0]
|
56 |
+
return binary_decision(confidence)
|
57 |
|
58 |
def preprocess_imgs(set_name, img_size):
|
59 |
set_new = []
|
|
|
62 |
set_new.append(preprocess_input(img))
|
63 |
return np.array(set_new)
|
64 |
|
65 |
+
# Streamlit components
|
66 |
uploaded_file = st.file_uploader("Choose an MRI image", type=["jpg", "jpeg"])
|
67 |
|
68 |
# Display Gradio interface
|
69 |
st.markdown("<h1 style='text-align: center;'>Gradio Interface</h1>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Create a placeholder for the Gradio interface
|
72 |
gradio_placeholder = st.empty()
|
73 |
|
74 |
+
# Create a custom HTML block for title and description
|
75 |
+
html_block_title_description = gr.HTML(
|
76 |
+
f"<h2>Brain Tumor Detection App</h2>"
|
77 |
+
"<p>Curious about detecting brain tumors in medical images? "
|
78 |
+
"Give this app a try! Upload an MRI image in JPG or "
|
79 |
+
"PNG format, and discover whether it shows signs of a brain tumor. "
|
80 |
+
"This is an updated version of the Brain Tumor Classifier: "
|
81 |
+
"<a href='https://www.kaggle.com/datasets/navoneel/brain-mri-images-for-brain-tumor-detection/' target='_blank'>Kaggle Dataset</a></p>"
|
82 |
+
)
|
83 |
|
84 |
# Gradio interface
|
85 |
iface = gr.Interface(
|
86 |
fn=predict_braintumor,
|
87 |
inputs="image",
|
88 |
+
outputs="text",
|
89 |
examples=[
|
90 |
["examples/1_no.jpeg"],
|
91 |
["examples/2_no.jpeg"],
|
|
|
97 |
live=True
|
98 |
)
|
99 |
|
100 |
+
# Display title and description in Gradio interface
|
101 |
+
iface.launch(gradio_placeholder, html_block_title_description)
|
102 |
|
103 |
# Streamlit components below the Gradio interface
|
104 |
if uploaded_file is not None:
|
|
|
107 |
|
108 |
# Perform prediction when the "Predict" button is clicked
|
109 |
if st.button("Predict"):
|
110 |
+
result = predict_braintumor(uploaded_file)
|
|
|
|
|
|
|
111 |
|
112 |
+
# Display the prediction result with confidence
|
113 |
+
if result == 1:
|
114 |
+
st.success("Brain Tumor Found!")
|
115 |
+
else:
|
116 |
+
st.success("Brain Tumor Not Found!")
|