3zoozzn commited on
Commit
7ddebf7
1 Parent(s): 6d886c8

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +48 -0
  2. model.pkl +3 -0
  3. requierments.txt +3 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import the necessary packages
2
+ import gradio as gr
3
+ import pickle
4
+ import pandas as pd
5
+
6
+ # Load the saved model using pickle
7
+ with open(r'Stroke_Prediction/model.pkl', 'rb') as file:
8
+ model = pickle.load(file)
9
+
10
+ # Define a function to make predictions
11
+
12
+
13
+ def predict(gender, age, hypertension, heart_disease, ever_married, work_type, residence_type, avg_glucose_level, bmi, smoking_status):
14
+ # Convert the input into a pandas DataFrame
15
+ input_df = pd.DataFrame([[gender, age, hypertension, heart_disease, ever_married, work_type, residence_type, avg_glucose_level, bmi, smoking_status]],
16
+ columns=['gender', 'age', 'hypertension', 'heart_disease', 'ever_married', 'work_type',
17
+ 'Residence_type', 'avg_glucose_level', 'bmi', 'smoking_status'])
18
+ # Predict the stroke probability
19
+ prediction = model.predict_proba(input_df)[0][1]
20
+ # Return the prediction
21
+ result = "The probability of stroke is {:.2f}%".format(prediction * 100) #to give a percentage
22
+ return result
23
+
24
+
25
+ # Create the input and output interfaces
26
+ gender = gr.inputs.Radio(choices=["Male", "Female"], label="Gender")
27
+ age = gr.inputs.Slider(minimum=0, maximum=100)
28
+ hypertension = gr.inputs.Radio(choices=["Yes", "No"], label="Hypertension")
29
+ heart_disease = gr.inputs.Radio(choices=["Yes", "No"], label="Heart Disease")
30
+ ever_married = gr.inputs.Radio(choices=["Yes", "No"], label="Ever Married")
31
+ work_type = gr.inputs.Dropdown(
32
+ ["Private", "Self-employed", "Govt_job", "Children", "Never_worked"], label="Work Type")
33
+ residence_type = gr.inputs.Radio(
34
+ choices=["Urban", "Rural"], label="Residence Type")
35
+ avg_glucose_level = gr.inputs.Number(label="Average Glucose Level")
36
+ bmi = gr.inputs.Slider(minimum=0, maximum=60, label="BMI")
37
+ smoking_status = gr.inputs.Dropdown(
38
+ ["formerly smoked", "never smoked", "smokes"], label="Smoking Status")
39
+
40
+ # Create the interface
41
+ inputs = [gender, age, hypertension, heart_disease, ever_married,
42
+ work_type, residence_type, avg_glucose_level, bmi, smoking_status]
43
+ outputs = gr.outputs.Textbox(label="Stroke Probability")
44
+
45
+ # Launch the interface
46
+ demo = gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="Stroke Prediction",
47
+ description="Fill in the details and click submit to check the probability of stroke")
48
+ demo.launch(share=True)
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:688d2f5b4ab52ec8fd1b4634c51428e71a1c82eddd943e6a849288673bebd0b6
3
+ size 257370
requierments.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ pickle
3
+ pandas