Spaces:
Sleeping
Sleeping
File size: 3,724 Bytes
275e531 999d28f 2514e94 275e531 2514e94 275e531 8b144ac 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 96c3270 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 275e531 2514e94 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import streamlit as st
import numpy as np
import pandas as pd
import pickle
# Load model
try:
with open("final_model (3).pkl", "rb") as f:
model = pickle.load(f)
st.success("β
Model loaded successfully!")
except FileNotFoundError:
st.error("β Model file not found! Please upload `final_model (3).pkl`.")
model = None
# Custom CSS for styling
st.markdown(
"""
<style>
.stApp {
background-color: #121212;
color: #FFFFFF;
}
.title {
text-align: center;
font-size: 38px;
font-weight: bold;
color: #BB86FC;
margin-top: 20px;
}
.stButton > button {
background-color: #6200EE;
color: white;
font-size: 18px;
border-radius: 8px;
padding: 10px 20px;
transition: 0.3s ease-in-out;
}
.stButton > button:hover {
background-color: #3700B3;
transform: scale(1.05);
}
.result-box {
text-align: center;
font-size: 22px;
font-weight: bold;
color: white;
padding: 16px;
border-radius: 10px;
margin-top: 30px;
box-shadow: 0px 4px 12px rgba(255, 255, 255, 0.3);
}
.high-risk {
background-color: #D32F2F;
}
.low-risk {
background-color: #388E3C;
}
.probability {
background-color: #FFA726;
margin-top: 12px;
}
</style>
""",
unsafe_allow_html=True,
)
st.markdown("<h1 class='title'>π©Ί PCOS Risk Predictor</h1>", unsafe_allow_html=True)
# Collect user inputs
with st.expander("π Personal Information", expanded=True):
Age = st.slider("π Age", 18, 44, 30)
with st.expander("π₯ Medical Information", expanded=True):
BMI = st.number_input("βοΈ BMI", min_value=8, max_value=50, value=23)
Menstrual_Irregularity = st.selectbox("π©Έ Menstrual Irregularity (0 = No, 1 = Yes)", [0, 1])
Testosterone_Level = st.number_input("𧬠Testosterone Level (ng/dL)", min_value=20, max_value=135, value=53)
Antral_Follicle_Count = st.number_input("π§ͺ Antral Follicle Count", min_value=3, max_value=39, value=8)
# Predict
if st.button("π Predict Risk"):
if model is None:
st.error("β οΈ Model is not loaded. Please ensure the model file exists.")
else:
try:
input_df = pd.DataFrame([[
Age,
BMI,
Menstrual_Irregularity,
Testosterone_Level,
Antral_Follicle_Count
]], columns=[
'Age',
'BMI',
'Menstrual_Irregularity',
'Testosterone_Level(ng/dL)',
'Antral_Follicle_Count'
])
prediction = model.predict(input_df)[0]
probability = model.predict_proba(input_df)[0][1] * 100
if prediction == 1:
result_text = "β οΈβ High Risk of PCOS Detected!"
result_class = "high-risk"
else:
result_text = "β
Low Risk of PCOS β You're Good!"
result_class = "low-risk"
st.markdown(
f"<div class='result-box {result_class}'>{result_text}</div>",
unsafe_allow_html=True
)
st.markdown(
f"<div class='result-box probability'>π Estimated Probability: {probability:.2f}%</div>",
unsafe_allow_html=True
)
except Exception as e:
st.error(f"π« Prediction failed: {e}")
|