Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
3ab8166
1
Parent(s):
6a8052b
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,27 @@ braintumor_model = load_model('models/brain_tumor_binary.h5')
|
|
12 |
# Configuring Streamlit
|
13 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def preprocess_image(img):
|
16 |
# If it's a NumPy array, use it directly
|
17 |
if isinstance(img, np.ndarray):
|
@@ -27,9 +48,7 @@ def preprocess_image(img):
|
|
27 |
img_gray = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE)
|
28 |
|
29 |
# Crop and preprocess the grayscale image
|
30 |
-
img_processed =
|
31 |
-
img_processed = preprocess_input(img_processed)
|
32 |
-
img_processed = np.expand_dims(img_processed, axis=0)
|
33 |
|
34 |
return img_processed
|
35 |
|
@@ -47,33 +66,3 @@ def predict_braintumor(img):
|
|
47 |
# Handle binary decision
|
48 |
confidence = pred[0][0]
|
49 |
return "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
|
50 |
-
|
51 |
-
def main():
|
52 |
-
st.title("Brain Tumor Prediction App")
|
53 |
-
|
54 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg"])
|
55 |
-
|
56 |
-
if uploaded_file is not None:
|
57 |
-
st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)
|
58 |
-
st.write("")
|
59 |
-
st.write("Classifying...")
|
60 |
-
|
61 |
-
# Make prediction
|
62 |
-
result = predict_braintumor(uploaded_file)
|
63 |
-
|
64 |
-
# Display prediction
|
65 |
-
st.subheader("Prediction:")
|
66 |
-
st.success(result)
|
67 |
-
|
68 |
-
if __name__ == "__main__":
|
69 |
-
# Streamlit app
|
70 |
-
main()
|
71 |
-
|
72 |
-
# Gradio interface
|
73 |
-
iface = gr.Interface(
|
74 |
-
fn=predict_braintumor,
|
75 |
-
inputs="image",
|
76 |
-
outputs="text",
|
77 |
-
examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]]
|
78 |
-
)
|
79 |
-
iface.launch()
|
|
|
12 |
# Configuring Streamlit
|
13 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
14 |
|
15 |
+
# Customizing Gradio appearance
|
16 |
+
gr.set_config(
|
17 |
+
display_name=title,
|
18 |
+
interface_color="rgba(255, 99, 71, 0.8)", # Adjust color as needed
|
19 |
+
live=True
|
20 |
+
)
|
21 |
+
|
22 |
+
# Configuring Gradio
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn="predict_braintumor",
|
25 |
+
inputs="image",
|
26 |
+
outputs="text",
|
27 |
+
live=True,
|
28 |
+
interpretation="default",
|
29 |
+
examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]],
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
article=article
|
33 |
+
)
|
34 |
+
iface.launch()
|
35 |
+
|
36 |
def preprocess_image(img):
|
37 |
# If it's a NumPy array, use it directly
|
38 |
if isinstance(img, np.ndarray):
|
|
|
48 |
img_gray = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE)
|
49 |
|
50 |
# Crop and preprocess the grayscale image
|
51 |
+
img_processed = preprocess_imgs([img_gray], (224, 224))
|
|
|
|
|
52 |
|
53 |
return img_processed
|
54 |
|
|
|
66 |
# Handle binary decision
|
67 |
confidence = pred[0][0]
|
68 |
return "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|