jawadskript commited on
Commit
554025f
·
verified ·
1 Parent(s): b147ad5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -9
README.md CHANGED
@@ -44,12 +44,44 @@ Validation Accuracy: ~96%
44
  Example (simplified):
45
 
46
  ```python
47
- model = Sequential([
48
- Conv2D(32, (3,3), activation='relu', input_shape=(150, 150, 3)),
49
- MaxPooling2D(2,2),
50
- Conv2D(64, (3,3), activation='relu'),
51
- MaxPooling2D(2,2),
52
- Flatten(),
53
- Dense(128, activation='relu'),
54
- Dense(1, activation='sigmoid')
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}%**")