Med7 / app.py
abhibisht89's picture
Update app.py
91d6217
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()