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( """ """, unsafe_allow_html=True, ) st.markdown("

๐Ÿฉบ PCOS Risk Predictor

", 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"
{result_text}
", unsafe_allow_html=True ) st.markdown( f"
๐Ÿ“Š Estimated Probability: {probability:.2f}%
", unsafe_allow_html=True ) except Exception as e: st.error(f"๐Ÿšซ Prediction failed: {e}")