DHEIVER commited on
Commit
35098f0
1 Parent(s): bc97ec5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -16
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 = [{"text": sentence,
20
- "ents": entities,
21
- "title": None}]
 
 
22
 
23
  html = displacy.render(params, style="ent", manual=True, options={
24
  "colors": {
25
- "DRUG": "#f08080",
26
- "ADR": "#9bddff",
27
- },
28
  })
29
  return html
30
 
31
- exp=["Abortion, miscarriage or uterine hemorrhage associated with misoprostol (Cytotec), a labor-inducing drug.",
 
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
- 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.\
40
- The goal of this project is to extracts the adverse drug reaction from unstructured text with the Drug."
41
 
42
- inp=gr.inputs.Textbox(lines=5, placeholder=None, default="", label="text to extract adverse drug reaction and drug mention")
43
- out=gr.outputs.HTML(label=None)
 
 
 
 
 
 
 
 
44
 
45
- iface = gr.Interface(fn=get_adr_from_text, inputs=inp, outputs=out,examples=exp,article=desc,title="Adverse Drug Reaction Xtractor",theme="huggingface",layout='horizontal')
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()