| |
| |
|
|
|
|
| import gradio as gr |
| import pandas as pd |
| from pycaret.classification import load_model, predict_model |
|
|
|
|
| |
| model = load_model('tuned_blend_specific_model_19112021') |
|
|
|
|
| |
| def predict(model, input_df): |
| predictions_df = predict_model(estimator=model, data=input_df) |
| predict_label = predictions_df["Label"][0] |
| predict_score = predictions_df["Score"][0] |
| amputation_risk = "" |
| if predict_label == 1: |
| amputation_risk = "YES" |
| amputation_risk_output = "Amputation Risk: " + amputation_risk |
| score_output = "Score: "+str(predict_score) |
| |
| html = "<div style='background-color:rgb(153, 0, 0);color:white;font-size:20px;'>" + amputation_risk_output + "<br>" + score_output + "<br>" + "</div>" |
| else: |
| amputation_risk = "NO" |
| amputation_risk_output = "Amputation Risk: " + amputation_risk |
| score_output = "Score: "+str(predict_score) |
| html = "<div style='background-color:rgba(16, 185, 129, var(--tw-bg-opacity));color:white;font-size:20px;'>" + amputation_risk_output + "<br>" + score_output + "<br>" + "</div>" |
| |
| return html |
|
|
|
|
| |
| 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]) |
| |
| |
| return str(predict(model=model, input_df=input_df)) |
|
|
|
|
| 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 © DIARC. 2021. All Rights Reserved. Contact Us: <a href='mailto:smtshali@wol.co.za'>Dr Sifiso 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="html", |
| theme="grass", |
| examples=[ |
| [77, "Female", "Asian", 2], |
| [28, "Male", "Black", 1], |
| [75, "Male", "White", 2], |
| [59, "Male", "Coloured", 1], |
| [73, "Female", "Other", 1], |
| [4, "Female", "Black", 2], |
| [65, "Male", "Coloured", 2], |
| ], |
| ) |
|
|
|
|
| iface.test_launch() |
| if __name__ == "__main__": |
| iface.launch() |
| |