SURESHBEEKHANI commited on
Commit
b89d505
·
verified ·
1 Parent(s): bd4bff8

Upload 5 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ logo/logo.png filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ultralytics import YOLO
3
+ from PIL import Image
4
+ import torchvision.transforms as transforms
5
+ import base64
6
+
7
+ # Set Streamlit Page Configuration
8
+ st.set_page_config(
9
+ page_title="Brain Tumor Segmentation",
10
+ page_icon="logo/logo.png",
11
+ layout="centered"
12
+ )
13
+
14
+ # Cache the YOLO model to avoid reloading on every interaction
15
+ @st.cache_resource()
16
+ def load_model():
17
+ return YOLO("model/best.pt") # Update path if needed
18
+
19
+ model = load_model()
20
+
21
+ # Define image transformation pipeline
22
+ transform = transforms.Compose([
23
+ transforms.Resize((640, 640)),
24
+ transforms.ToTensor()
25
+ ])
26
+
27
+ # Function to predict and overlay tumor segmentation mask
28
+ def predict_tumor(image: Image.Image):
29
+ try:
30
+ image_tensor = transform(image).unsqueeze(0) # Add batch dimension
31
+ results = model.predict(image_tensor)
32
+ output_image = results[0].plot() # Overlay segmentation mask
33
+ return Image.fromarray(output_image)
34
+ except Exception as e:
35
+ st.error(f"Prediction Error: {e}")
36
+ return None
37
+
38
+ # Function to encode image to base64 for embedding
39
+ def get_base64_image(image_path):
40
+ with open(image_path, "rb") as img_file:
41
+ return base64.b64encode(img_file.read()).decode()
42
+
43
+ # Display logo
44
+ image_base64 = get_base64_image("logo/logo.png")
45
+ st.markdown(
46
+ f'<div style="text-align: center;"><img src="data:image/png;base64,{image_base64}" width="100"></div>',
47
+ unsafe_allow_html=True
48
+ )
49
+
50
+ # --- UI Customization ---
51
+ st.markdown("""
52
+ <style>
53
+ [data-testid="stSidebar"] { background-color: #1E1E2F; }
54
+ [data-testid="stSidebar"] h1, [data-testid="stSidebar"] h2 { color: white; }
55
+ h1 { text-align: center; font-size: 36px; font-weight: bold; color: #2C3E50; }
56
+ div.stButton > button { background-color: #3498DB; color: white; font-weight: bold; }
57
+ div.stButton > button:hover { background-color: #2980B9; }
58
+ </style>
59
+ """, unsafe_allow_html=True)
60
+
61
+ # --- Sidebar ---
62
+ st.sidebar.header("📤 Upload an MRI Image")
63
+ uploaded_file = st.sidebar.file_uploader("Drag and drop or browse", type=['jpg', 'png', 'jpeg'])
64
+
65
+ # --- Main Page ---
66
+ st.title("Brain Tumor Segmentation")
67
+ st.markdown("<p style='text-align: center;'>Detect and segment brain tumors from MRI scans.</p>", unsafe_allow_html=True)
68
+
69
+ if uploaded_file:
70
+ image = Image.open(uploaded_file).convert("RGB")
71
+ col1, col2 = st.columns(2)
72
+
73
+ with col1:
74
+ st.image(image, caption="📷 Uploaded Image", use_container_width=True)
75
+
76
+ if st.sidebar.button("🔍 Predict Tumor Segmentation"):
77
+ segmented_image = predict_tumor(image)
78
+ if segmented_image:
79
+ with col2:
80
+ st.image(segmented_image, caption="🎯 Segmented Tumor", use_container_width=True)
81
+ else:
82
+ st.error("Segmentation failed. Please try again.")
83
+
84
+ st.markdown("---")
85
+ st.info("This app uses **YOLO-Seg** for real-time tumor segmentation. Upload an MRI image to get started.")
logo/logo.png ADDED

Git LFS Details

  • SHA256: e1a3547fc35e739002ad94a3eb15c62207eac122d4c3ea28b8562cd0642e1c75
  • Pointer size: 131 Bytes
  • Size of remote file: 176 kB
model/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d27e39c39f386e466a34d0b243de5cd6449120cab37c9bbf3a3a5279fd15d9e9
3
+ size 5996125
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Flask
2
+ ultralytics
3
+ Pillow
4
+ torch
5
+ torchvision
6
+ numpy
resources/YOLO11_Instance_Segmentation.ipynb ADDED
The diff for this file is too large to render. See raw diff