Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from spacy import displacy
|
3 |
|
4 |
-
from transformers import AutoTokenizer, AutoModelForTokenClassification,pipeline
|
|
|
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("abhibisht89/spanbert-large-cased-finetuned-ade_corpus_v2")
|
6 |
model = AutoModelForTokenClassification.from_pretrained("abhibisht89/spanbert-large-cased-finetuned-ade_corpus_v2").to('cpu')
|
7 |
-
adr_ner_model = pipeline(task="ner", model=model, tokenizer=tokenizer,grouped_entities=True)
|
8 |
|
9 |
def get_adr_from_text(sentence):
|
10 |
tokens = adr_ner_model(sentence)
|
@@ -16,31 +18,45 @@ def get_adr_from_text(sentence):
|
|
16 |
token["label"] = label
|
17 |
entities.append(token)
|
18 |
|
19 |
-
params = [{
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
html = displacy.render(params, style="ent", manual=True, options={
|
24 |
"colors": {
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
})
|
29 |
return html
|
30 |
|
31 |
-
exp=[
|
|
|
32 |
"Addiction to many sedatives and analgesics, such as diazepam, morphine, etc.",
|
33 |
"Birth defects associated with thalidomide",
|
34 |
"Bleeding of the intestine associated with aspirin therapy",
|
35 |
"Cardiovascular disease associated with COX-2 inhibitors (i.e. Vioxx)",
|
36 |
"Deafness and kidney failure associated with gentamicin (an antibiotic)",
|
37 |
-
"Having fever after taking paracetamol"
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
iface
|
46 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from spacy import displacy
|
3 |
|
4 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
5 |
+
|
6 |
+
# Carregar o modelo de tokenização e classificação de entidades
|
7 |
tokenizer = AutoTokenizer.from_pretrained("abhibisht89/spanbert-large-cased-finetuned-ade_corpus_v2")
|
8 |
model = AutoModelForTokenClassification.from_pretrained("abhibisht89/spanbert-large-cased-finetuned-ade_corpus_v2").to('cpu')
|
9 |
+
adr_ner_model = pipeline(task="ner", model=model, tokenizer=tokenizer, grouped_entities=True)
|
10 |
|
11 |
def get_adr_from_text(sentence):
|
12 |
tokens = adr_ner_model(sentence)
|
|
|
18 |
token["label"] = label
|
19 |
entities.append(token)
|
20 |
|
21 |
+
params = [{
|
22 |
+
"text": sentence,
|
23 |
+
"ents": entities,
|
24 |
+
"title": None
|
25 |
+
}]
|
26 |
|
27 |
html = displacy.render(params, style="ent", manual=True, options={
|
28 |
"colors": {
|
29 |
+
"DRUG": "#f08080",
|
30 |
+
"ADR": "#9bddff",
|
31 |
+
},
|
32 |
})
|
33 |
return html
|
34 |
|
35 |
+
exp = [
|
36 |
+
"Abortion, miscarriage or uterine hemorrhage associated with misoprostol (Cytotec), a labor-inducing drug.",
|
37 |
"Addiction to many sedatives and analgesics, such as diazepam, morphine, etc.",
|
38 |
"Birth defects associated with thalidomide",
|
39 |
"Bleeding of the intestine associated with aspirin therapy",
|
40 |
"Cardiovascular disease associated with COX-2 inhibitors (i.e. Vioxx)",
|
41 |
"Deafness and kidney failure associated with gentamicin (an antibiotic)",
|
42 |
+
"Having fever after taking paracetamol"
|
43 |
+
]
|
44 |
+
|
45 |
+
desc = "An adverse drug reaction (ADR) can be defined as an appreciably harmful or unpleasant reaction resulting from an intervention related to the use of a medicinal product. \
|
46 |
+
The goal of this project is to extract the adverse drug reaction from unstructured text with the Drug."
|
47 |
|
48 |
+
inp = gr.inputs.Textbox(lines=5, placeholder=None, default="", label="Texto para extrair reação adversa a medicamentos e menção ao medicamento")
|
49 |
+
out = gr.outputs.HTML(label=None)
|
50 |
|
51 |
+
iface = gr.Interface(
|
52 |
+
fn=get_adr_from_text,
|
53 |
+
inputs=inp,
|
54 |
+
outputs=out,
|
55 |
+
examples=exp,
|
56 |
+
article=desc,
|
57 |
+
title="Extrator de Reações Adversas a Medicamentos",
|
58 |
+
theme="huggingface",
|
59 |
+
layout="horizontal"
|
60 |
+
)
|
61 |
|
62 |
+
iface.launch()
|
|