Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import pickle | |
| # Load models | |
| diabetes_model = pickle.load(open("diabetes_model.pkl", "rb")) | |
| heart_model = pickle.load(open("heart_model.pkl", "rb")) | |
| parkinsons_model = pickle.load(open("parkinsons_model.pkl", "rb")) | |
| # Prediction functions | |
| def predict_diabetes(*inputs): | |
| input_data = np.array(inputs).reshape(1, -1) | |
| prediction = diabetes_model.predict(input_data)[0] | |
| return "β <b style='color:#1e90ff;'>You are Diabetic</b>" if prediction == 1 else "π <b style='color:#20bf6b;'>You are Not Diabetic</b>" | |
| def predict_heart(*inputs): | |
| input_data = np.array(inputs).reshape(1, -1) | |
| prediction = heart_model.predict(input_data)[0] | |
| return "β€οΈ <b style='color:#e84118;'>Heart Disease Detected</b>" if prediction == 1 else "π <b style='color:#44bd32;'>No Heart Disease</b>" | |
| def predict_parkinsons(*inputs): | |
| input_data = np.array(inputs).reshape(1, -1) | |
| prediction = parkinsons_model.predict(input_data)[0] | |
| return "π§ <b style='color:#8c7ae6;'>Parkinson's Detected</b>" if prediction == 1 else "π <b style='color:#0097e6;'>No Parkinson's</b>" | |
| with gr.Blocks(theme="default", css=""" | |
| body { | |
| background: linear-gradient(to right, #74ebd5, #ACB6E5); | |
| font-family: 'Segoe UI', sans-serif; | |
| color: #2c3e50; | |
| } | |
| .gr-button { | |
| background: linear-gradient(to right, #2980b9, #6dd5fa); | |
| color: white !important; | |
| font-weight: bold; | |
| border-radius: 10px !important; | |
| border: none; | |
| padding: 14px 24px !important; | |
| box-shadow: 0 4px 12px rgba(0,0,0,0.15); | |
| } | |
| .gr-input, .gr-number, .gr-textbox, .gr-dropdown { | |
| background-color: #ffffff !important; | |
| border: 2px solid #dff9fb !important; | |
| border-radius: 12px !important; | |
| color: #2c3e50 !important; | |
| padding: 10px !important; | |
| font-size: 16px !important; | |
| box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); | |
| } | |
| .gr-markdown h1, .gr-markdown h3, h1, h3 { | |
| text-align: center; | |
| color: #2c3e50; | |
| } | |
| .card { | |
| background-color: #ffffff; | |
| border-radius: 16px; | |
| padding: 20px; | |
| margin-top: 20px; | |
| box-shadow: 0 8px 16px rgba(0,0,0,0.1); | |
| } | |
| """) as demo: | |
| gr.Markdown("<h1 style='text-align: center;'>π Multi-Disease Prediction App</h1>") | |
| gr.Markdown("<p style='text-align: center;'>Select a disease, fill in the data, and get instant AI-based predictions.</p>") | |
| disease = gr.Dropdown(["Diabetes", "Heart Disease", "Parkinson's"], label="π Select Disease") | |
| output = gr.HTML("<b style='color:#2c3e50;'>Prediction will appear here</b>") | |
| with gr.Group(visible=False) as diabetes_group: | |
| gr.Markdown("### π©Ί <span style='color:#2980b9;'>Diabetes Inputs</span>") | |
| diabetes_inputs = [ | |
| gr.Number(label=label) for label in [ | |
| "Pregnancies", "Glucose", "Blood Pressure", "Skin Thickness", | |
| "Insulin", "BMI", "Diabetes Pedigree Function", "Age" | |
| ] | |
| ] | |
| diabetes_btn = gr.Button("π Predict Diabetes") | |
| with gr.Group(visible=False) as heart_group: | |
| gr.Markdown("### β€οΈ <span style='color:#c23616;'>Heart Disease Inputs</span>") | |
| heart_inputs = [ | |
| gr.Number(label=label) for label in [ | |
| "Age", "Sex (1=Male, 0=Female)", "Chest Pain Type", "Resting BP", "Cholesterol", | |
| "Fasting BS (1=True, 0=False)", "Rest ECG", "Max HR", "Exercise Angina (1=True, 0=False)", | |
| "Oldpeak", "ST Slope", "Major Vessels", "Thal" | |
| ] | |
| ] | |
| heart_btn = gr.Button("π Predict Heart Disease") | |
| with gr.Group(visible=False) as parkinsons_group: | |
| gr.Markdown("### π§ <span style='color:#8c7ae6;'>Parkinson's Inputs</span>") | |
| parkinsons_inputs = [ | |
| gr.Number(label=label) for label in [ | |
| "MDVP:Fo(Hz)", "MDVP:Fhi(Hz)", "MDVP:Flo(Hz)", "MDVP:Jitter(%)", | |
| "MDVP:Jitter(Abs)", "MDVP:RAP", "MDVP:PPQ", "Jitter:DDP", | |
| "MDVP:Shimmer", "MDVP:Shimmer(dB)", "Shimmer:APQ3", | |
| "Shimmer:APQ5", "MDVP:APQ", "Shimmer:DDA", "NHR", | |
| "HNR", "RPDE", "DFA", "spread1", "spread2", "D2", "PPE" | |
| ] | |
| ] | |
| parkinsons_btn = gr.Button("π Predict Parkinson's") | |
| def show_form(choice): | |
| return ( | |
| gr.update(visible=choice == "Diabetes"), | |
| gr.update(visible=choice == "Heart Disease"), | |
| gr.update(visible=choice == "Parkinson's") | |
| ) | |
| disease.change(show_form, disease, [diabetes_group, heart_group, parkinsons_group]) | |
| diabetes_btn.click(predict_diabetes, diabetes_inputs, output) | |
| heart_btn.click(predict_heart, heart_inputs, output) | |
| parkinsons_btn.click(predict_parkinsons, parkinsons_inputs, output) | |
| demo.launch() | |