Spaces:
Runtime error
Runtime error
File size: 2,181 Bytes
091b77e 6a55033 091b77e 846da51 091b77e 2a493e6 091b77e 2a493e6 091b77e b00415c 7fda840 b00415c bdba6de 6d38d42 091b77e |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
import sentencepiece
import streamlit as st
import pandas as pd
text_1 = "Patiente atteinte d’une pathologie chronique"
text_2 = "Vous êtes amené à prendre en charge un homme de 54 ans qui souffre d’une spondylarthrite ankylosante sévère."
st.title("Demo for Biomedical POS Tagging in French with DrBERT")
st.sidebar.write("Model : DrBERT-7GB base CAS corpus POS tagging")
st.sidebar.write("For details of model: 'https://huggingface.co/Dr-BERT/DrBERT-7GB'")
model_checkpoint = "Dr-BERT/CAS-Biomedical-POS-Tagging"
aggregation = "simple"
st.subheader("Select Text")
context_1 = st.text_area("Text #1", text_1, height=128)
context_2 = st.text_area("Text #2", text_2, height=128)
context_3 = st.text_area("New Text", value="", height=128)
context = st.radio("Select Text", ("Text #1", "Text #2", "New Text"))
if context == "Text #1":
input_text = context_1
elif context == "Text #2":
input_text = context_2
elif context == "New Text":
input_text = context_3
@st.cache(allow_output_mutation=True)
def setModel(model_checkpoint, aggregation):
model = AutoModelForTokenClassification.from_pretrained(model_checkpoint)
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
return pipeline('token-classification', model=model, tokenizer=tokenizer, aggregation_strategy=aggregation), model.config.id2label
Run_Button = st.button("Run", key=None)
if Run_Button == True:
ner_pipeline, id2label = setModel(model_checkpoint, aggregation)
output = ner_pipeline(input_text)
# print(id2label)
# output_new = []
# for o in output:
# o["entity_group"] = id2label[int(o["entity_group"].split("_")[-1])]
# output_new.append(o)
df = pd.DataFrame.from_dict(output)
if aggregation != "none":
df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
else:
df.rename(index=str,columns={'entity_group':'POS Tag'},inplace=True)
cols_to_keep = ['word','POS Tag','score','start','end']
df_final = df[cols_to_keep]
st.subheader("POS Tags")
st.dataframe(df_final) |