EC2 Default User commited on
Commit
bc6c1cd
1 Parent(s): 6ca03fa

lets push app to the huggingface spaces

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
11
+ entities = []
12
+
13
+ for token in tokens:
14
+ label = token["entity_group"]
15
+ if label != "O":
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()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ spacy==3.0.2
2
+ torch==1.5.0
3
+ transformers==4.12.5