abhibisht89 commited on
Commit
b4d8df5
1 Parent(s): a380d2c
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from spacy import displacy
3
+ import spacy
4
+
5
+ med7 = spacy.load("en_core_med7_lg")
6
+
7
+ def get_med7_ent(text):
8
+
9
+ # create distinct colours for labels
10
+ col_dict = {}
11
+ seven_colours = ['#e6194B', '#3cb44b', '#ffe119', '#ffd8b1', '#f58231', '#f032e6', '#42d4f4']
12
+ for label, colour in zip(med7.pipe_labels['ner'], seven_colours):
13
+ col_dict[label] = colour
14
+
15
+ options = {'ents': med7.pipe_labels['ner'], 'colors':col_dict}
16
+
17
+ # text = 'A patient was prescribed Magnesium hydroxide 400mg/5ml suspension PO of total 30ml bid for the next 5 days.'
18
+ doc = med7(text)
19
+
20
+ # spacy.displacy.render(doc, style='ent', jupyter=True, options=options)
21
+
22
+ # [(ent.text, ent.label_) for ent in doc.ents]
23
+
24
+ html = displacy.render(doc, style="ent", jupyter=True, options=options)
25
+ return html
26
+
27
+ exp=["A patient was prescribed Magnesium hydroxide 400mg/5ml suspension PO of total 30ml bid for the next 5 days."]
28
+
29
+ desc="Med7 — an information extraction model for clinical natural language processing"
30
+
31
+ inp=gr.inputs.Textbox(lines=5, placeholder=None, default="", label="text to extract Med7 Entities")
32
+ out=gr.outputs.HTML(label=None)
33
+
34
+ iface = gr.Interface(fn=get_med7_ent, inputs=inp, outputs=out,examples=exp,article=desc,title="Med7",theme="huggingface",layout='horizontal')
35
+ iface.launch()