paragon-analytics commited on
Commit
68fbe9e
1 Parent(s): 08184e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -24,9 +24,14 @@ pred = transformers.pipeline("text-classification", model=model,
24
 
25
  explainer = shap.Explainer(pred)
26
 
27
-
28
  ##
29
  classifier = transformers.pipeline("text-classification", model = "cross-encoder/qnli-electra-base")
 
 
 
 
 
 
30
  ##
31
 
32
  def adr_predict(x):
@@ -38,9 +43,10 @@ def adr_predict(x):
38
  shap_values = explainer([str(x).lower()])
39
  local_plot = shap.plots.text(shap_values[0], display=False)
40
 
41
- med = classifier(x+str("There is a medication."))[0]
42
 
43
- return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, local_plot, med
 
44
 
45
 
46
  def main(prob1):
@@ -64,6 +70,7 @@ with gr.Blocks(title=title) as demo:
64
  label = gr.Label(label = "Predicted Label")
65
  local_plot = gr.HTML(label = 'Shap:')
66
  med = gr.Label(label = "Contains Medication")
 
67
 
68
  submit_btn.click(
69
  main,
 
24
 
25
  explainer = shap.Explainer(pred)
26
 
 
27
  ##
28
  classifier = transformers.pipeline("text-classification", model = "cross-encoder/qnli-electra-base")
29
+
30
+ def med_score(x):
31
+ label = x['label']
32
+ score_1 = x['score']
33
+ return score_1
34
+
35
  ##
36
 
37
  def adr_predict(x):
 
43
  shap_values = explainer([str(x).lower()])
44
  local_plot = shap.plots.text(shap_values[0], display=False)
45
 
46
+ med = med_scoreclassifier(x+str("There is a medication."))[0])
47
 
48
+ return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, local_plot,
49
+ {"Contains Medication": float(med), "No Medications": float(1-med)}
50
 
51
 
52
  def main(prob1):
 
70
  label = gr.Label(label = "Predicted Label")
71
  local_plot = gr.HTML(label = 'Shap:')
72
  med = gr.Label(label = "Contains Medication")
73
+
74
 
75
  submit_btn.click(
76
  main,