paragon-analytics commited on
Commit
55ecc4c
1 Parent(s): cde5ee9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -32,6 +32,11 @@ def med_score(x):
32
  score_1 = x['score']
33
  return score_1
34
 
 
 
 
 
 
35
  ##
36
 
37
  def adr_predict(x):
@@ -44,14 +49,15 @@ def adr_predict(x):
44
  local_plot = shap.plots.text(shap_values[0], display=False)
45
 
46
  med = med_score(classifier(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, {"Contains Medication": float(med), "No Medications": float(1-med)}
49
 
50
 
51
  def main(prob1):
52
  text = str(prob1).lower()
53
  obj = adr_predict(text)
54
- return obj[0],obj[1],obj[2]
55
 
56
  title = "Welcome to **ADR Detector** 🪐"
57
  description1 = """This app takes text (up to a few sentences) and predicts to what extent the text describes severe (or non-severe) adverse reaction to medicaitons. Please do NOT use for medical diagnosis."""
@@ -64,22 +70,23 @@ with gr.Blocks(title=title) as demo:
64
  submit_btn = gr.Button("Analyze")
65
 
66
  with gr.Row():
 
67
  local_plot = gr.HTML(label = 'Shap:')
68
 
69
  with gr.Column(visible=True) as output_col:
70
- label = gr.Label(label = "Predicted Label")
71
  med = gr.Label(label = "Contains Medication")
72
-
 
73
  submit_btn.click(
74
  main,
75
  [prob1],
76
  [label
77
- ,local_plot, med
78
  ], api_name="adr"
79
  )
80
 
81
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
82
- gr.Examples([["I have severe pain."],["I have minor pain."]], [prob1], [label,local_plot, med
83
  ], main, cache_examples=True)
84
 
85
  demo.launch()
 
32
  score_1 = x['score']
33
  return score_1
34
 
35
+ def sym_score(x):
36
+ label = x['label']
37
+ score_1 = x['score']
38
+ return score_1
39
+
40
  ##
41
 
42
  def adr_predict(x):
 
49
  local_plot = shap.plots.text(shap_values[0], display=False)
50
 
51
  med = med_score(classifier(x+str(", There is a medication."))[0])
52
+ sym = sym_score(classifier(x+str(", There is a symptom."))[0])
53
 
54
+ return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}, local_plot, {"Contains Medication": float(med), "No Medications": float(1-med)}, {"Contains Symptoms": float(sym), "No Symptoms": float(1-sym)}
55
 
56
 
57
  def main(prob1):
58
  text = str(prob1).lower()
59
  obj = adr_predict(text)
60
+ return obj[0],obj[1],obj[2],obj[3]
61
 
62
  title = "Welcome to **ADR Detector** 🪐"
63
  description1 = """This app takes text (up to a few sentences) and predicts to what extent the text describes severe (or non-severe) adverse reaction to medicaitons. Please do NOT use for medical diagnosis."""
 
70
  submit_btn = gr.Button("Analyze")
71
 
72
  with gr.Row():
73
+ label = gr.Label(label = "Predicted Label")
74
  local_plot = gr.HTML(label = 'Shap:')
75
 
76
  with gr.Column(visible=True) as output_col:
 
77
  med = gr.Label(label = "Contains Medication")
78
+ sym = gr.Label(label = "Contains Symptoms")
79
+
80
  submit_btn.click(
81
  main,
82
  [prob1],
83
  [label
84
+ ,local_plot, med, sym
85
  ], api_name="adr"
86
  )
87
 
88
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
89
+ gr.Examples([["I had severe headache after taking Aspirin."],["I had minor headache after taking Acetaminophen."]], [prob1], [label,local_plot, med, sym
90
  ], main, cache_examples=True)
91
 
92
  demo.launch()