rohitashva commited on
Commit
da89937
·
verified ·
1 Parent(s): fe2da5d

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +61 -0
  2. requirements.txt +4 -0
  3. saved_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
+ from tensorflow.keras.preprocessing import image
5
+ from PIL import Image
6
+
7
+ # ------------------------------
8
+ # Load the trained model
9
+ # ------------------------------
10
+ @st.cache_resource()
11
+ def load_model():
12
+ return tf.keras.models.load_model("model.h5")
13
+
14
+ model = load_model()
15
+
16
+ # Class labels from your notebook
17
+ CLASS_LABELS = ["Glioma", "Meningioma", "No Tumor", "Pituitary Tumor"]
18
+
19
+ # ------------------------------
20
+ # Image Preprocessing
21
+ # ------------------------------
22
+ def preprocess_image(img):
23
+ """Preprocess the image to match the model's input requirements."""
24
+ img = img.resize((224, 224)) # Resize to model input size
25
+ img = img.convert("RGB") # Ensure RGB mode
26
+ img_array = np.array(img) / 255.0 # Normalize pixel values
27
+ img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
28
+ return img_array
29
+
30
+ # ------------------------------
31
+ # Streamlit UI
32
+ # ------------------------------
33
+ st.title("🧠 Brain Tumor Detection with Deep Learning")
34
+ st.write("Upload an MRI scan (JPG, PNG) to check for a brain tumor.")
35
+
36
+ uploaded_file = st.file_uploader("Choose an MRI scan...", type=["jpg", "png", "jpeg"])
37
+
38
+ if uploaded_file is not None:
39
+ # Display the uploaded image
40
+ image = Image.open(uploaded_file)
41
+ st.image(image, caption="Uploaded MRI Scan", use_column_width=True)
42
+
43
+ # Preprocess the image
44
+ img_array = preprocess_image(image)
45
+
46
+ # Make prediction
47
+ prediction = model.predict(img_array)
48
+ predicted_class = np.argmax(prediction, axis=1)[0]
49
+ confidence = np.max(prediction)
50
+
51
+ # Display result
52
+ st.subheader("🩺 Prediction Results")
53
+ st.write(f"**Predicted Class:** {CLASS_LABELS[predicted_class]}")
54
+ st.write(f"**Confidence Score:** {confidence:.2f}")
55
+
56
+ # Provide interpretation
57
+ if predicted_class == 2:
58
+ st.success("✅ No Brain Tumor Detected.")
59
+ else:
60
+ st.error(f"🚨 Brain Tumor Detected: **{CLASS_LABELS[predicted_class]}**. Consult a doctor.")
61
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ tensorflow
3
+ numpy
4
+ pillow
saved_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63172564e417d6ee4208b1c5d1503a70cd3ab8a997f0d4be1ce170e8a0888bb3
3
+ size 213127952