ArpitChb commited on
Commit
672d7d2
·
verified ·
1 Parent(s): f1c72a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -23
app.py CHANGED
@@ -2,40 +2,47 @@ import gradio as gr
2
  import pandas as pd
3
  import pickle
4
  import numpy as np
5
- import numpy as np
6
  import pandas as pd
7
 
8
-
9
-
10
- # Load your ML model (replace 'model.pkl' with your model file)
11
  with open("model.pkl", "rb") as model_file:
12
  model = pickle.load(model_file)
13
 
14
- # Define your prediction function
15
- def predict_health_risk(age, activity_level, diet_score, health_history):
16
  """
17
- Predict health risk based on user input.
18
  """
19
- input_data = np.array([[age, activity_level, diet_score, health_history]])
20
- prediction = model.predict(input_data)
21
- return f"Predicted Risk: {prediction[0]}"
 
 
 
22
 
23
- # Set up Gradio interface
24
  with gr.Blocks() as demo:
25
- gr.Markdown("## Personalized Health Tracker")
26
- gr.Markdown("Enter your details to predict health risks.")
27
-
28
  with gr.Row():
29
- age = gr.Number(label="Age", value=30)
30
- activity_level = gr.Number(label="Activity Level (1-10)", value=5)
31
- diet_score = gr.Number(label="Diet Score (1-10)", value=5)
32
- health_history = gr.Number(label="Health History (e.g., 1 for Yes, 0 for No)", value=0)
33
-
34
- predict_btn = gr.Button("Predict Risk")
35
- output = gr.Textbox(label="Risk Score")
36
-
37
- predict_btn.click(predict_health_risk, inputs=[age, activity_level, diet_score, health_history], outputs=output)
 
 
 
 
 
 
38
 
39
  # Launch the app
40
  if __name__ == "__main__":
41
  demo.launch()
 
 
2
  import pandas as pd
3
  import pickle
4
  import numpy as np
 
5
  import pandas as pd
6
 
7
+ # Load the model
 
 
8
  with open("model.pkl", "rb") as model_file:
9
  model = pickle.load(model_file)
10
 
11
+ # Define the prediction function
12
+ def predict_diabetes_risk(pregnancies, glucose, blood_pressure, insulin, bmi, age):
13
  """
14
+ Predict diabetes risk based on user inputs.
15
  """
16
+ # Prepare input data
17
+ input_data = np.array([[pregnancies, glucose, blood_pressure, insulin, bmi, age]])
18
+ prediction = model.predict(input_data) # Assuming the model has a `predict` method
19
+ probability = model.predict_proba(input_data)[0][1] # If available, get prediction probability
20
+ risk_level = "High Risk" if prediction[0] == 1 else "Low Risk"
21
+ return f"Risk Level: {risk_level} (Probability: {probability:.2%})"
22
 
23
+ # Set up the Gradio interface
24
  with gr.Blocks() as demo:
25
+ gr.Markdown("## Diabetes Risk Predictor")
26
+ gr.Markdown("Enter the following details to predict your risk of diabetes.")
27
+
28
  with gr.Row():
29
+ pregnancies = gr.Number(label="Pregnancies", value=0)
30
+ glucose = gr.Number(label="Glucose Level", value=0)
31
+ blood_pressure = gr.Number(label="Blood Pressure Level", value=0)
32
+ insulin = gr.Number(label="Insulin Level", value=0)
33
+ bmi = gr.Number(label="BMI (Body Mass Index)", value=0)
34
+ age = gr.Number(label="Age", value=0)
35
+
36
+ predict_button = gr.Button("Predict Risk")
37
+ output = gr.Textbox(label="Prediction Result")
38
+
39
+ predict_button.click(
40
+ predict_diabetes_risk,
41
+ inputs=[pregnancies, glucose, blood_pressure, insulin, bmi, age],
42
+ outputs=output,
43
+ )
44
 
45
  # Launch the app
46
  if __name__ == "__main__":
47
  demo.launch()
48
+