File size: 1,623 Bytes
afb2fec
91d6217
 
 
 
 
 
 
 
 
 
 
afb2fec
b4d8df5
 
 
 
91d6217
b4d8df5
 
 
 
 
 
 
 
 
 
 
f865b2e
4f6eb0d
b4d8df5
 
 
3dc0f32
b4d8df5
3dc0f32
b4d8df5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
#os.system('pip install https://huggingface.co/kormilitzin/en_core_med7_lg/resolve/main/en_core_med7_lg-any-py3-none-any.whl')

os.system('pip install https://huggingface.co/kormilitzin/en_core_med7_trf/resolve/main/en_core_med7_trf-any-py3-none-any.whl')

# Using spacy.load().
#import spacy
#nlp = spacy.load("en_core_med7_trf")

# Importing as module.
#import en_core_med7_trf
#nlp = en_core_med7_trf.load()')

import gradio as gr
from spacy import displacy
import spacy

med7 = spacy.load("en_core_med7_trf")

def get_med7_ent(text):

    # create distinct colours for labels
    col_dict = {}
    seven_colours = ['#e6194B', '#3cb44b', '#ffe119', '#ffd8b1', '#f58231', '#f032e6', '#42d4f4']
    for label, colour in zip(med7.pipe_labels['ner'], seven_colours):
        col_dict[label] = colour

    options = {'ents': med7.pipe_labels['ner'], 'colors':col_dict}
    doc = med7(text)
    html = displacy.render(doc, style='ent',options=options)
    return html

exp=["A patient was prescribed Magnesium hydroxide 400mg/5ml suspension PO of total 30ml bid for the next 5 days."]

desc="Med7 — An information extraction model for clinical natural language processing. More information about the model development can be found in recent pre-print: Med7: a transferable clinical natural language processing model for electronic health records."

inp=gr.inputs.Textbox(lines=5, placeholder=None, default="", label="Text")
out=gr.outputs.HTML(label=None)

iface = gr.Interface(fn=get_med7_ent, inputs=inp, outputs=out,examples=exp,article=desc,title="Med7",theme="huggingface",layout='horizontal')
iface.launch()