fmegahed commited on
Commit
ee552c6
·
1 Parent(s): 45a5bed

version 0.0.41

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -16,8 +16,6 @@ import requests
16
  import urllib.request
17
  import shutil
18
 
19
- from pandas.api.types import CategoricalDtype
20
-
21
  url = 'https://raw.githubusercontent.com/fmegahed/tavr_paper/main/data/example_data2.csv'
22
  download = requests.get(url).content
23
 
@@ -36,6 +34,8 @@ def predict(age, female, race, elective, aweekend, zipinc_qrtl, hosp_region, hos
36
  prior_cabg, prior_icd, prior_mi, prior_pci, prior_ppm, prior_tia_stroke,
37
  pulmonary_circulation_disorder, smoker, valvular_disease, weight_loss,
38
  endovascular_tavr, transapical_tavr):
 
 
39
 
40
  df = pd.DataFrame.from_dict({
41
  'age': [age], 'female': [female], 'race': [race], 'elective': elective,
@@ -68,16 +68,14 @@ def predict(age, female, race, elective, aweekend, zipinc_qrtl, hosp_region, hos
68
  .apply(lambda x: x.astype('category'))
69
 
70
  # converting ordinal column to ordinal
71
- #ordinal_cat = CategoricalDtype(categories = ['FirstQ', 'SecondQ', 'ThirdQ', 'FourthQ'], ordered = True)
72
- #df.zipinc_qrtl = df.zipinc_qrtl.astype(ordinal_cat)
73
-
74
- # reading the model from GitHub
75
  with urllib.request.urlopen('https://github.com/fmegahed/tavr_paper/blob/main/data/final_model.pkl?raw=true') as response, open('final_model.pkl', 'wb') as out_file:
76
  shutil.copyfileobj(response, out_file)
77
 
78
  model = load_model('final_model')
79
-
80
-
81
  pred = predict_model(model, df, raw_score=True)
82
 
83
  return {'Death %': round(100*pred['Score_Yes'][0], 2),
@@ -143,8 +141,8 @@ gr.Interface(predict, [age, female, race, elective, aweekend, zipinc_qrtl, hosp_
143
  prior_cabg, prior_icd, prior_mi, prior_pci, prior_ppm, prior_tia_stroke,
144
  pulmonary_circulation_disorder, smoker, valvular_disease, weight_loss,
145
  endovascular_tavr, transapical_tavr],
146
- 'label',
147
  live=True,
148
  title = "Predicting In-Hospital Mortality After TAVR Using Preoperative Variables and Penalized Logistic Regression",
149
  description = "The app below utilizes the finalized logistic regression model with an l2 penalty based on the manuscript by Alhwiti et al. The manuscript will be submitted to JACC: Cardiovascular Interventions. The data used for model building is all TAVR procedures between 2012 and 2019 as reported in the HCUP NIS database. <br><br> The purpose of the app is to provide evidence-based clinical support for interventional cardiology. <br> <br> For instruction on how to use the app and the encoding required for the variables, please see <b>XYZ: insert website link here</b>.",
150
- css = 'https://bootswatch.com/5/journal/bootstrap.css').launch(share = True);
 
16
  import urllib.request
17
  import shutil
18
 
 
 
19
  url = 'https://raw.githubusercontent.com/fmegahed/tavr_paper/main/data/example_data2.csv'
20
  download = requests.get(url).content
21
 
 
34
  prior_cabg, prior_icd, prior_mi, prior_pci, prior_ppm, prior_tia_stroke,
35
  pulmonary_circulation_disorder, smoker, valvular_disease, weight_loss,
36
  endovascular_tavr, transapical_tavr):
37
+
38
+
39
 
40
  df = pd.DataFrame.from_dict({
41
  'age': [age], 'female': [female], 'race': [race], 'elective': elective,
 
68
  .apply(lambda x: x.astype('category'))
69
 
70
  # converting ordinal column to ordinal
71
+ ordinal_cat = CategoricalDtype(categories = ['FirstQ', 'SecondQ', 'ThirdQ', 'FourthQ'], ordered = True)
72
+ df.zipinc_qrtl = df.zipinc_qrtl.astype(ordinal_cat)
73
+
 
74
  with urllib.request.urlopen('https://github.com/fmegahed/tavr_paper/blob/main/data/final_model.pkl?raw=true') as response, open('final_model.pkl', 'wb') as out_file:
75
  shutil.copyfileobj(response, out_file)
76
 
77
  model = load_model('final_model')
78
+
 
79
  pred = predict_model(model, df, raw_score=True)
80
 
81
  return {'Death %': round(100*pred['Score_Yes'][0], 2),
 
141
  prior_cabg, prior_icd, prior_mi, prior_pci, prior_ppm, prior_tia_stroke,
142
  pulmonary_circulation_disorder, smoker, valvular_disease, weight_loss,
143
  endovascular_tavr, transapical_tavr],
144
+ 'text',
145
  live=True,
146
  title = "Predicting In-Hospital Mortality After TAVR Using Preoperative Variables and Penalized Logistic Regression",
147
  description = "The app below utilizes the finalized logistic regression model with an l2 penalty based on the manuscript by Alhwiti et al. The manuscript will be submitted to JACC: Cardiovascular Interventions. The data used for model building is all TAVR procedures between 2012 and 2019 as reported in the HCUP NIS database. <br><br> The purpose of the app is to provide evidence-based clinical support for interventional cardiology. <br> <br> For instruction on how to use the app and the encoding required for the variables, please see <b>XYZ: insert website link here</b>.",
148
+ css = 'https://bootswatch.com/5/journal/bootstrap.css').launch(debug = True);