Spaces:
Runtime error
Runtime error
paragon-analytics
commited on
Commit
•
7c8cdc0
1
Parent(s):
1460b1f
Update app.py
Browse files
app.py
CHANGED
@@ -41,6 +41,10 @@ def sym_score(x):
|
|
41 |
score_1sym = x['score']
|
42 |
return round(score_1sym,3)
|
43 |
|
|
|
|
|
|
|
|
|
44 |
##
|
45 |
|
46 |
def adr_predict(x):
|
@@ -54,14 +58,16 @@ def adr_predict(x):
|
|
54 |
|
55 |
med = med_score(classifier(x+str(", There is a medication."))[0])
|
56 |
sym = sym_score(classifier(x+str(", There is a symptom."))[0])
|
|
|
|
|
57 |
|
58 |
-
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)}
|
59 |
|
60 |
|
61 |
def main(prob1):
|
62 |
text = str(prob1).lower()
|
63 |
obj = adr_predict(text)
|
64 |
-
return obj[0],obj[1],obj[2],obj[3]
|
65 |
|
66 |
title = "Welcome to **ADR Detector** 🪐"
|
67 |
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."""
|
@@ -78,6 +84,7 @@ with gr.Blocks(title=title) as demo:
|
|
78 |
with gr.Column(visible=True) as output_col:
|
79 |
label = gr.Label(label = "Predicted Label")
|
80 |
local_plot = gr.HTML(label = 'Shap:')
|
|
|
81 |
|
82 |
with gr.Column(visible=True) as output_col:
|
83 |
med = gr.Label(label = "Contains Medication")
|
@@ -87,14 +94,13 @@ with gr.Blocks(title=title) as demo:
|
|
87 |
main,
|
88 |
[prob1],
|
89 |
[label
|
90 |
-
,local_plot, med
|
91 |
-
, sym
|
92 |
], api_name="adr"
|
93 |
)
|
94 |
|
95 |
with gr.Row():
|
96 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
97 |
-
gr.Examples([["I had severe headache after taking Aspirin."],["I had minor stomachache after taking Acetaminophen."]],
|
98 |
-
|
99 |
|
100 |
demo.launch()
|
|
|
41 |
score_1sym = x['score']
|
42 |
return round(score_1sym,3)
|
43 |
|
44 |
+
ner_tokenizer = AutoTokenizer.from_pretrained("d4data/biomedical-ner-all")
|
45 |
+
ner_model = AutoModelForTokenClassification.from_pretrained("d4data/biomedical-ner-all")
|
46 |
+
|
47 |
+
ner_pipe = pipeline("ner", model=model, tokenizer=tokenizer, aggregation_strategy="simple") # pass device=0 if using gpu
|
48 |
##
|
49 |
|
50 |
def adr_predict(x):
|
|
|
58 |
|
59 |
med = med_score(classifier(x+str(", There is a medication."))[0])
|
60 |
sym = sym_score(classifier(x+str(", There is a symptom."))[0])
|
61 |
+
|
62 |
+
htext = ner_pipe(x)
|
63 |
|
64 |
+
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)},htext
|
65 |
|
66 |
|
67 |
def main(prob1):
|
68 |
text = str(prob1).lower()
|
69 |
obj = adr_predict(text)
|
70 |
+
return obj[0],obj[1],obj[2],obj[3],obj[4]
|
71 |
|
72 |
title = "Welcome to **ADR Detector** 🪐"
|
73 |
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."""
|
|
|
84 |
with gr.Column(visible=True) as output_col:
|
85 |
label = gr.Label(label = "Predicted Label")
|
86 |
local_plot = gr.HTML(label = 'Shap:')
|
87 |
+
htext = gr.HighlightedText(label="Diff", combine_adjacent=True, show_legend=True)
|
88 |
|
89 |
with gr.Column(visible=True) as output_col:
|
90 |
med = gr.Label(label = "Contains Medication")
|
|
|
94 |
main,
|
95 |
[prob1],
|
96 |
[label
|
97 |
+
,local_plot, med, sym, htext
|
|
|
98 |
], api_name="adr"
|
99 |
)
|
100 |
|
101 |
with gr.Row():
|
102 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
103 |
+
gr.Examples([["I had severe headache after taking Aspirin."],["I had minor stomachache after taking Acetaminophen."]],
|
104 |
+
[prob1], [label,local_plot, med, sym,htext], main, cache_examples=True)
|
105 |
|
106 |
demo.launch()
|