nisharg nargund commited on
Commit
ee9c3a8
·
1 Parent(s): f8d3988

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -1,12 +1,10 @@
1
  !pip install tensorflow
 
 
2
  import streamlit as st
3
  import tensorflow as tf
4
  from PIL import Image
5
  import numpy as np
6
- import keras
7
-
8
- # Load the TensorFlow model from the .h5 file
9
- model = tf.keras.models.load_model("model.h5")
10
 
11
  # Create a Streamlit app
12
  st.title("Brain Tumor Detection")
@@ -14,22 +12,23 @@ st.title("Brain Tumor Detection")
14
  # Upload an image
15
  image = st.file_uploader("Upload an MRI image of a brain with a tumor", type=["jpg", "jpeg", "png"])
16
 
17
- # Button to make predictions
18
- if image is not None:
19
- image = Image.open(image)
20
- st.image(image, caption="Uploaded Image", use_column_width=True)
21
-
22
- # Preprocess the image
23
- image = image.resize((224, 224)) # Adjust the size according to your model's input requirements
24
- image = np.array(image)
25
- image = image / 255.0 # Normalize the image to [0, 1]
26
- image = np.expand_dims(image, axis=0) # Add batch dimension
27
-
28
- # Make predictions
29
- prediction = model.predict(image)
30
-
31
- # Display prediction results
32
- if prediction > 0.5:
33
- st.write("Prediction: Tumor detected")
34
- else:
35
- st.write("Prediction: No tumor detected")
 
 
1
  !pip install tensorflow
2
+
3
+ # Import necessary libraries
4
  import streamlit as st
5
  import tensorflow as tf
6
  from PIL import Image
7
  import numpy as np
 
 
 
 
8
 
9
  # Create a Streamlit app
10
  st.title("Brain Tumor Detection")
 
12
  # Upload an image
13
  image = st.file_uploader("Upload an MRI image of a brain with a tumor", type=["jpg", "jpeg", "png"])
14
 
15
+ # Check if TensorFlow is available
16
+ if 'tensorflow' not in sys.modules:
17
+ st.warning("TensorFlow is not available in this environment. Please ensure that you have the correct environment activated.")
18
+
19
+ else:
20
+ # Load the TensorFlow model from the .h5 file
21
+ model = tf.keras.models.load_model("model.h5")
22
+
23
+ # Button to make predictions
24
+ if image is not None:
25
+ image = Image.open(image)
26
+ st.image(image, caption="Uploaded Image", use_column_width=True)
27
+
28
+ # Preprocess the image
29
+ image = image.resize((224, 224)) # Adjust the size according to your model's input requirements
30
+ image = np.array(image)
31
+ image = image / 255.0 # Normalize the image to [0, 1]
32
+ image = np.expand_dims(image, axis=0) # Add batch dimension
33
+
34
+ # Make predictions