Anupam202224 commited on
Commit
49dda5a
1 Parent(s): 6b051bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py CHANGED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+
5
+ # Load the saved model (from the Colab notebook)
6
+ with open("/content/logistic_model_pipeline.pkl2", "rb") as f:
7
+ model = pickle.load(f)
8
+
9
+ # Define the prediction function (from the Colab notebook)
10
+ def predict_heart_disease(age, sex_male, cigs_per_day, tot_chol, sys_bp, glucose):
11
+ # Create a DataFrame for the input
12
+ input_data = pd.DataFrame({
13
+ 'age': [age],
14
+ 'Sex_male': [sex_male],
15
+ 'cigsPerDay': [cigs_per_day],
16
+ 'totChol': [tot_chol],
17
+ 'sysBP': [sys_bp],
18
+ 'glucose': [glucose]
19
+ })
20
+
21
+ # Convert DataFrame to NumPy array
22
+ input_data_array = input_data.values
23
+
24
+ # Make prediction using the loaded model (replace with your model's prediction logic)
25
+ prob = model.predict_proba(input_data_array)[0, 1] # Assuming a probability prediction
26
+ return f"The probability of having heart disease is: {prob * 100:.2f}%"
27
+
28
+ # Create the Gradio interface
29
+ with gr.Blocks() as interface:
30
+ gr.Markdown("## Heart Disease Risk Prediction")
31
+ gr.Markdown("Enter your details below to check the probability of having heart disease.")
32
+
33
+ # Age input with helper text
34
+ age = gr.Slider(label="Age", minimum=20, maximum=100, value=50, step=1, info="Enter your age (20-100).")
35
+
36
+ # Sex input with helper text
37
+ sex_male = gr.Radio(label="Sex", choices=[1, 0], value=1, info="Select your sex: 1 for Male, 0 for Female.")
38
+
39
+ # Cigarettes per day input with helper text
40
+ cigs_per_day = gr.Slider(label="Cigarettes per Day", minimum=0, maximum=60, value=10, step=1, info="Enter the number of cigarettes you smoke per day (0-60).")
41
+
42
+ # Total cholesterol input with helper text
43
+ tot_chol = gr.Slider(label="Total Cholesterol (mg/dL)", minimum=100, maximum=400, value=200, step=1, info="Enter your total cholesterol level (100-400 mg/dL).")
44
+
45
+ # Systolic blood pressure input with helper text
46
+ sys_bp = gr.Slider(label="Systolic Blood Pressure (mmHg)", minimum=90, maximum=200, value=120, step=1, info="Enter your systolic blood pressure (90-200 mmHg).")
47
+
48
+ # Glucose input with helper text
49
+ glucose = gr.Slider(label="Glucose Level (mg/dL)", minimum=50, maximum=300, value=100, step=1, info="Enter your glucose level (50-300 mg/dL).")
50
+
51
+ # Predict button and output
52
+ predict_btn = gr.Button("Predict")
53
+ output = gr.Textbox(label="Prediction")
54
+
55
+ # Set up the prediction process
56
+ predict_btn.click(predict_heart_disease, inputs=[age, sex_male, cigs_per_day, tot_chol, sys_bp, glucose], outputs=output)
57
+
58
+ # Launch the interface
59
+ interface.launch(share=True)