Update src/streamlit_app.py
Browse files- src/streamlit_app.py +56 -34
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,62 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# ======================
|
| 7 |
+
# LOAD MODEL
|
| 8 |
+
# ======================
|
| 9 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
+
model = joblib.load(os.path.join(BASE_DIR, "breast_cancer_model.pkl"))
|
| 11 |
+
|
| 12 |
+
# ======================
|
| 13 |
+
# PAGE CONFIG
|
| 14 |
+
# ======================
|
| 15 |
+
st.set_page_config(
|
| 16 |
+
page_title="Breast Cancer Prediction",
|
| 17 |
+
page_icon="🎗️",
|
| 18 |
+
layout="centered"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
st.title("🎗️ Breast Cancer Prediction")
|
| 22 |
+
st.write("Predict whether a tumor is benign or malignant")
|
| 23 |
+
|
| 24 |
+
# ======================
|
| 25 |
+
# SIDEBAR INPUTS
|
| 26 |
+
# ======================
|
| 27 |
+
st.sidebar.header("Cell Nuclei Measurements")
|
| 28 |
+
|
| 29 |
+
radius_mean = st.sidebar.slider("Radius Mean", 5.0, 30.0, 14.0)
|
| 30 |
+
texture_mean = st.sidebar.slider("Texture Mean", 5.0, 40.0, 19.0)
|
| 31 |
+
perimeter_mean = st.sidebar.slider("Perimeter Mean", 40.0, 200.0, 90.0)
|
| 32 |
+
area_mean = st.sidebar.slider("Area Mean", 200.0, 2500.0, 650.0)
|
| 33 |
+
smoothness_mean = st.sidebar.slider("Smoothness Mean", 0.05, 0.2, 0.1)
|
| 34 |
+
|
| 35 |
+
# ======================
|
| 36 |
+
# DATAFRAME
|
| 37 |
+
# ======================
|
| 38 |
+
input_df = pd.DataFrame({
|
| 39 |
+
"radius_mean": [radius_mean],
|
| 40 |
+
"texture_mean": [texture_mean],
|
| 41 |
+
"perimeter_mean": [perimeter_mean],
|
| 42 |
+
"area_mean": [area_mean],
|
| 43 |
+
"smoothness_mean": [smoothness_mean]
|
| 44 |
+
})
|
| 45 |
|
| 46 |
+
st.subheader("Input Data")
|
| 47 |
+
st.write(input_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# ======================
|
| 50 |
+
# PREDICTION
|
| 51 |
+
# ======================
|
| 52 |
+
if st.button("Predict"):
|
| 53 |
|
| 54 |
+
prediction = model.predict(input_df)[0]
|
| 55 |
+
probability = model.predict_proba(input_df)[0][1]
|
| 56 |
|
| 57 |
+
st.subheader("Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
if prediction == 1:
|
| 60 |
+
st.error(f"⚠️ Malignant Tumor ({probability:.2%})")
|
| 61 |
+
else:
|
| 62 |
+
st.success(f"✅ Benign Tumor ({1 - probability:.2%})")
|
|
|
|
|
|
|
|
|
|
|
|