Update README.md
Browse files
README.md
CHANGED
@@ -44,12 +44,44 @@ Validation Accuracy: ~96%
|
|
44 |
Example (simplified):
|
45 |
|
46 |
```python
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
Example (simplified):
|
45 |
|
46 |
```python
|
47 |
+
import streamlit as st
|
48 |
+
import tensorflow as tf
|
49 |
+
import numpy as np
|
50 |
+
from tensorflow.keras.preprocessing import image
|
51 |
+
from PIL import Image
|
52 |
+
|
53 |
+
# Load the trained model
|
54 |
+
@st.cache_resource
|
55 |
+
def load_model():
|
56 |
+
return tf.keras.models.load_model('models/brain_tumor_model.h5') # Update path if needed
|
57 |
+
|
58 |
+
model = load_model()
|
59 |
+
|
60 |
+
# Define class labels
|
61 |
+
class_names = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
|
62 |
+
|
63 |
+
# UI
|
64 |
+
st.title("🧠 Brain Tumor Detection from MRI")
|
65 |
+
st.write("Upload an MRI image to detect the type of brain tumor.")
|
66 |
+
|
67 |
+
# Upload image
|
68 |
+
uploaded_file = st.file_uploader("Choose an MRI image", type=["jpg", "jpeg", "png"])
|
69 |
+
|
70 |
+
if uploaded_file is not None:
|
71 |
+
# Show image
|
72 |
+
img = Image.open(uploaded_file)
|
73 |
+
st.image(img, caption="🖼️ Uploaded Image", use_container_width=True)
|
74 |
+
|
75 |
+
# Preprocessing
|
76 |
+
img = img.resize((224, 224)) # ✅ Make sure it matches your model's input size
|
77 |
+
img_array = image.img_to_array(img)
|
78 |
+
img_array = np.expand_dims(img_array, axis=0) / 255.0
|
79 |
+
|
80 |
+
# Prediction
|
81 |
+
predictions = model.predict(img_array)
|
82 |
+
confidence = float(np.max(predictions)) * 100
|
83 |
+
predicted_class = class_names[np.argmax(predictions)]
|
84 |
+
|
85 |
+
# Output
|
86 |
+
st.success(f"🎯 Predicted Tumor Type: **{predicted_class}**")
|
87 |
+
st.info(f"📊 Model Confidence: **{confidence:.2f}%**")
|