Spaces:
Sleeping
Sleeping
NovooBasak
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,67 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from fastai.vision.all import *
|
| 3 |
-
from PIL import Image
|
| 4 |
-
|
| 5 |
-
# Load the model
|
| 6 |
-
learn = load_learner('model.pkl')
|
| 7 |
-
|
| 8 |
-
st.set_page_config(page_title="Breast Cancer Detector", layout="centered")
|
| 9 |
-
st.title("🩺 Breast Cancer Detection (MIAS ROI Dataset)")
|
| 10 |
-
|
| 11 |
-
st.write("Upload a mammogram ROI image to see if it's **cancerous** or **normal**.")
|
| 12 |
-
|
| 13 |
-
#
|
| 14 |
-
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
with
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
learn = load_learner('model.pkl')
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Breast Cancer Detector", layout="centered")
|
| 9 |
+
st.title("🩺 Breast Cancer Detection (MIAS ROI Dataset)")
|
| 10 |
+
|
| 11 |
+
st.write("Upload a mammogram ROI image to see if it's **cancerous** or **normal**.")
|
| 12 |
+
|
| 13 |
+
# Option to upload an image
|
| 14 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
|
| 15 |
+
|
| 16 |
+
# Select input source
|
| 17 |
+
img = None
|
| 18 |
+
if uploaded_file is not None:
|
| 19 |
+
img = Image.open(uploaded_file).convert('RGB')
|
| 20 |
+
|
| 21 |
+
if img is not None:
|
| 22 |
+
st.image(img, caption='Input Image', use_column_width=True)
|
| 23 |
+
|
| 24 |
+
# Convert to fastai's PILImage
|
| 25 |
+
img_fastai = PILImage.create(img)
|
| 26 |
+
|
| 27 |
+
# Prediction
|
| 28 |
+
pred_class, pred_idx, probs = learn.predict(img_fastai)
|
| 29 |
+
|
| 30 |
+
# Show results
|
| 31 |
+
st.subheader(f"Prediction: {pred_class.upper()}")
|
| 32 |
+
|
| 33 |
+
# Show both class probabilities
|
| 34 |
+
for cls, prob in zip(learn.dls.vocab, probs):
|
| 35 |
+
st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
|
| 36 |
+
|
| 37 |
+
st.markdown("---")
|
| 38 |
+
|
| 39 |
+
# Sample Images
|
| 40 |
+
st.subheader("Try with Sample Images:")
|
| 41 |
+
|
| 42 |
+
col1, col2 = st.columns(2)
|
| 43 |
+
|
| 44 |
+
with col1:
|
| 45 |
+
if st.button('Sample Normal'):
|
| 46 |
+
sample_path = 'sample_images/normal_sample.png' # You must upload this in Hugging Face
|
| 47 |
+
img = Image.open(sample_path).convert('RGB')
|
| 48 |
+
st.image(img, caption="Normal Sample", use_column_width=True)
|
| 49 |
+
img_fastai = PILImage.create(img)
|
| 50 |
+
pred_class, pred_idx, probs = learn.predict(img_fastai)
|
| 51 |
+
st.subheader(f"Prediction: {pred_class.upper()}")
|
| 52 |
+
for cls, prob in zip(learn.dls.vocab, probs):
|
| 53 |
+
st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
|
| 54 |
+
|
| 55 |
+
with col2:
|
| 56 |
+
if st.button('Sample Cancer'):
|
| 57 |
+
sample_path = 'sample_images/cancer_sample.png' # You must upload this too
|
| 58 |
+
img = Image.open(sample_path).convert('RGB')
|
| 59 |
+
st.image(img, caption="Cancer Sample", use_column_width=True)
|
| 60 |
+
img_fastai = PILImage.create(img)
|
| 61 |
+
pred_class, pred_idx, probs = learn.predict(img_fastai)
|
| 62 |
+
st.subheader(f"Prediction: {pred_class.upper()}")
|
| 63 |
+
for cls, prob in zip(learn.dls.vocab, probs):
|
| 64 |
+
st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
|
| 65 |
+
|
| 66 |
+
st.markdown("---")
|
| 67 |
+
st.write("Made by Novoo.")
|