santarabantoosoo commited on
Commit
c92e63c
1 Parent(s): 222772d
Files changed (1) hide show
  1. app.py +38 -47
app.py CHANGED
@@ -5,68 +5,59 @@ import numpy as np
5
  import lightgbm as lgb
6
  from autogluon.tabular import TabularPredictor
7
 
8
- loaded_model = pickle.load(open('model.pkl', 'rb'))
9
-
10
- def relapse(age, early_stage = 0 , pathology = 'Mixed', B_symptoms = 0):
11
-
12
- # default values
13
- pathology_nod = 0
14
- pathology_others = 0
15
-
16
- if early_stage:
17
- early_stage = 1
18
-
19
- if pathology == 'Nodular':
20
- pathology_nod = 1
21
-
22
- if pathology == 'Others':
23
- pathology_others = 1
24
-
25
- if B_symptoms:
26
- B_symptoms = 1
27
-
28
- # I will multiply age by std dev and then add the mean to reverse standard scalar
29
-
30
- # I am using data to get the mean and std dev which is probably not right.
31
-
32
- age = (age - 14.892) / 1.635
33
-
34
- X_test_radio = pd.DataFrame({'Age' : age, 'early_advanced_early': early_stage,
35
- 'pathology_Nodular Sclerosis cHL' : pathology_nod,
36
- 'pathology_others': pathology_others , 'B_symptoms_Yes': B_symptoms,
37
- 'radio_Yes': 1, 'second_PET' : 1}, index = [0])
38
-
39
- X_test_no_radio = pd.DataFrame({'Age' : age, 'early_advanced_early': early_stage,
40
- 'pathology_Nodular Sclerosis cHL' : pathology_nod,
41
- 'pathology_others': pathology_others, 'B_symptoms_Yes': B_symptoms,
42
- 'radio_Yes': 0, 'second_PET' : 1}, index = [0])
43
-
44
-
45
- pred_proba_radio = loaded_model.predict_proba(X_test_radio)[:, 1]
46
 
47
  pred_proba_radio = round(np.ndarray.item(pred_proba_radio),2)
48
 
49
  pred_radio = loaded_model.predict(X_test_radio)
50
 
51
- pred_proba_no_radio = loaded_model.predict_proba(X_test_no_radio)[:, 1]
52
 
53
  pred_proba_no_radio = round(np.ndarray.item(pred_proba_no_radio),2)
54
 
55
  pred_no_radio = loaded_model.predict(X_test_no_radio)
56
 
57
- return pred_proba_radio ,pred_proba_no_radio
58
 
59
- iface = gr.Interface(title = 'Should we omit radiotherapy?',
 
 
60
  description = 'This model predicts relapse according to risk factors.',
61
  fn=relapse,
62
  inputs= [
63
  gr.Number(label = 'Age', show_label = True),
64
- gr.Checkbox( label = 'Early stage', show_label = True),
65
- gr.Radio( choices = ['Mixed cellularity', 'Nodular', 'Others'], label = 'Pathology',
66
- show_label = True),
67
  gr.Checkbox(label = 'B_symptoms', show_label = True)],
68
- outputs= [gr.Label(label = 'Relapse probability with RTH'),
69
- gr.Label(label = 'Relapse probability without RTH')],live = True)
70
-
 
71
 
72
  iface.launch()
 
5
  import lightgbm as lgb
6
  from autogluon.tabular import TabularPredictor
7
 
8
+ loaded_model = pickle.load(open('Autogluon/models/XGBoost_BAG_L1/model.pkl', 'rb'))
9
+ # pred_proba_radio = loaded_model.predict_proba(X_test_radio)
10
+ # pred_proba_radio
11
+
12
+
13
+ def relapse(age, pathology, B_symptoms):
14
+
15
+ X_test_radio = pd.DataFrame.from_dict(
16
+ {
17
+ "Age": [age],
18
+ "pathology_Nodular Sclerosis cHL": [1 if pathology == 'Nodular' else 0],
19
+ "pathology_others": [1 if pathology == 'Others' else 0],
20
+ "B_symptoms_Yes" : [1 if B_symptoms else 0],
21
+ 'radio_Yes': [1]
22
+ }
23
+ )
24
+
25
+ X_test_no_radio = pd.DataFrame.from_dict(
26
+ {
27
+ "Age": [age],
28
+ "pathology_Nodular Sclerosis cHL": [1 if pathology == 'Nodular' else 0],
29
+ "pathology_others": [1 if pathology == 'Others' else 0],
30
+ "B_symptoms_Yes" : [1 if B_symptoms else 0],
31
+ 'radio_Yes': [0]
32
+ }
33
+ )
34
+
35
+ pred_proba_radio = loaded_model.predict_proba(X_test_radio)
 
 
 
 
 
 
 
 
 
 
36
 
37
  pred_proba_radio = round(np.ndarray.item(pred_proba_radio),2)
38
 
39
  pred_radio = loaded_model.predict(X_test_radio)
40
 
41
+ pred_proba_no_radio = loaded_model.predict_proba(X_test_no_radio)
42
 
43
  pred_proba_no_radio = round(np.ndarray.item(pred_proba_no_radio),2)
44
 
45
  pred_no_radio = loaded_model.predict(X_test_no_radio)
46
 
47
+ return {"Radio": pred_proba_radio, "No Radio": pred_proba_no_radio}
48
 
49
+ iface = gr.Interface(
50
+
51
+ title = 'Should we omit radiotherapy?',
52
  description = 'This model predicts relapse according to risk factors.',
53
  fn=relapse,
54
  inputs= [
55
  gr.Number(label = 'Age', show_label = True),
56
+ gr.Radio( choices = ['Mixed cellularity', 'Nodular', 'Others'], label = 'Pathology', show_label = True),
 
 
57
  gr.Checkbox(label = 'B_symptoms', show_label = True)],
58
+ outputs = gr.Label(label = 'Has a higher probability of relapse', show_label = True)
59
+ ,live = True,
60
+ interpretation="default",
61
+ )
62
 
63
  iface.launch()