Spaces:
Sleeping
Sleeping
File size: 1,983 Bytes
8c6a0d0 1efb9cc 8c6a0d0 7e0bf40 ae15045 8c6a0d0 7e0bf40 ae15045 7e0bf40 8c6a0d0 7e0bf40 113eee1 8c6a0d0 7e0bf40 302195e 7e0bf40 8c6a0d0 302195e 6938a8c 302195e 6938a8c 302195e 6938a8c | 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 | import gradio as gr
import numpy as np
# Load trained model parameters (assumed to be saved as .npy file)
theta_final = np.load("theta_final.npy") # Save your trained theta and upload it to HF Spaces
# Mean and standard deviation for normalization (precomputed from dataset)
mu = np.array([0.5] * 16) # Replace with actual values
sigma = np.array([0.2] * 16) # Replace with actual values
sigma = np.where(sigma == 0, 1, sigma) # Prevent division by zero
def predict_stroke_risk(*symptoms):
user_input = np.array([symptoms])
normalized_input = (user_input - mu) / sigma
normalized_input = np.c_[np.ones((normalized_input.shape[0], 1)), normalized_input] # Add bias term
y_pred = normalized_input @ theta_final
y_pred = np.clip(y_pred[0][0], 0, 100) # Ensure output is between 0% and 100%
return f"Predicted Stroke Risk: {y_pred:.2f}%"
# Symptoms list
symptoms = [
"Chest Pain", "Shortness of Breath", "Irregular Heartbeat", "Fatigue/Weakness",
"Dizziness", "Swelling/Edema", "Pain in Neck/Jaw/Shoulder/Back", "Excessive Sweating",
"Persistent Cough", "Nausea/Vomiting", "High Blood Pressure", "Chest Discomfort During Activity",
"Cold Hands/Feet", "Snoring/Sleep Apnea", "Anxiety/Feeling of Doom", "Age > 50"
]
with gr.Blocks(css="body {font-family: monospace; text-align: center; color: #3A78F2;}") as demo:
gr.Markdown("# Stroke Prediction")
gr.Markdown("### Select your symptoms:")
checkbox_list = []
with gr.Row():
for i in range(0, len(symptoms), 5): # 5 symptoms per column
with gr.Column():
for j in range(5):
if i + j < len(symptoms):
checkbox_list.append(gr.Checkbox(label=symptoms[i + j], value=False))
submit_button = gr.Button("Submit")
output_text = gr.Markdown("### Possibility of stroke: ______")
submit_button.click(fn=predict_stroke_risk, inputs=checkbox_list, outputs=output_text)
demo.launch()
|