high77 commited on
Commit
6b881c1
·
verified ·
1 Parent(s): d8ebc66

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ # Load saved artifacts
7
+ model = joblib.load('xgb_model.pkl')
8
+ scaler = joblib.load('scaler.pkl')
9
+ label_enc = joblib.load('label_encoder.pkl')
10
+
11
+ # List of feature names in correct order (exclude Patient Id and target)
12
+ feature_names = [
13
+ 'Age', 'Total cholesterol', 'HDL', 'LDL', 'VLDL', 'TRIGLYCERIDES',
14
+ 'before glycemic control random blood sugar', 'before glycemic control HbA1c',
15
+ 'alcohol consumption', 'family_history_diabetes', 'Gender_FEMALE', 'Gender_MALE',
16
+ 'dietary habits_non-vegetarian', 'dietary habits_non-vegetarian ', 'dietary habits_vegetarian',
17
+ 'smoking status_no', 'smoking status_yes',
18
+ 'family_history_cardiovascular_disease_no', 'family_history_cardiovascular_disease_yes'
19
+ ]
20
+
21
+ # Function to predict diabetes status
22
+ def predict_diabetes(*inputs):
23
+ # Convert inputs to dataframe
24
+ input_df = pd.DataFrame([inputs], columns=feature_names)
25
+
26
+ # Scale input features
27
+ scaled_features = scaler.transform(input_df)
28
+
29
+ # Predict label index
30
+ pred_encoded = model.predict(scaled_features)[0]
31
+
32
+ # Decode label to original class
33
+ pred_label = label_enc.inverse_transform([pred_encoded])[0]
34
+
35
+ return pred_label
36
+
37
+ # Define Gradio input components
38
+ inputs = [
39
+ gr.Number(label=feature) for feature in feature_names
40
+ ]
41
+
42
+ # Gradio interface
43
+ title = "Diabetes Predictor"
44
+ description = """
45
+ Developed by Dr. Vinod Kumar Yata's research group
46
+ School of Allied and Healthcare Sciences, Malla Reddy University, Hyderabad, India
47
+
48
+ ⚠️ Warning:
49
+ This is an experimental tool and should not be used for medical diagnosis.
50
+ Always consult a licensed healthcare provider for medical advice.
51
+ """
52
+
53
+ iface = gr.Interface(
54
+ fn=predict_diabetes,
55
+ inputs=inputs,
56
+ outputs=gr.Textbox(label="Predicted Diabetes Status"),
57
+ title=title,
58
+ description=description,
59
+ theme="default"
60
+ )
61
+
62
+ if __name__ == "__main__":
63
+ iface.launch()