import gradio as gr import numpy as np import pickle import time # Load the trained models with open("stroke_clf.pkl", "rb") as f: clf_model = pickle.load(f) with open("stroke_reg.pkl", "rb") as f: reg_model = pickle.load(f) # Custom CSS for enhanced styling custom_css = """ .gradio-container { max-width: 1200px !important; margin-left: auto !important; margin-right: auto !important; } .container { margin: 0 auto !important; padding: 2rem !important; } .question-group { border: 1px solid #e5e7eb !important; border-radius: 8px !important; padding: 1.5rem !important; margin-bottom: 1.5rem !important; background: white !important; } .footer { text-align: center !important; padding: 2rem !important; background: #f8fafc !important; border-top: 1px solid #e5e7eb !important; } """ def predict_stroke(*inputs): """ Enhanced prediction function with detailed output formatting """ age = inputs[0] features = [1 if x == "Yes" else 0 for x in inputs[1:]] + [age] sample_input = np.array([features]) # Get predictions classification_result = clf_model.predict(sample_input)[0] regression_result = reg_model.predict(sample_input)[0] risk_percentage = round(regression_result, 2) # Simulate processing time.sleep(1.5) # Enhanced results formatting if classification_result == 1: severity = "High" if risk_percentage > 70 else "Moderate" color = "red" if risk_percentage > 70 else "orange" result = f"""
Risk Level: {risk_percentage}%
Status: Immediate Attention Recommended
Risk Level: {risk_percentage}%
Status: Healthy Range
Welcome to EarlyMed—a VIT-AP University initiative using advanced AI to help you understand your stroke risk factors.
This tool is designed for educational purposes and early awareness only. It is not a substitute for professional medical diagnosis or advice.
© 2025 EarlyMed - VIT-AP University | All Rights Reserved