Zakia commited on
Commit
1754b09
1 Parent(s): 32d2e2e

cleaned code and set output for amputation risk

Browse files
Files changed (1) hide show
  1. app.py +8 -28
app.py CHANGED
@@ -17,42 +17,23 @@ def predict(model, input_df):
17
  predictions_df = predict_model(estimator=model, data=input_df)
18
  predict_label = predictions_df["Label"][0] # either 1 (amputation yes) or 0 (amputation no)
19
  predict_score = predictions_df["Score"][0] # the prediction (accuracy)
20
- return "<b>AMPUTATION RISK: " + str(predict_label) + " SCORE: "+str(predict_score)+"</b>"
21
-
22
-
23
-
24
-
25
- #input_dict = {"AGE": age, "GENDER_F": gender, "RACE_Asian": ,"RACE_Black": , "RACE_Coloured":, "RACE_Other":, "RACE_White":, "DIABETES_CLASS_Type 1 diabetes":}
26
-
27
-
28
-
29
-
30
 
31
 
32
  # the parameters in this function, actually gets the inputs for the prediction
33
  def predict_amputation(age, gender, race, diabetes_type):
34
- #input_dict = {"AGE": 70.0, "GENDER_F": 0.0, "RACE_Asian": 1.0, "RACE_Black": 0.0, "RACE_Coloured": 0.0, "RACE_Other": 0.0, "RACE_White": 0.0, "DIABETES_CLASS_Type 1 diabetes":0.0}
35
-
36
-
37
- #input_dict = {"AGE": 70.0, "GENDER": 0.0, "RACE": 1.0, "DIABETES_CLASS":0.0, "AMPUTATION":0}
38
-
39
-
40
- #input_dict = {"AGE": 70, "GENDER": "F", "RACE": "Asian", "DIABETES_CLASS":"Type 2 diabetes", "AMPUTATION":''}
41
-
42
-
43
- #input_dict = {"AGE": 80, "GENDER": "F", "RACE": "Asian", "DIABETES_CLASS":"Type 2 diabetes", "AMPUTATION":''}
44
-
45
  diabetes_class = "Type "+str(diabetes_type)+" diabetes"
46
  gender = gender[0]
47
  input_dict = {"AGE": age, "GENDER": gender, "RACE": race, "DIABETES_CLASS":diabetes_class, "AMPUTATION":''}
48
 
49
  input_df = pd.DataFrame([input_dict])
50
 
51
- return gender#str(predict(model=model, input_df=input_df))
52
- #return str("ALLAH " + " " + str(age) + " " + gender + " " + race + diabetes_type)
53
- #return diabetes_type
54
- #return "ALLAH: "+str(predict(model=model, input_df=input_df)) # calls the predict function when 'submit' is clicked
55
-
56
 
57
 
58
 
@@ -63,8 +44,6 @@ description = "A diabetes-related amputation machine learning model trained on t
63
  article = "<p style='text-align: center'><span style='font-size: 15pt;'>Copyright &copy; DIARC. 2021. All Rights Reserved. Contact Us: <a href='mailto:smtshali@wol.co.za'>Dr Sifisiso Mtshali</a> or <a href='mailto:mahomedo@ukzn.ac.za'>Dr Ozayr Mahomed</a></span></p>"
64
 
65
 
66
-
67
-
68
  iface = gr.Interface(
69
  fn=predict_amputation,
70
  title=title,
@@ -82,6 +61,7 @@ iface = gr.Interface(
82
  ],
83
  )
84
 
 
85
  iface.test_launch()
86
  if __name__ == "__main__":
87
  iface.launch()
 
17
  predictions_df = predict_model(estimator=model, data=input_df)
18
  predict_label = predictions_df["Label"][0] # either 1 (amputation yes) or 0 (amputation no)
19
  predict_score = predictions_df["Score"][0] # the prediction (accuracy)
20
+ amputation_risk = ""
21
+ if predict_label == 1:
22
+ amputation_risk = "YES"
23
+ else:
24
+ amputation_risk = "NO"
25
+ return "AMPUTATION RISK: " + amputation_risk + " SCORE: "+str(predict_score)
 
 
 
 
26
 
27
 
28
  # the parameters in this function, actually gets the inputs for the prediction
29
  def predict_amputation(age, gender, race, diabetes_type):
 
 
 
 
 
 
 
 
 
 
 
30
  diabetes_class = "Type "+str(diabetes_type)+" diabetes"
31
  gender = gender[0]
32
  input_dict = {"AGE": age, "GENDER": gender, "RACE": race, "DIABETES_CLASS":diabetes_class, "AMPUTATION":''}
33
 
34
  input_df = pd.DataFrame([input_dict])
35
 
36
+ return str(predict(model=model, input_df=input_df)) # calls the predict function when 'submit' is clicked
 
 
 
 
37
 
38
 
39
 
 
44
  article = "<p style='text-align: center'><span style='font-size: 15pt;'>Copyright &copy; DIARC. 2021. All Rights Reserved. Contact Us: <a href='mailto:smtshali@wol.co.za'>Dr Sifisiso Mtshali</a> or <a href='mailto:mahomedo@ukzn.ac.za'>Dr Ozayr Mahomed</a></span></p>"
45
 
46
 
 
 
47
  iface = gr.Interface(
48
  fn=predict_amputation,
49
  title=title,
 
61
  ],
62
  )
63
 
64
+
65
  iface.test_launch()
66
  if __name__ == "__main__":
67
  iface.launch()