Screen going blank?

import streamlit as st
import joblib
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import xgboost as xgb
from xgboost import XGBClassifier

# Load the Random Forest model
prediction_model = xgb.Booster()

def main():

    if st.button("Prediction"):
        st.markdown("Enter the User's Details to predict the occurrence of Stroke")
        st.text("Please Enter correct details to get better results")
        # Getting User Inputs
        gender ="What is User's gender", ("Male", "Female"))
        age = st.number_input("Enter User's age", value=40)
        hypertension ="Hypertension?", ("Yes", "No"))
        heart_disease ="User Ever had a heart disease?", ("Yes", "No"))
        ever_married ="User Ever Married?", ("Yes", "No"))
        work_type ="What is User's work type?", ("Government Job", "Private Job", "Self Employed", "Never Worked", "Children"))
        Residence_type ="What is User's Residence type?", ("Urban", "Rural"))
        avg_glucose_level = st.number_input("Enter User's Average Glucose Level", value=92.35)
        bmi = st.number_input("Enter User's BMI", value=25.4)
        smoking_status ="User's Smoking Status?", ("Unknown", "Formerly Smoked", "Never Smoked", "Smokes"))
        if st.button("Submit"):
            # Encoding categorical attributes to values
            gender = 1 if gender == 'Male' else 0
            age = float(age)
            hypertension = 1 if hypertension == 'Yes' else 0
            ever_married = 1 if ever_married == 'Yes' else 0
            heart_disease = 1 if heart_disease == 'Yes' else 0
            if work_type == 'Government Job':
                work_type = 0 
            elif work_type == 'Never Worked':
                work_type = 1 
            elif work_type == 'Private Job':
                work_type = 2 
            elif work_type == 'Self Employed':
                work_type = 3
            elif work_type == 'Children':
                work_type = 4 
            Residence_type = 1 if Residence_type == 'Urban' else 0
            avg_glucose_level = float(avg_glucose_level)
            bmi = float(bmi)
            if smoking_status == 'Unknown':
                smoking_status = 0 
            elif smoking_status == 'Formerly Smoked':
                smoking_status = 1 
            elif smoking_status == 'Never Smoked':
                smoking_status = 2
            elif smoking_status == 'Smokes':
                smoking_status = 3 

            # Creating nparray of User Inputs
            user_input = np.array([gender, age, hypertension, heart_disease, ever_married, work_type, Residence_type, avg_glucose_level, bmi, smoking_status]).reshape(1, -1)

            # Converting into DataFrame to avoid mismatching feature_names error
            user_input_df = pd.DataFrame(user_input, columns=['gender', 'age', 'hypertension', 'heart_disease', 'ever_married', 'work_type', 'Residence_type', 'avg_glucose_level', 'bmi', 'smoking_status'])

            # Prediction using Random Forest model
            prediction = loaded_model.predict(user_input_df)

            # Printing Predicted results
            if prediction == 1:
                st.header("User has Higher Chances of having a StrokeπŸ˜”")
                st.header("User has Lower Chances of having a Stroke😊")

if __name__ == '__main__':

this is the code, everytime I run it it goes blank, please help

Hi @swaraj-khan,

Have you tried replacing loaded_model with prediction_model?


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.