paragon-analytics commited on
Commit
98c11b8
Β·
1 Parent(s): 647aaf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -66,11 +66,12 @@ def adr_predict(x):
66
  # build an explainer using a token masker
67
  explainer = shap.Explainer(f, tokenizer)
68
  shap_values = explainer(str(x), fixed_context=1)
 
69
  # plot the first sentence's explanation
70
- plt = shap.plots.text(shap_values[0],display=False)
71
 
72
 
73
- return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, word_attributions,plt
74
 
75
  def main(text):
76
  text = str(text).lower()
@@ -101,16 +102,16 @@ with gr.Blocks(title=title) as demo:
101
  "--": "darkblue",
102
  "-": "blue", "NA":"white"})
103
 
104
- shap = gr.HighlightedText(label="SHAP Scores",combine_adjacent=False)
105
 
106
 
107
  submit_btn.click(
108
  main,
109
  [text],
110
- [label,intp,shap], api_name="adr"
111
  )
112
 
113
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
114
- gr.Examples([["I have minor pain."],["I have severe pain."]], [text], [label,intp,shap], main, cache_examples=True)
115
 
116
  demo.launch()
 
66
  # build an explainer using a token masker
67
  explainer = shap.Explainer(f, tokenizer)
68
  shap_values = explainer(str(x), fixed_context=1)
69
+ scores = list(zip(shap_values.data[0], shap_values.values[0, :, 1]))
70
  # plot the first sentence's explanation
71
+ # plt = shap.plots.text(shap_values[0],display=False)
72
 
73
 
74
+ return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, word_attributions,scores
75
 
76
  def main(text):
77
  text = str(text).lower()
 
102
  "--": "darkblue",
103
  "-": "blue", "NA":"white"})
104
 
105
+ interpretation = gr.components.Interpretation(text)
106
 
107
 
108
  submit_btn.click(
109
  main,
110
  [text],
111
+ [label,intp,interpretation], api_name="adr"
112
  )
113
 
114
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
115
+ gr.Examples([["I have minor pain."],["I have severe pain."]], [text], [label,intp,interpretation], main, cache_examples=True)
116
 
117
  demo.launch()