Upload 5 files
Browse files- .gitattributes +1 -0
- app.py +89 -0
- logo/logo.png +3 -0
- requirements.txt +6 -0
- resources/Lung_Cancer_Detection.ipynb +0 -0
- weights/Lung Cancer Detection.pt +3 -0
.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,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="Lung Cancer Detection",
|
| 10 |
+
page_icon="logo/logo.png",
|
| 11 |
+
layout="centered"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Cache model loaders for each detection type
|
| 15 |
+
@st.cache_resource()
|
| 16 |
+
def load_lung_model():
|
| 17 |
+
return YOLO("weights/Lung Cancer Detection.pt") # Path for lung cancer detection model
|
| 18 |
+
|
| 19 |
+
# Load lung model only
|
| 20 |
+
lung_model = load_lung_model()
|
| 21 |
+
|
| 22 |
+
# Define image transformation pipeline
|
| 23 |
+
transform = transforms.Compose([
|
| 24 |
+
transforms.Resize((640, 640)),
|
| 25 |
+
transforms.ToTensor()
|
| 26 |
+
])
|
| 27 |
+
|
| 28 |
+
# Update prediction function to accept a model parameter
|
| 29 |
+
def predict_tumor(image: Image.Image, model):
|
| 30 |
+
try:
|
| 31 |
+
image_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
| 32 |
+
results = model.predict(image_tensor)
|
| 33 |
+
output_image = results[0].plot() # Overlay segmentation mask
|
| 34 |
+
return Image.fromarray(output_image)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
st.error(f"Prediction Error: {e}")
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
# Function to encode image to base64 for embedding
|
| 40 |
+
def get_base64_image(image_path):
|
| 41 |
+
with open(image_path, "rb") as img_file:
|
| 42 |
+
return base64.b64encode(img_file.read()).decode()
|
| 43 |
+
|
| 44 |
+
# Display logo
|
| 45 |
+
image_base64 = get_base64_image("logo/logo.png")
|
| 46 |
+
st.markdown(
|
| 47 |
+
f'<div style="text-align: center;"><img src="data:image/png;base64,{image_base64}" width="100"></div>',
|
| 48 |
+
unsafe_allow_html=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# --- UI Customization ---
|
| 52 |
+
st.markdown("""
|
| 53 |
+
<style>
|
| 54 |
+
[data-testid="stSidebar"] { background-color: #1E1E2F; }
|
| 55 |
+
[data-testid="stSidebar"] h1, [data-testid="stSidebar"] h2 { color: white; }
|
| 56 |
+
h1 { text-align: center; font-size: 36px; font-weight: bold; color: #2C3E50; }
|
| 57 |
+
div.stButton > button { background-color: #3498DB; color: white; font-weight: bold; }
|
| 58 |
+
div.stButton > button:hover { background-color: #2980B9; }
|
| 59 |
+
</style>
|
| 60 |
+
""", unsafe_allow_html=True)
|
| 61 |
+
|
| 62 |
+
# --- Sidebar ---
|
| 63 |
+
st.sidebar.header("📤 Upload a CT Image")
|
| 64 |
+
uploaded_file = st.sidebar.file_uploader("Drag and drop or browse", type=['jpg', 'png', 'jpeg'])
|
| 65 |
+
|
| 66 |
+
# Updated: remove detection option since only lung cancer is supported now
|
| 67 |
+
detection_option = "Lung Cancer"
|
| 68 |
+
|
| 69 |
+
# --- Main Page ---
|
| 70 |
+
st.title("Lung Cancer Detection")
|
| 71 |
+
st.markdown("<p style='text-align: center;'>Detect and segment lung cancer from CT scans.</p>", unsafe_allow_html=True)
|
| 72 |
+
|
| 73 |
+
if uploaded_file:
|
| 74 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 75 |
+
col1, col2 = st.columns(2)
|
| 76 |
+
|
| 77 |
+
with col1:
|
| 78 |
+
st.image(image, caption="📷 Uploaded Image", use_container_width=True)
|
| 79 |
+
|
| 80 |
+
if st.sidebar.button("🔍 Predict " + detection_option):
|
| 81 |
+
segmented_image = predict_tumor(image, lung_model)
|
| 82 |
+
if segmented_image:
|
| 83 |
+
with col2:
|
| 84 |
+
st.image(segmented_image, caption="🎯 Segmented Lung Cancer", use_container_width=True)
|
| 85 |
+
else:
|
| 86 |
+
st.error("Segmentation failed. Please try again.")
|
| 87 |
+
|
| 88 |
+
st.markdown("---")
|
| 89 |
+
st.info("This app uses **YOLO-Seg** for real-time lung cancer detection. Upload a CT image to get started.")
|
logo/logo.png
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
ultralytics
|
| 3 |
+
Pillow
|
| 4 |
+
torch
|
| 5 |
+
torchvision
|
| 6 |
+
numpy
|
resources/Lung_Cancer_Detection.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
weights/Lung Cancer Detection.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbf3cf58b36f47888ee0120bae72b9583ac7af5cb8cc814313693201e9c24e6e
|
| 3 |
+
size 5996957
|