#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) return "AMPUTATION RISK: " + str(predict_label) + " SCORE: "+str(predict_score)+"" #input_dict = {"AGE": age, "GENDER_F": gender, "RACE_Asian": ,"RACE_Black": , "RACE_Coloured":, "RACE_Other":, "RACE_White":, "DIABETES_CLASS_Type 1 diabetes":} # the parameters in this function, actually gets the inputs for the prediction def predict_amputation(age, gender, race, diabetes_type): #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} #input_dict = {"AGE": 70.0, "GENDER": 0.0, "RACE": 1.0, "DIABETES_CLASS":0.0, "AMPUTATION":0} #input_dict = {"AGE": 70, "GENDER": "F", "RACE": "Asian", "DIABETES_CLASS":"Type 2 diabetes", "AMPUTATION":''} #input_dict = {"AGE": 80, "GENDER": "F", "RACE": "Asian", "DIABETES_CLASS":"Type 2 diabetes", "AMPUTATION":''} 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 gender#str(predict(model=model, input_df=input_df)) #return str("ALLAH " + " " + str(age) + " " + gender + " " + race + diabetes_type) #return diabetes_type #return "ALLAH: "+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 = "
Copyright © DIARC. 2021. All Rights Reserved. Contact Us: Dr Sifisiso Mtshali or Dr Ozayr Mahomed
" 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()