Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import pickle | |
| 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.pkl`.") | |
| model = None | |
| st.markdown( | |
| """ | |
| <style> | |
| body { | |
| background-color: #121212; | |
| color: #FFFFFF; | |
| } | |
| .stApp { | |
| background-color: #121212; | |
| color: #FFFFFF; | |
| } | |
| .title { | |
| text-align: center; | |
| font-size: 36px; | |
| font-weight: bold; | |
| color: #BB86FC; | |
| } | |
| .stButton > button { | |
| width: 100%; | |
| background-color: #6200EE; | |
| color: white; | |
| font-size: 18px; | |
| border-radius: 8px; | |
| padding: 10px; | |
| transition: 0.3s ease-in-out; | |
| } | |
| .stButton > button:hover { | |
| background-color: #3700B3; | |
| transform: scale(1.05); | |
| } | |
| .result-box { | |
| text-align: center; | |
| font-size: 20px; | |
| font-weight: bold; | |
| color: white; | |
| padding: 12px; | |
| border-radius: 8px; | |
| margin-top: 20px; | |
| box-shadow: 0px 4px 8px rgba(255, 255, 255, 0.2); | |
| transition: 0.3s ease-in-out; | |
| } | |
| .result-box:hover { | |
| transform: scale(1.05); | |
| } | |
| .high-risk { | |
| background-color: #D32F2F; | |
| } | |
| .low-risk { | |
| background-color: #388E3C; | |
| } | |
| .probability { | |
| background-color: #FFA726; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True, | |
| ) | |
| st.markdown("<h1 class='title'> PCOS Risk Predictor</h1>", unsafe_allow_html=True) | |
| with st.expander("πΉ **Personal Information**", expanded=True): | |
| Age = st.slider("Age", 18, 80, 40) | |
| 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,1]) | |
| Testosterone_Level = st.number_input("Testosterone_Level(ng/dL)", min_value=20, max_value=53, value=136) | |
| Antral_Follicle_Count = st.number_input("Antral_Follicle_Count", min_value=3, max_value=39, value=8) | |
| if st.button("π Predict Risk"): | |
| try: | |
| input_data = [[Age,BMI,Menstrual_Irregularity,Testosterone_Level,Antral_Follicle_Count]] | |
| prediction = model.predict(input_data)[0] | |
| probability = model.predict_proba(input_data)[0][1] * 100 | |
| # Determine Risk Category | |
| if prediction == 1: | |
| result_text = "ββ οΈ High Risk of PCOS Disease!" | |
| result_class = "high-risk" | |
| else: | |
| result_text = "β Low Risk of PCOS Disease!" | |
| result_class = "low-risk" | |
| # Display Result | |
| st.markdown( | |
| f"<div class='result-box {result_class}'> {result_text} </div>", | |
| unsafe_allow_html=True, | |
| ) | |
| # Display Probability Score | |
| st.markdown( | |
| f"<div class='result-box probability'> π Risk Probability: {probability:.2f}% </div>", | |
| unsafe_allow_html=True, | |
| ) | |
| except Exception as e: | |
| st.error(f"β οΈ Prediction failed: {e}") | |