File size: 2,794 Bytes
1e20656
 
5c5b397
 
 
aae6493
c05f598
 
 
 
b8f8c32
c05f598
 
 
 
 
29e3408
 
1754b09
 
 
873b4ad
1754b09
 
873b4ad
 
 
 
c05f598
 
 
 
8f428af
32d2e2e
e2fec6b
12b6b1a
9dee9a0
e2fec6b
873b4ad
1754b09
4920d02
a52d12d
4920d02
12cd932
16b729b
7d9a734
66da2fe
c7a8f72
 
12cd932
8181851
12cd932
 
c7a8f72
36ce2c2
 
 
 
27bf8b4
32d2e2e
5e90216
 
 
 
 
 
 
 
a61a907
1754b09
a61a907
0707d46
36ce2c2
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Bismillahir Rahmaanir Raheem
#Almadadh Ya Gause RadiAllahu Ta'alah Anh - Ameen


import gradio as gr
import pandas as pd
from pycaret.classification import load_model, predict_model


# load the trained model for predictions
model = load_model('tuned_blend_specific_model_19112021')


# define the function to call 
def predict(model, input_df):
	predictions_df = predict_model(estimator=model, data=input_df)
	predict_label = predictions_df["Label"][0] # either 1 (amputation yes) or 0 (amputation no)
	predict_score = predictions_df["Score"][0] # the prediction (accuracy)
	amputation_risk = ""
	if predict_label == 1:
		amputation_risk = "YES"
		output = "<div style='background-color:green;'>"+"AMPUTATION RISK: " + amputation_risk + " SCORE: "+str(predict_score)+"</div>"
	else:
		amputation_risk = "NO"
		output = "<div style='background-color:green;'>"+"AMPUTATION RISK: " + amputation_risk + " SCORE: "+str(predict_score)+"</div>"
	
	
	return output#"AMPUTATION RISK: " + amputation_risk + " SCORE: "+str(predict_score)  


# the parameters in this function, actually gets the inputs for the prediction 
def predict_amputation(age, gender, race, diabetes_type):
	diabetes_class = "Type "+str(diabetes_type)+" diabetes"
	gender = gender[0]
	input_dict = {"AGE": age, "GENDER": gender, "RACE": race, "DIABETES_CLASS":diabetes_class, "AMPUTATION":''}
	
	input_df = pd.DataFrame([input_dict])
	
	# output 
	return str(predict(model=model, input_df=input_df)) # calls the predict function when 'submit' is clicked


title = "DIabetes-related Amputation Risk Calculator (DIARC)"

description = "A diabetes-related amputation machine learning model trained on the diabetes dataset from the Inkosi Albert Luthuli Central Hospital (IALCH) in Durban, KwaZulu-Natal, South Africa."

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>"


iface = gr.Interface(
		fn=predict_amputation, 
		title=title, 
		description=description, 
		article=article,
		inputs=[gr.inputs.Slider(minimum=0,maximum=100, step=1, default=0, label="Age"), 
		        gr.inputs.Dropdown(["Female", "Male"], default="Female", label="Gender"), 
				gr.inputs.Dropdown(["Asian", "Black", "Coloured", "White", "Other"], default="Asian", label="Race"), 
				gr.inputs.Dropdown(["1", "2"], default="1", label="Diabetes Type")], 
		outputs="text",
		theme="huggingface",
		examples=[
			[50, "Male", "Black", 2],
			[76, "Female", "Asian", 2],
			[12, "Female", "White", 1],
			[30, "Male", "Coloured", 1],
			[65, "Female", "Other", 2],
		],
)


iface.test_launch()		
if __name__ == "__main__":
	iface.launch()