# import gradio as gr # import pickle # import pandas as pd # import numpy as np # import lightgbm as lgb # from autogluon.tabular import TabularPredictor # loaded_model = pickle.load(open('Autogluon/models/XGBoost_BAG_L1/model.pkl', 'rb')) # # pred_proba_radio = loaded_model.predict_proba(X_test_radio) # # pred_proba_radio # def relapse(age, pathology, B_symptoms): # X_test_radio = pd.DataFrame.from_dict( # { # "Age": [age], # "pathology_Nodular Sclerosis cHL": [1 if pathology == 'Nodular' else 0], # "pathology_others": [1 if pathology == 'Others' else 0], # "B_symptoms_Yes" : [1 if B_symptoms else 0], # 'radio_Yes': [1] # } # ) # X_test_no_radio = pd.DataFrame.from_dict( # { # "Age": [age], # "pathology_Nodular Sclerosis cHL": [1 if pathology == 'Nodular' else 0], # "pathology_others": [1 if pathology == 'Others' else 0], # "B_symptoms_Yes" : [1 if B_symptoms else 0], # 'radio_Yes': [0] # } # ) # pred_proba_radio = loaded_model.predict_proba(X_test_radio) # pred_proba_radio = round(np.ndarray.item(pred_proba_radio),2) # pred_radio = loaded_model.predict(X_test_radio) # pred_proba_no_radio = loaded_model.predict_proba(X_test_no_radio) # pred_proba_no_radio = round(np.ndarray.item(pred_proba_no_radio),2) # pred_no_radio = loaded_model.predict(X_test_no_radio) # return {"Radio": pred_proba_radio, "No Radio": pred_proba_no_radio} # iface = gr.Interface( # title = 'Should we omit radiotherapy?', # description = 'This model predicts relapse according to risk factors.', # fn=relapse, # inputs= [ # gr.Number(label = 'Age', show_label = True), # gr.Radio( choices = ['Mixed cellularity', 'Nodular', 'Others'], label = 'Pathology', show_label = True), # gr.Checkbox(label = 'B_symptoms', show_label = True)], # outputs = gr.Label(label = 'Has a higher probability of relapse', show_label = True) # ,live = True, # interpretation="default", # ) # iface.launch() import gradio as gr import pandas as pd import numpy as np from autogluon.tabular import TabularPredictor predictor_1 = TabularPredictor.load("no_path_PET_1/") predictor_2 = TabularPredictor.load("no_path_PET_2/") predictor_3 = TabularPredictor.load("no_path_PET_3/") predictor_4 = TabularPredictor.load("no_path_PET_4/") predictor_5 = TabularPredictor.load("no_path_PET_5/") ## Import mapping dataset stage_mapping = pd.read_csv('stage_mapping.csv', index_col = 0) # stage_mapping def get_encoding(stage): return stage_mapping.loc[stage, 'stage_encoded'] # this is the dataframe for mappings that will be created from the training set def relapse(age_group, stage): X_test_radio = pd.DataFrame.from_dict( { "age_group": ["<=15" if age_group == "<=15" else ">15"], 'radio': ["Yes"], 'stage_encoded' : get_encoding(stage) } ) X_test_no_radio = pd.DataFrame.from_dict( { "age_group": ["<=15" if age_group == "Age <=15" else ">15"], 'radio': ["No"], 'stage_encoded' : get_encoding(stage) } ) rad_1 = float(round(predictor_1.predict_proba(X_test_radio).iloc[0,1],3)) rad_2 = float(round(predictor_2.predict_proba(X_test_radio).iloc[0,1],3)) rad_3 = float(round(predictor_3.predict_proba(X_test_radio).iloc[0,1],3)) rad_4 = float(round(predictor_4.predict_proba(X_test_radio).iloc[0,1],3)) pred_proba_radio = float(round(np.mean([rad_1, rad_2, rad_3, rad_4]),3)) no_rad1 = float(round(predictor_1.predict_proba(X_test_no_radio).iloc[0,1],3)) no_rad2 = float(round(predictor_2.predict_proba(X_test_no_radio).iloc[0,1],3)) no_rad3 = float(round(predictor_3.predict_proba(X_test_no_radio).iloc[0,1],3)) no_rad4 = float(round(predictor_4.predict_proba(X_test_no_radio).iloc[0,1],3)) pred_proba_no_radio = float(round(np.mean([no_rad1, no_rad2, no_rad3, no_rad4]),3)) return {"Radio": pred_proba_radio, "No Radio": pred_proba_no_radio} iface = gr.Interface( title = 'Should we omit radiotherapy?', description = 'This model predicts relapse according to risk factors.', fn=relapse, inputs= [ gr.Checkbox(label = 'Age <= 15', show_label = True), gr.Dropdown(choices = ['1A', '1B', '2A', '2B', '3A', '3B', '4A', '4B'], label = 'stage', show_label = True) ] ,outputs = gr.Label(label = 'Has a higher probability of relapse', show_label = True) ,live = True, interpretation="default", ) iface.launch()