Spaces:
Sleeping
Sleeping
File size: 1,632 Bytes
da0d126 |
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 |
import streamlit as st
def input_form() -> dict:
"""Collect numeric-encoded patient features via sidebar widgets."""
st.sidebar.header("Patient Information")
return {
"gender": st.sidebar.selectbox("Gender", [(0.0, "Male"), (1.0, "Female")])[0],
"age": st.sidebar.slider("Age", 0.0, 100.0, 50.0),
"hypertension": st.sidebar.selectbox("Hypertension", [(0, "No"), (1, "Yes")])[0],
"heart_disease": st.sidebar.selectbox("Heart Disease", [(0, "No"), (1, "Yes")])[0],
"ever_married": st.sidebar.selectbox("Ever Married", [(0.0, "No"), (1.0, "Yes")])[0],
"work_type": st.sidebar.selectbox(
"Work Type",
[(0.0, "Private"), (1.0, "Self-employed"), (2.0, "Govt_job"), (3.0, "children"), (4.0, "Never_worked")]
)[0],
"Residence_type": st.sidebar.selectbox(
"Residence Type", [(0.0, "Urban"), (1.0, "Rural")]
)[0],
"avg_glucose_level": st.sidebar.number_input("Avg Glucose Level", 40.0, 300.0, 100.0),
"bmi": st.sidebar.number_input("BMI", 10.0, 60.0, 25.0),
"smoking_status": st.sidebar.selectbox(
"Smoking Status",
[(0.0, "formerly smoked"), (1.0, "never smoked"), (2.0, "smokes"), (3.0, "Unknown")]
)[0]
}
def display_result(label: str, proba: float):
"""Render prediction and confidence."""
st.header("Prediction Result")
st.markdown(f"**Stroke Type:** {label}")
st.markdown(f"**Confidence:** {proba:.1%}")
if proba < 0.5:
st.info("Model confidence is low — consider additional evaluation.")
|