Spaces:
Sleeping
Sleeping
File size: 4,916 Bytes
864ca3a 16ec6ea f7012c4 94be168 f7012c4 864ca3a c92e63c 864ca3a c92e63c 864ca3a c92e63c 6198d18 864ca3a c92e63c 864ca3a c92e63c 6198d18 864ca3a c92e63c f7012c4 864ca3a f7012c4 864ca3a f7012c4 864ca3a f7012c4 c92e63c f7012c4 864ca3a c92e63c f7012c4 864ca3a c92e63c 16ec6ea 6198d18 |
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# 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/")
## 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 else ">15"],
'radio': ["Yes"],
'stage_encoded' : get_encoding(stage)
}
)
X_test_no_radio = pd.DataFrame.from_dict(
{
"age_group": ["<=15" if age_group 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()
|