LovnishVerma commited on
Commit
e7a8b14
1 Parent(s): 9a5ddab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -4
app.py CHANGED
@@ -7,12 +7,29 @@ from tensorflow.keras.applications.vgg16 import preprocess_input
7
  from tensorflow.keras.preprocessing import image
8
 
9
  # Loading Models
10
- # braintumor_model = load_model('models/brain_tumor_binary.h5')
11
- braintumor_model = load_model('models/braintumor.h5')
12
 
13
  # Configuring Streamlit
14
- st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
16
  def preprocess_image(img):
17
  # If it's a NumPy array, use it directly
18
  if isinstance(img, np.ndarray):
@@ -79,6 +96,31 @@ iface = gr.Interface(
79
  fn=predict_braintumor,
80
  inputs="image",
81
  outputs="text",
82
- examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]]
 
83
  )
 
 
84
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  from tensorflow.keras.preprocessing import image
8
 
9
  # Loading Models
10
+ braintumor_model = load_model('models/brain_tumor_binary.h5')
 
11
 
12
  # Configuring Streamlit
13
+ st.set_page_config(
14
+ page_title="Brain Tumor Prediction App",
15
+ page_icon=":brain:",
16
+ layout="centered",
17
+ )
18
+
19
+ # Streamlit app title and description
20
+ st.title("Brain Tumor Prediction App")
21
+ st.write(
22
+ "Upload an image, and the app will predict whether a brain tumor is present or not."
23
+ )
24
 
25
+ # Add Streamlit sidebar for additional information or options
26
+ st.sidebar.title("About")
27
+ st.sidebar.info(
28
+ "This app uses a trained model to predict brain tumors from images. "
29
+ "The model is based on VGG16 architecture."
30
+ )
31
+
32
+ # Function to preprocess the image
33
  def preprocess_image(img):
34
  # If it's a NumPy array, use it directly
35
  if isinstance(img, np.ndarray):
 
96
  fn=predict_braintumor,
97
  inputs="image",
98
  outputs="text",
99
+ examples=[["examples/1_no.jpeg"], ["examples/2_no.jpeg"], ["examples/3_no.jpg"], ["examples/Y1.jpg"], ["examples/Y2.jpg"], ["examples/Y3.jpg"]],
100
+ live=True # Allows real-time updates without restarting the app
101
  )
102
+
103
+ # Display Gradio interface
104
  iface.launch()
105
+
106
+ # Streamlit components below the Gradio interface
107
+ uploaded_file = st.file_uploader("Choose an MRI image", type=["jpg", "jpeg"])
108
+
109
+ if uploaded_file is not None:
110
+ # Display the uploaded image
111
+ st.image(uploaded_file, caption="Uploaded MRI Image.", use_column_width=True)
112
+
113
+ # Perform prediction when the "Predict" button is clicked
114
+ if st.button("Predict"):
115
+ # Preprocess the image
116
+ img_array = preprocess_image(uploaded_file)
117
+
118
+ # Make prediction
119
+ pred = braintumor_model.predict(img_array)
120
+
121
+ # Handle binary decision
122
+ confidence = pred[0][0]
123
+ result = "Brain Tumor Not Found!" if binary_decision(confidence) == 1 else "Brain Tumor Found!"
124
+
125
+ # Display the prediction result
126
+ st.write(result)