File size: 1,504 Bytes
163b90f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766fbf5
 
 
 
 
 
 
163b90f
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import numpy as np
import pickle

# Load the trained model
with open('heart_disease_model.pkl', 'rb') as file:
    model = pickle.load(file)

# Define the prediction function
def predict_heart_disease(male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI):
    male = 1 if male == 'Male' else 0
    currentSmoker = 1 if currentSmoker == "Yes" else 0
    BPMeds = 1 if BPMeds == "Yes" else 0
    prevalentStroke = 1 if prevalentStroke == "Yes" else 0
    prevalentHyp = 1 if prevalentHyp == "Yes" else 0
    diabetes = 1 if diabetes == "Yes" else 0
    input_data = np.array([[male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI]])
    prediction = model.predict(input_data)
    return 'Heart Disease' if prediction[0] == 1 else 'No Heart Disease'

# Define the input components
inputs = [
    gr.Radio(choices=["Male", "Female"], label="Sex"),
    gr.Number(label="Age"),
    gr.Text(label="Do you smoke? (Yes/No)"),
    gr.Number(label="Number of ciggerates a day"),
    gr.Text(label="Do you take BP medicines?"),
    gr.text(label="Have you hade strokes previously?"),
    gr.text(label="Have you hade High BP previously?"),
    gr.text(label="Do you have Diabetes?"),
    gr.Number(value=float, label="BMI")

]

# Define the output component
outputs = gr.Textbox(label="Prediction")

# Create and launch the Gradio interface
gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=outputs).launch()