jsr90 commited on
Commit
b066f66
1 Parent(s): 982a2eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -29
app.py CHANGED
@@ -2,24 +2,22 @@ import gradio as gr
2
  import pandas as pd
3
  from joblib import load
4
 
5
-
6
-
7
- def cardio(age,is_male,ap_hi,ap_lo,cholesterol,gluc,smoke,alco,active,height,weight,BMI):
8
  model = load('cardiosight.joblib')
9
  df = pd.DataFrame.from_dict(
10
  {
11
  "age": [age*365],
12
- "gender":[0 if is_male else 1],
13
  "ap_hi": [ap_hi],
14
  "ap_lo": [ap_lo],
15
  "cholesterol": [cholesterol + 1],
16
  "gluc": [gluc + 1],
17
- "smoke":[1 if smoke else 0],
18
- "alco": [1 if alco else 0],
19
- "active": [1 if active else 0],
20
  "newvalues_height": [height],
21
  "newvalues_weight": [weight],
22
- "New_values_BMI": [BMI],
23
 
24
  }
25
  )
@@ -29,37 +27,35 @@ def cardio(age,is_male,ap_hi,ap_lo,cholesterol,gluc,smoke,alco,active,height,wei
29
  predicted="Tiene un riesgo alto de sufrir problemas cardiovasculares"
30
  else:
31
  predicted="Su riesgo de sufrir problemas cardiovasculares es muy bajo. Siga así."
32
- return predicted
33
 
34
  iface = gr.Interface(
35
  cardio,
36
  [
37
- gr.inputs.Slider(1,99,label="Age"),
38
- "checkbox",
39
- gr.inputs.Slider(10,250,label="Diastolic Preassure"),
40
- gr.inputs.Slider(10,250,label="Sistolic Preassure"),
41
- gr.inputs.Radio(["Normal","High","Very High"],type="index",label="Cholesterol"),
42
- gr.inputs.Radio(["Normal","High","Very High"],type="index",label="Glucosa Level"),
43
- "checkbox",
44
- "checkbox",
45
- "checkbox",
46
- gr.inputs.Slider(30,220,label="Height in cm"),
47
- gr.inputs.Slider(10,300,label="Weight in Kg"),
48
- gr.inputs.Slider(1,50,label="BMI"),
49
  ],
50
 
51
  "text",
52
  examples=[
53
- [40,True,120,80,"High","Normal",0,0,1,168,62,21],
54
- [35,False,150,60,"Very High","Normal",0,0,1,143,52,31],
55
- [60,True,160,70,"High","High",1,1,0,185,90,23],
 
 
 
56
  ],
57
- interpretation="default",
58
  title = 'Calculadora de Riesgo Cardiovascular mediante Inteligencia Artificial',
59
- description = 'El proyecto de CARDIOSIGHT nace debido a la presente necesidad en nuestro país de crear métodos y herramientas de identificación temprana para los individuos con alto riesgo de sufrir enfermedades cardiovasculares. Con el fin de prevenir eventos cardíacos primarios y ayudar a disminuir la incidencia de nuevos casos, por medio de hábitos de prevención. Mas información: https://saturdays.ai/2022/03/16/cardiosight-machine-learning-para-calcular-riesgo-cardiovascular/',
60
- theme = 'grass'
61
  )
62
 
63
-
64
-
65
  iface.launch()
 
2
  import pandas as pd
3
  from joblib import load
4
 
5
+ def cardio(age,gender,ap_hi,ap_lo,cholesterol,gluc,smoke,alco,active,height,weight):
 
 
6
  model = load('cardiosight.joblib')
7
  df = pd.DataFrame.from_dict(
8
  {
9
  "age": [age*365],
10
+ "gender":[0 if gender=='Male' else 1],
11
  "ap_hi": [ap_hi],
12
  "ap_lo": [ap_lo],
13
  "cholesterol": [cholesterol + 1],
14
  "gluc": [gluc + 1],
15
+ "smoke":[1 if smoke=='Yes' else 0],
16
+ "alco": [1 if alco=='Yes' else 0],
17
+ "active": [1 if active=='Yes' else 0],
18
  "newvalues_height": [height],
19
  "newvalues_weight": [weight],
20
+ "New_values_BMI": weight/((height/100)**2),
21
 
22
  }
23
  )
 
27
  predicted="Tiene un riesgo alto de sufrir problemas cardiovasculares"
28
  else:
29
  predicted="Su riesgo de sufrir problemas cardiovasculares es muy bajo. Siga así."
30
+ return "Su IMC es de "+str(round(df['New_values_BMI'][0], 2))+'. '+predicted
31
 
32
  iface = gr.Interface(
33
  cardio,
34
  [
35
+ gr.Slider(1,99,label="Age"),
36
+ gr.Dropdown(choices=['Male', 'Female'], label='Gender', value='Female'),
37
+ gr.Slider(10,250,label="Diastolic Preassure"),
38
+ gr.Slider(10,250,label="Sistolic Preassure"),
39
+ gr.Radio(["Normal","High","Very High"],type="index",label="Cholesterol"),
40
+ gr.Radio(["Normal","High","Very High"],type="index",label="Glucosa Level"),
41
+ gr.Dropdown(choices=['Yes', 'No'], label='Smoke', value='No'),
42
+ gr.Dropdown(choices=['Yes', 'No'], label='Alcohol', value='No'),
43
+ gr.Dropdown(choices=['Yes', 'No'], label='Active', value='Yes'),
44
+ gr.Slider(30,220,label="Height in cm"),
45
+ gr.Slider(10,300,label="Weight in Kg"),
 
46
  ],
47
 
48
  "text",
49
  examples=[
50
+ [20,'Male',110,60,"Normal","Normal",'No','No','Yes',168,60],
51
+ [30,'Female',120,70,"High","High",'No','Yes','Yes',143,70],
52
+ [40,'Male',130,80,"Very High","Very High",'Yes','Yes','No',185,80],
53
+ [50,'Female',140,90,"Normal","High",'Yes','No','No',165,90],
54
+ [60,'Male',150,100,"High","Very High",'No','No','Yes',175,100],
55
+ [70,'Female',160,90,"Very High","Normal",'Yes','Yes','No',185,110],
56
  ],
 
57
  title = 'Calculadora de Riesgo Cardiovascular mediante Inteligencia Artificial',
58
+ description = 'Duplicación del proyecto de CARDIOSIGHT. He cambiado los botones tipo check por dropdown y calculado el IMC a partir de la altura y el peso. Más información: https://saturdays.ai/2022/03/16/cardiosight-machine-learning-para-calcular-riesgo-cardiovascular/'
 
59
  )
60
 
 
 
61
  iface.launch()