NovooBasak commited on
Commit
c5caf36
·
verified ·
1 Parent(s): aa17600

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -61
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
- # Upload image only (removed camera input)
14
- uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
15
-
16
- img = None
17
- if uploaded_file is not None:
18
- img = Image.open(uploaded_file).convert('RGB')
19
-
20
- if img is not None:
21
- st.image(img, caption='Input Image', use_column_width=True)
22
-
23
- # Prediction
24
- pred_class, pred_idx, probs = learn.predict(img)
25
-
26
- # Show results
27
- st.subheader(f"Prediction: {pred_class.upper()}")
28
-
29
- # Show both class probabilities
30
- for cls, prob in zip(learn.dls.vocab, probs):
31
- st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
32
-
33
- st.markdown("---")
34
-
35
- # Sample Images
36
- st.subheader("Try with Sample Images:")
37
-
38
- col1, col2 = st.columns(2)
39
-
40
- with col1:
41
- if st.button('Sample Normal'):
42
- sample_path = 'sample_images/normal_sample.png' # You will upload this
43
- img = Image.open(sample_path).convert('RGB')
44
- st.image(img, caption="Normal Sample", use_column_width=True)
45
- pred_class, pred_idx, probs = learn.predict(img)
46
- st.subheader(f"Prediction: {pred_class.upper()}")
47
- for cls, prob in zip(learn.dls.vocab, probs):
48
- st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
49
-
50
- with col2:
51
- if st.button('Sample Cancer'):
52
- sample_path = 'sample_images/cancer_sample.png' # You will upload this
53
- img = Image.open(sample_path).convert('RGB')
54
- st.image(img, caption="Cancer Sample", use_column_width=True)
55
- pred_class, pred_idx, probs = learn.predict(img)
56
- st.subheader(f"Prediction: {pred_class.upper()}")
57
- for cls, prob in zip(learn.dls.vocab, probs):
58
- st.write(f"**{cls.capitalize()}**: {prob*100:.2f}% confidence")
59
-
60
- st.markdown("---")
61
- st.write("Made with ❤️ using FastAI and Streamlit.")
 
 
 
 
 
 
 
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.")