Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load trained model
|
| 6 |
+
model = joblib.load("xgboost_model.pkl") # Make sure this file is in same directory
|
| 7 |
+
|
| 8 |
+
# Prediction function
|
| 9 |
+
def predict_alzheimers(age, gender, bmi, smoking, alcohol, diabetes, hypertension, family_history, cognitive_score, apoe4):
|
| 10 |
+
# Convert inputs
|
| 11 |
+
gender = 1 if gender == "Male" else 0
|
| 12 |
+
smoking = {"Non-Smoker": 0, "Smoker": 1, "Former Smoker": 2}[smoking]
|
| 13 |
+
alcohol = {"None": 0, "Moderate": 1, "Heavy": 2}[alcohol]
|
| 14 |
+
diabetes = 1 if diabetes == "Yes" else 0
|
| 15 |
+
hypertension = 1 if hypertension == "Yes" else 0
|
| 16 |
+
family_history = 1 if family_history == "Yes" else 0
|
| 17 |
+
apoe4 = 1 if apoe4 == "Yes" else 0
|
| 18 |
+
|
| 19 |
+
features = np.array([[age, gender, bmi, smoking, alcohol, diabetes, hypertension, family_history, cognitive_score, apoe4]])
|
| 20 |
+
prediction = model.predict(features)[0]
|
| 21 |
+
return "🧠 Likely Alzheimer’s Positive" if prediction == 1 else "✅ Likely Alzheimer’s Negative"
|
| 22 |
+
|
| 23 |
+
# Gradio UI
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=predict_alzheimers,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Number(label="Age"),
|
| 28 |
+
gr.Radio(["Male", "Female"], label="Gender"),
|
| 29 |
+
gr.Number(label="BMI"),
|
| 30 |
+
gr.Radio(["Non-Smoker", "Smoker", "Former Smoker"], label="Smoking Status"),
|
| 31 |
+
gr.Radio(["None", "Moderate", "Heavy"], label="Alcohol Consumption"),
|
| 32 |
+
gr.Radio(["Yes", "No"], label="Diabetes"),
|
| 33 |
+
gr.Radio(["Yes", "No"], label="Hypertension"),
|
| 34 |
+
gr.Radio(["Yes", "No"], label="Family History of Alzheimer’s"),
|
| 35 |
+
gr.Number(label="Cognitive Test Score"),
|
| 36 |
+
gr.Radio(["Yes", "No"], label="APOE-ε4 allele Present?")
|
| 37 |
+
],
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="Alzheimer’s Prediction App",
|
| 40 |
+
description="Enter patient details to predict Alzheimer’s risk using XGBoost model"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
interface.launch()
|